A few minor things. Fixed missing fields from app messages. Fixed some missing messages. Removed unnecessary asyncs.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3637 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2021-01-12 02:23:57 +00:00
parent 7012418b13
commit 92c06b34a9
3 changed files with 66 additions and 60 deletions

View File

@ -1 +1 @@
{"type":"tildefriends-app","files":{"app.js":"&WiH+BcLge0Imgpcfo/lecF92raEkf2cLyxr+GQKM5DU=.sha256","index.html":"&z528csPu5+I+634DKxY3EBOQYAAVt1hLOQiWj+gW+qM=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256"}} {"type":"tildefriends-app","files":{"app.js":"&QC3jbGKlu7N1D7w6L64MUuT0EWf0MSew1gEg4LbaFcM=.sha256","index.html":"&eqLI+5Abbs4OEjIO7neOQFjhm/iknp6gi96RD2VTAR0=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256"}}

View File

@ -5,7 +5,7 @@ const k_votes_max = 100;
async function following(db, id) { async function following(db, id) {
var o = await db.get(id + ":following"); var o = await db.get(id + ":following");
const k_version = 4; const k_version = 5;
var f = o ? JSON.parse(o) : o; var f = o ? JSON.parse(o) : o;
if (!f || f.version != k_version) { if (!f || f.version != k_version) {
f = {users: [], sequence: 0, version: k_version}; f = {users: [], sequence: 0, version: k_version};
@ -24,7 +24,7 @@ async function following(db, id) {
"UNION SELECT MAX(sequence) AS sequence, NULL, NULL FROM messages WHERE author = ?1 "+ "UNION SELECT MAX(sequence) AS sequence, NULL, NULL FROM messages WHERE author = ?1 "+
"ORDER BY sequence", "ORDER BY sequence",
[id, f.sequence], [id, f.sequence],
async function(row) { function(row) {
if (row.following) { if (row.following) {
f.users.add(row.contact); f.users.add(row.contact);
} else { } else {
@ -53,7 +53,7 @@ async function followingDeep(db, seed_ids, depth) {
async function followers(db, id) { async function followers(db, id) {
var o = await db.get(id + ":followers"); var o = await db.get(id + ":followers");
const k_version = 2; const k_version = 3;
var f = o ? JSON.parse(o) : o; var f = o ? JSON.parse(o) : o;
if (!f || f.version != k_version) { if (!f || f.version != k_version) {
f = {users: [], rowid: 0, version: k_version}; f = {users: [], rowid: 0, version: k_version};
@ -72,7 +72,7 @@ async function followers(db, id) {
"UNION SELECT MAX(rowid) as rowid, NULL, NULL FROM messages "+ "UNION SELECT MAX(rowid) as rowid, NULL, NULL FROM messages "+
"ORDER BY rowid", "ORDER BY rowid",
[f.rowid, id], [f.rowid, id],
async function(row) { function(row) {
if (row.following) { if (row.following) {
f.users.add(row.contact); f.users.add(row.contact);
} else { } else {
@ -101,7 +101,7 @@ async function sendUser(db, id) {
async function pubsByUser(db, id) { async function pubsByUser(db, id) {
var o = await db.get(id + ":pubs"); var o = await db.get(id + ":pubs");
const k_version = 2; const k_version = 3;
var f = o ? JSON.parse(o) : o; var f = o ? JSON.parse(o) : o;
if (!f || f.version != k_version) { if (!f || f.version != k_version) {
f = {pubs: [], sequence: 0, version: k_version}; f = {pubs: [], sequence: 0, version: k_version};
@ -121,7 +121,7 @@ async function pubsByUser(db, id) {
"UNION SELECT MAX(sequence) as sequence, NULL, NULL, NULL FROM messages WHERE author = ?2 "+ "UNION SELECT MAX(sequence) as sequence, NULL, NULL, NULL FROM messages WHERE author = ?2 "+
"ORDER BY sequence", "ORDER BY sequence",
[f.sequence, id], [f.sequence, id],
async function(row) { function(row) {
f.sequence = row.sequence; f.sequence = row.sequence;
if (row.host) { if (row.host) {
row = {host: row.host, port: row.port, key: row.key}; row = {host: row.host, port: row.port, key: row.key};
@ -237,7 +237,7 @@ async function getRecentPostIds(db, id, ids, limit) {
async function getVotes(db, id) { async function getVotes(db, id) {
var o = await db.get(id + ":votes"); var o = await db.get(id + ":votes");
const k_version = 2; const k_version = 3;
var votes = []; var votes = [];
var f = o ? JSON.parse(o) : o; var f = o ? JSON.parse(o) : o;
if (!f || f.version != k_version) { if (!f || f.version != k_version) {
@ -259,7 +259,7 @@ async function getVotes(db, id) {
"UNION SELECT MAX(rowid) as rowid, NULL, NULL AS id, NULL, NULL, NULL FROM messages "+ "UNION SELECT MAX(rowid) as rowid, NULL, NULL AS id, NULL, NULL, NULL FROM messages "+
"ORDER BY rowid DESC LIMIT ?", "ORDER BY rowid DESC LIMIT ?",
[f.rowid, id, k_votes_max], [f.rowid, id, k_votes_max],
async function(row) { function(row) {
if (row.id) { if (row.id) {
votes.push(row); votes.push(row);
} else { } else {
@ -363,6 +363,7 @@ core.register('message', async function(m) {
app = JSON.parse(utf8Decode(app)); app = JSON.parse(utf8Decode(app));
app.type = 'tildefriends-app'; app.type = 'tildefriends-app';
app.name = m.message.share_app.name; app.name = m.message.share_app.name;
app.text = m.message.share_app.text;
await ssb.appendMessage(app); await ssb.appendMessage(app);
} else if (m.message.user) { } else if (m.message.user) {
await sendUser(await database("ssb"), m.message.user); await sendUser(await database("ssb"), m.message.user);

View File

@ -84,29 +84,29 @@
}, },
template: `<span @click="show_user_dialog = true"> template: `<span @click="show_user_dialog = true">
{{users[id] && users[id].name ? users[id].name : id}} {{users[id] && users[id].name ? users[id].name : id}}
<md-tooltip v-if="users[id] && users[id].name">{{id}}</md-tooltip> <md-tooltip v-if="users[id] && users[id].name">{{id}}</md-tooltip>
<md-dialog :md-active.sync="show_user_dialog"> <md-dialog :md-active.sync="show_user_dialog">
<md-dialog-title>{{users[id] && users[id].name ? users[id].name : id}}</md-dialog-title> <md-dialog-title>{{users[id] && users[id].name ? users[id].name : id}}</md-dialog-title>
<md-dialog-content v-if="users[id]"> <md-dialog-content v-if="users[id]">
<div v-if="users[id].image"><img :src="'/' + users[id].image + '/view'"></div> <div v-if="users[id].image"><img :src="'/' + users[id].image + '/view'"></div>
<div v-if="users[id].name">{{id}}</div> <div v-if="users[id].name">{{id}}</div>
<div>{{users[id].description}}</div> <div>{{users[id].description}}</div>
<div><md-switch v-model="following">Following</md-switch></div> <div><md-switch v-model="following">Following</md-switch></div>
<md-list> <md-list>
<md-subheader>Followers</md-subheader> <md-subheader>Followers</md-subheader>
<md-list-item v-for="follower in (users[id] || []).followers" v-bind:key="'follower-' + follower"> <md-list-item v-for="follower in (users[id] || []).followers" v-bind:key="'follower-' + follower">
<tf-user :id="follower"></tf-user> <tf-user :id="follower"></tf-user>
</md-list-item> </md-list-item>
<md-subheader>Following</md-subheader> <md-subheader>Following</md-subheader>
<md-list-item v-for="user in (users[id] || []).following" v-bind:key="'following-' + user"> <md-list-item v-for="user in (users[id] || []).following" v-bind:key="'following-' + user">
<tf-user :id="user"></tf-user> <tf-user :id="user"></tf-user>
</md-list-item> </md-list-item>
</md-list> </md-list>
</md-dialog-content> </md-dialog-content>
<md-dialog-actions> <md-dialog-actions>
<md-button @click="show_user_dialog = false">Close</md-button> <md-button @click="show_user_dialog = false">Close</md-button>
</md-dialog-actions> </md-dialog-actions>
</md-dialog> </md-dialog>
</span>`, </span>`,
}); });
Vue.component('tf-message', { Vue.component('tf-message', {
@ -162,36 +162,40 @@
}, },
template: `<md-app class="md-elevation-8" style="margin: 1em" v-if="!content_json || ['pub', 'vote'].indexOf(content_json.type) == -1"> template: `<md-app class="md-elevation-8" style="margin: 1em" v-if="!content_json || ['pub', 'vote'].indexOf(content_json.type) == -1">
<md-app-toolbar> <md-app-toolbar>
<h3> <h3>
<tf-user :id="message.author"></tf-user> <tf-user :id="message.author"></tf-user>
</h3> </h3>
<div style="font-size: x-small">{{new Date(message.timestamp)}}</div> <div style="font-size: x-small">{{new Date(message.timestamp)}}</div>
<div class="md-toolbar-section-end"> <div class="md-toolbar-section-end">
<md-menu> <md-menu>
<md-button md-menu-trigger class="md-icon-button"><md-icon>more_vert</md-icon></md-button> <md-button md-menu-trigger class="md-icon-button"><md-icon>more_vert</md-icon></md-button>
<md-menu-content> <md-menu-content>
<md-menu-item v-if="!showRaw" v-on:click="showRaw = true">View Raw</md-menu-item> <md-menu-item v-if="!showRaw" v-on:click="showRaw = true">View Raw</md-menu-item>
<md-menu-item v-else v-on:click="showRaw = false">View Message</md-menu-item> <md-menu-item v-else v-on:click="showRaw = false">View Message</md-menu-item>
</md-menu-content> </md-menu-content>
</md-menu> </md-menu>
</div> </div>
</md-app-toolbar> </md-app-toolbar>
<md-app-content> <md-app-content>
<div v-if="showRaw">{{message.content}}</div> <div v-if="showRaw">{{message.content}}</div>
<div v-else> <div v-else>
<div v-if="content_json && content_json.type == 'post'"> <div v-if="content_json && content_json.type == 'post'">
<div v-html="this.markdown(content_json.text)"></div> <div v-html="this.markdown(content_json.text)"></div>
<img v-for="mention in content_json.mentions" v-if="mention.link && typeof(mention.link) == 'string' && mention.link.startsWith('&')" :src="'/' + mention.link + '/view'"></img> <img v-for="mention in content_json.mentions" v-if="mention.link && typeof(mention.link) == 'string' && mention.link.startsWith('&')" :src="'/' + mention.link + '/view'"></img>
</div> </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-if="content_json && content_json.type == 'tildefriends-app'">
<div v-else>{{message.content}}</div> <div v-html="this.markdown(content_json.text)"></div>
</div> <md-button target="_top" :href="'/' + message.id + '/'">{{content_json.name || 'tildefriends-app'}}</md-button>
<tf-message v-for="sub_message in sub_messages" v-bind:message="sub_message" v-bind:messages="messages" v-bind:key="sub_message.id"></tf-message> </div>
<md-chip v-for="vote in Object.keys(votes)" v-bind:key="vote"> <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>
{{vote + (votes[vote].length > 1 ? ' (' + votes[vote].length + ')' : '')}} <div v-else>{{message.content}}</div>
</md-chip> </div>
</md-app-content> <tf-message v-for="sub_message in sub_messages" v-bind:message="sub_message" v-bind:messages="messages" v-bind:key="sub_message.id"></tf-message>
</md-app>`, <md-chip v-for="vote in Object.keys(votes)" v-bind:key="vote">
{{vote + (votes[vote].length > 1 ? ' (' + votes[vote].length + ')' : '')}}
</md-chip>
</md-app-content>
</md-app>`,
}); });
function markdown(d) { return d; } function markdown(d) { return d; }
Vue.config.performance = true; Vue.config.performance = true;
@ -203,6 +207,7 @@
if (g_data.share_app) { if (g_data.share_app) {
window.parent.postMessage({share_app: { window.parent.postMessage({share_app: {
app: g_data.apps[g_data.share_app], app: g_data.apps[g_data.share_app],
name: g_data.share_app,
text: document.getElementById('post_text').value, text: document.getElementById('post_text').value,
}}, '*'); }}, '*');
} else { } else {
@ -296,7 +301,7 @@
<md-button class="md-raised md-primary" v-on:click="post_message()">Submit Post</md-button> <md-button class="md-raised md-primary" v-on:click="post_message()">Submit Post</md-button>
</md-card-actions> </md-card-actions>
</md-card> </md-card>
<tf-message v-for="message in messages" v-if="!content_json(message).root" v-bind:message="message" v-bind:messages="messages" v-bind:key="message.id"></tf-message> <tf-message v-for="message in messages" v-if="!content_json(message).root || !messages.some(m => m.id == content_json(message).root)" v-bind:message="message" v-bind:messages="messages" v-bind:key="message.id"></tf-message>
</md-app-content> </md-app-content>
</md-app> </md-app>
</div> </div>