This lets me post a 'tildefriends-app' message.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3634 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
a2851f8ade
commit
d8657866f5
@ -1 +1 @@
|
|||||||
{"type":"tildefriends-app","files":{"app.js":"&6uFJG2C0kZar1Aj+7p2/KzYEBXgmK/uJSt7aIJqenN4=.sha256","index.html":"&TFtniuUIVO7XeWCgwmqPAmuBzpGX6slxJQcPMEr+860=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256"}}
|
{"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"}}
|
@ -168,7 +168,7 @@ async function getAbout(db, id) {
|
|||||||
"UNION SELECT MAX(sequence) as sequence, NULL FROM messages WHERE author = ?2 "+
|
"UNION SELECT MAX(sequence) as sequence, 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.content) {
|
if (row.content) {
|
||||||
var about = {};
|
var about = {};
|
||||||
@ -199,7 +199,7 @@ function fnv32a(value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getRecentPostIds(db, id, ids, limit) {
|
async function getRecentPostIds(db, id, ids, limit) {
|
||||||
const k_version = 6;
|
const k_version = 7;
|
||||||
var o = await db.get(id + ':recent_posts');
|
var o = await db.get(id + ':recent_posts');
|
||||||
var recent = [];
|
var recent = [];
|
||||||
var f = o ? JSON.parse(o) : o;
|
var f = o ? JSON.parse(o) : o;
|
||||||
@ -215,7 +215,7 @@ async function getRecentPostIds(db, id, ids, limit) {
|
|||||||
"WHERE "+
|
"WHERE "+
|
||||||
" rowid > ? AND "+
|
" rowid > ? AND "+
|
||||||
" author IN (" + ids.map(x => '?').join(", ") + ") AND "+
|
" author IN (" + ids.map(x => '?').join(", ") + ") AND "+
|
||||||
" json_extract(content, '$.type') = 'post' "+
|
" json_extract(content, '$.type') IN ('post', 'tildefriends-app') "+
|
||||||
"UNION SELECT MAX(rowid) as rowid, NULL FROM messages "+
|
"UNION SELECT MAX(rowid) as rowid, NULL FROM messages "+
|
||||||
"ORDER BY rowid DESC LIMIT ?",
|
"ORDER BY rowid DESC LIMIT ?",
|
||||||
[].concat([f.rowid], ids, [limit + 1]),
|
[].concat([f.rowid], ids, [limit + 1]),
|
||||||
@ -280,7 +280,7 @@ async function getPosts(db, ids) {
|
|||||||
await ssb.sqlStream(
|
await ssb.sqlStream(
|
||||||
"SELECT rowid, * FROM messages WHERE id IN (" + ids.map(x => "?").join(", ") + ")",
|
"SELECT rowid, * FROM messages WHERE id IN (" + ids.map(x => "?").join(", ") + ")",
|
||||||
ids,
|
ids,
|
||||||
async function(row) {
|
function(row) {
|
||||||
try {
|
try {
|
||||||
posts.push(row);
|
posts.push(row);
|
||||||
} catch {
|
} catch {
|
||||||
@ -312,6 +312,7 @@ async function refresh() {
|
|||||||
app.postMessage({pubs: await visiblePubs(db, whoami)}),
|
app.postMessage({pubs: await visiblePubs(db, whoami)}),
|
||||||
app.postMessage({broadcasts: await ssb.getBroadcasts()}),
|
app.postMessage({broadcasts: await ssb.getBroadcasts()}),
|
||||||
app.postMessage({connections: await ssb.connections()}),
|
app.postMessage({connections: await ssb.connections()}),
|
||||||
|
app.postMessage({apps: await core.apps()}),
|
||||||
followingDeep(db, [whoami], 2).then(function(f) {
|
followingDeep(db, [whoami], 2).then(function(f) {
|
||||||
getRecentPostIds(db, whoami, [].concat([whoami], f), k_posts_max).then(async function(ids) {
|
getRecentPostIds(db, whoami, [].concat([whoami], f), k_posts_max).then(async function(ids) {
|
||||||
return getPosts(db, ids);
|
return getPosts(db, ids);
|
||||||
@ -357,6 +358,12 @@ core.register('message', async function(m) {
|
|||||||
await ssb.post(m.message.post);
|
await ssb.post(m.message.post);
|
||||||
} else if (m.message.appendMessage) {
|
} else if (m.message.appendMessage) {
|
||||||
await ssb.appendMessage(m.message.appendMessage);
|
await ssb.appendMessage(m.message.appendMessage);
|
||||||
|
} else if (m.message.share_app) {
|
||||||
|
var app = await ssb.blobGet(m.message.share_app.app);
|
||||||
|
app = JSON.parse(utf8Decode(app));
|
||||||
|
app.type = 'tildefriends-app';
|
||||||
|
app.name = m.message.share_app.name;
|
||||||
|
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);
|
||||||
} else if (m.message.refresh) {
|
} else if (m.message.refresh) {
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
connect: null,
|
connect: null,
|
||||||
pubs: [],
|
pubs: [],
|
||||||
votes: [],
|
votes: [],
|
||||||
|
apps: {},
|
||||||
|
share_app: null,
|
||||||
};
|
};
|
||||||
var g_data_initial = JSON.parse(JSON.stringify(g_data));
|
var g_data_initial = JSON.parse(JSON.stringify(g_data));
|
||||||
window.addEventListener('message', function(event) {
|
window.addEventListener('message', function(event) {
|
||||||
@ -43,6 +45,8 @@
|
|||||||
g_data.broadcasts = event.data.broadcasts;
|
g_data.broadcasts = event.data.broadcasts;
|
||||||
} else if (key == 'pubs') {
|
} else if (key == 'pubs') {
|
||||||
g_data.pubs = event.data.pubs;
|
g_data.pubs = event.data.pubs;
|
||||||
|
} else if (key == 'apps') {
|
||||||
|
g_data.apps = event.data.apps;
|
||||||
} else if (key == 'clear') {
|
} else if (key == 'clear') {
|
||||||
Object.keys(g_data_initial).forEach(function(key) {
|
Object.keys(g_data_initial).forEach(function(key) {
|
||||||
Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key])));
|
Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key])));
|
||||||
@ -196,7 +200,15 @@
|
|||||||
data: g_data,
|
data: g_data,
|
||||||
methods: {
|
methods: {
|
||||||
post_message: function() {
|
post_message: function() {
|
||||||
window.parent.postMessage({post: document.getElementById('post_text').value}, '*');
|
if (g_data.share_app) {
|
||||||
|
window.parent.postMessage({share_app: {
|
||||||
|
app: g_data.apps[g_data.share_app],
|
||||||
|
text: document.getElementById('post_text').value,
|
||||||
|
}}, '*');
|
||||||
|
} else {
|
||||||
|
window.parent.postMessage({post: document.getElementById('post_text').value}, '*');
|
||||||
|
}
|
||||||
|
document.getElementById('post_text').value = '';
|
||||||
},
|
},
|
||||||
ssb_connect: function(connection) {
|
ssb_connect: function(connection) {
|
||||||
window.parent.postMessage({connect: connection}, '*');
|
window.parent.postMessage({connect: connection}, '*');
|
||||||
@ -264,12 +276,23 @@
|
|||||||
<div class="md-title">What's up?</div>
|
<div class="md-title">What's up?</div>
|
||||||
</md-card-header>
|
</md-card-header>
|
||||||
<md-card-content>
|
<md-card-content>
|
||||||
|
<md-chip v-if="share_app" md-deletable @md-delete="share_app = null">
|
||||||
|
{{share_app}}: {{apps[share_app]}}
|
||||||
|
</md-chip>
|
||||||
<md-field>
|
<md-field>
|
||||||
<label>Post a message</label>
|
<label>Post a message</label>
|
||||||
<md-textarea id="post_text"></md-textarea>
|
<md-textarea id="post_text"></md-textarea>
|
||||||
</md-field>
|
</md-field>
|
||||||
</md-card-content>
|
</md-card-content>
|
||||||
<md-card-actions>
|
<md-card-actions>
|
||||||
|
<md-menu>
|
||||||
|
<md-button md-menu-trigger>Share App</md-button>
|
||||||
|
<md-menu-content>
|
||||||
|
<md-menu-item v-for="app in Object.keys(apps)" @click="share_app = app">
|
||||||
|
{{app}}
|
||||||
|
</md-menu-item>
|
||||||
|
</md-menu-content>
|
||||||
|
</md-menu>
|
||||||
<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>
|
||||||
|
Loading…
Reference in New Issue
Block a user