Trying to work toward multiple users. List wikis of people you are following. Also hook in to the lit updated event.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4626 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
a6c8dd846c
commit
b23bc0b16b
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "📝",
|
||||
"previous": "&N1wA9DJ6RacaPG52I+ZEhWbbVvf3U1Dcvouh0UkfkG0=.sha256"
|
||||
"previous": "&YeaTOrnB4mPU2htPCtcLH9Ys1rXyyulEroR2gkU7zKw=.sha256"
|
||||
}
|
@ -127,10 +127,11 @@ async function process_message(whoami, collection, message, kind, parent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) {
|
||||
tfrpc.register(async function collection(ids, kind, parent, max_rowid, data, include_private) {
|
||||
let whoami = await ssb.getIdentities();
|
||||
data = data ?? {};
|
||||
let rowid = 0;
|
||||
let first = true;
|
||||
await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) {
|
||||
rowid = row.rowid;
|
||||
});
|
||||
@ -140,10 +141,12 @@ tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) {
|
||||
await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) {
|
||||
rowid = row.rowid;
|
||||
});
|
||||
first = false;
|
||||
}
|
||||
|
||||
let modified = false;
|
||||
let rows = [];
|
||||
print(include_private ? true: false, ids);
|
||||
await ssb.sqlAsync(`
|
||||
SELECT messages.id, author, content, timestamp
|
||||
FROM messages
|
||||
@ -153,17 +156,18 @@ tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) {
|
||||
messages.rowid <= ?3 AND
|
||||
((json_extract(messages.content, '$.type') = ?4 AND
|
||||
(?5 IS NULL OR json_extract(messages.content, '$.parent') = ?5)) OR
|
||||
content LIKE '"%')
|
||||
`, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent], function(row) {
|
||||
(?6 AND content LIKE '"%'))
|
||||
`, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent, include_private ? true : false], function(row) {
|
||||
rows.push(row);
|
||||
});
|
||||
print('done');
|
||||
max_rowid = rowid;
|
||||
for (let row of rows) {
|
||||
if (await process_message(whoami, data, row, kind, parent)) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (modified) {
|
||||
if (first || modified) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -41,10 +41,18 @@ class TfCollectionsAppElement extends LitElement {
|
||||
async read_wikis() {
|
||||
let max_rowid;
|
||||
let wikis;
|
||||
let start_whoami = this.whoami;
|
||||
while (true)
|
||||
{
|
||||
console.log('read_wikis', max_rowid);
|
||||
[max_rowid, wikis] = await tfrpc.rpc.collection(this.owner_ids, 'wiki', undefined, max_rowid, wikis);
|
||||
console.log('read_wikis', this.whoami);
|
||||
let following = Object.keys(await tfrpc.rpc.following([this.whoami]), 2);
|
||||
console.log('following', following);
|
||||
[max_rowid, wikis] = await tfrpc.rpc.collection(following, 'wiki', undefined, max_rowid, wikis, false);
|
||||
console.log('read ->', wikis);
|
||||
if (this.whoami !== start_whoami) {
|
||||
break;
|
||||
}
|
||||
console.log('wikis =>', wikis);
|
||||
this.wikis = wikis;
|
||||
this.update_wiki();
|
||||
}
|
||||
@ -59,10 +67,8 @@ class TfCollectionsAppElement extends LitElement {
|
||||
let wiki_docs;
|
||||
while (true)
|
||||
{
|
||||
console.log('read_wiki_docs', max_rowid);
|
||||
[max_rowid, wiki_docs] = await tfrpc.rpc.collection(this.owner_ids, 'wiki-doc', this.wiki?.id, max_rowid, wiki_docs);
|
||||
if (this.wiki?.id !== start_id) {
|
||||
console.log('ending read_wiki_docs');
|
||||
break;
|
||||
}
|
||||
this.wiki_docs = wiki_docs;
|
||||
@ -188,6 +194,14 @@ class TfCollectionsAppElement extends LitElement {
|
||||
this.update_hash();
|
||||
}
|
||||
|
||||
updated(changed_properties) {
|
||||
if (changed_properties.has('whoami')) {
|
||||
this.wikis = {};
|
||||
this.wiki_docs = {};
|
||||
this.read_wikis();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
let self = this;
|
||||
return html`
|
||||
@ -195,14 +209,14 @@ class TfCollectionsAppElement extends LitElement {
|
||||
<tf-id-picker .ids=${this.ids} selected=${this.whoami} @change=${this.on_whoami_changed} ?hidden=${!this.ids?.length}></tf-id-picker>
|
||||
</div>
|
||||
<div>
|
||||
<tf-collection
|
||||
${keyed(this.whoami, html`<tf-collection
|
||||
.collection=${this.wikis}
|
||||
whoami=${this.whoami}
|
||||
selected_id=${this.wiki?.id}
|
||||
@create=${this.on_wiki_create}
|
||||
@rename=${this.on_wiki_rename}
|
||||
@tombstone=${this.on_wiki_tombstone}
|
||||
@change=${this.on_wiki_changed}></tf-collection>
|
||||
@change=${this.on_wiki_changed}></tf-collection>`)}
|
||||
${keyed(this.wiki_doc?.id, html`<tf-collection
|
||||
.collection=${this.wiki_docs}
|
||||
whoami=${this.whoami}
|
||||
|
Loading…
Reference in New Issue
Block a user