Show placeholders for missing messages.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3760 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-01-15 00:29:51 +00:00
parent 5e0304481b
commit dbfa9e5623
4 changed files with 63 additions and 32 deletions

View File

@ -239,7 +239,7 @@ async function getRelatedPostIds(db, message, ids, limit) {
" json_extract(content, '$.type') = 'post' AND "+
" (id = ? OR json_extract(content, '$.root') = ?) "+
"ORDER BY timestamp DESC LIMIT ?",
[].concat([message.timestamp, row_id_max], ids_batch, [message.id, id, limit]),
[].concat([message.timestamp || 0, row_id_max], ids_batch, [message.id, id, limit]),
function(row) {
if (row.id) {
recent.push({id: row.id, timestamp: row.timestamp});
@ -336,7 +336,8 @@ async function refresh(selected) {
var ids;
if (selected && selected.length == 1 && selected[0].startsWith('%')) {
var m = await getPosts(db, selected);
ids = m.length ? await getRelatedPostIds(db, m[0], all_followed, k_posts_max) : [];
m = m.length ? m[0] : {id: selected[0]};
ids = await getRelatedPostIds(db, m, all_followed, k_posts_max);
} else {
ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max);
}

View File

@ -56,44 +56,54 @@ Vue.component('tf-message', {
<md-button class="md-icon-button md-dense" @click="show_message">
<md-icon>percent</md-icon>
</md-button>
<tf-user :id="message.author"></tf-user>
<tf-user :id="message.author" v-if="message.author"></tf-user>
</h3>
<div style="font-size: x-small">
{{new Date(message.timestamp)}}
<md-tooltip>{{message.id}}</md-tooltip>
</div>
<div class="md-toolbar-section-end">
<md-menu>
<md-switch v-model="showRaw"></md-switch>
<md-tooltip>Show Raw Message</md-tooltip>
</md-menu>
</div>
<template v-if="message.author">
<div style="font-size: x-small">
{{new Date(message.timestamp)}}
<md-tooltip>{{message.id}}</md-tooltip>
</div>
<div class="md-toolbar-section-end">
<md-menu>
<md-switch v-model="showRaw"></md-switch>
<md-tooltip>Show Raw Message</md-tooltip>
</md-menu>
</div>
</template>
<template v-else>
<h3>Missing</h3>
</template>
</md-app-toolbar>
<md-app-content>
<div v-if="showRaw">
<h1>{{message.id}}</h1>
<pre style="word-wrap: break-all; white-space: pre-wrap">{{content_raw}}</pre>
</div>
<div v-else>
<div v-if="content_json && content_json.type == 'post'">
<div v-html="this.markdown(content_json.text)"></div>
<div v-for="mention in content_json.mentions" v-if="mention.link && typeof(mention.link) == 'string' && mention.link.startsWith('&')">
<a v-if="mention.type == 'application/tildefriends'" :href="'/' + mention.link + '/'" target="_top">{{mention.name}}</a>
<img v-else :src="'/' + mention.link + '/view'"></img>
<template v-if="message.author">
<div v-if="showRaw">
<h1>{{message.id}}</h1>
<pre style="word-wrap: break-all; white-space: pre-wrap">{{content_raw}}</pre>
</div>
<div v-else>
<div v-if="content_json && content_json.type == 'post'">
<div v-html="this.markdown(content_json.text)"></div>
<div v-for="mention in content_json.mentions" v-if="mention.link && typeof(mention.link) == 'string' && mention.link.startsWith('&')">
<a v-if="mention.type == 'application/tildefriends'" :href="'/' + mention.link + '/'" target="_top">{{mention.name}}</a>
<img v-else :src="'/' + mention.link + '/view'"></img>
</div>
</div>
<div v-else-if="content_json && content_json.type == 'tildefriends-app'">
<div v-html="this.markdown(content_json.text)"></div>
<md-button target="_top" :href="'/' + message.id + '/'">{{content_json.name || 'tildefriends-app'}}</md-button>
</div>
<div v-else-if="content_json && content_json.type == 'contact'"><tf-user :id="message.author"></tf-user> {{content_json.following ? '==&gt;' : '=/=&gt;'}} <tf-user :id="content_json.contact"></tf-user></div>
<div v-else>{{message.content}}</div>
</div>
<div v-else-if="content_json && content_json.type == 'tildefriends-app'">
<div v-html="this.markdown(content_json.text)"></div>
<md-button target="_top" :href="'/' + message.id + '/'">{{content_json.name || 'tildefriends-app'}}</md-button>
</div>
<div v-else-if="content_json && content_json.type == 'contact'"><tf-user :id="message.author"></tf-user> {{content_json.following ? '==&gt;' : '=/=&gt;'}} <tf-user :id="content_json.contact"></tf-user></div>
<div v-else>{{message.content}}</div>
</div>
</template>
<template v-else>
{{message.id}}
</template>
<tf-message v-for="sub_message in (message.children || [])" v-bind:message="sub_message" v-bind:messages="messages" v-bind:votes="votes" v-bind:key="sub_message.id"></tf-message>
<md-chip v-for="vote in Object.keys(votes[message.id] || {})" v-bind:key="vote">
{{vote + (votes[message.id][vote].length > 1 ? ' (' + votes[message.id][vote].length + ')' : '')}}
</md-chip>
<md-card-actions>
<md-card-actions v-if="message.author">
<md-button class="md-icon-button" @click="set_reply">
<md-icon>reply</md-icon>
</md-button>

View File

@ -48,6 +48,17 @@ function processMessages() {
found = true;
}
}
if (!found) {
var fake_root = {
id: root,
children: [new_message],
timestamp: new_message.timestamp,
content: '{}',
};
g_data.messages.push(fake_root);
g_data.messages.sort((x, y) => y.timestamp - x.timestamp);
found = true;
}
}
var removed = {};
for (let message of g_data.messages) {
@ -58,6 +69,15 @@ function processMessages() {
}
}
g_data.messages = g_data.messages.filter(x => !removed[x.id]);
if (!found) {
for (let message of g_data.messages) {
if (message.id == new_message.id) {
new_message.children = message.children;
Vue.set(g_data.messages, g_data.messages.indexOf(message), new_message);
found = true;
}
}
}
if (!found) {
g_data.messages.push(new_message);
g_data.messages.sort((x, y) => y.timestamp - x.timestamp);