forked from cory/tildefriends
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",
|
"type": "tildefriends-app",
|
||||||
"emoji": "📝",
|
"emoji": "📝",
|
||||||
"previous": "&N1wA9DJ6RacaPG52I+ZEhWbbVvf3U1Dcvouh0UkfkG0=.sha256"
|
"previous": "&YeaTOrnB4mPU2htPCtcLH9Ys1rXyyulEroR2gkU7zKw=.sha256"
|
||||||
}
|
}
|
@ -127,10 +127,11 @@ async function process_message(whoami, collection, message, kind, parent) {
|
|||||||
return true;
|
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();
|
let whoami = await ssb.getIdentities();
|
||||||
data = data ?? {};
|
data = data ?? {};
|
||||||
let rowid = 0;
|
let rowid = 0;
|
||||||
|
let first = true;
|
||||||
await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) {
|
await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) {
|
||||||
rowid = row.rowid;
|
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) {
|
await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) {
|
||||||
rowid = row.rowid;
|
rowid = row.rowid;
|
||||||
});
|
});
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let modified = false;
|
let modified = false;
|
||||||
let rows = [];
|
let rows = [];
|
||||||
|
print(include_private ? true: false, ids);
|
||||||
await ssb.sqlAsync(`
|
await ssb.sqlAsync(`
|
||||||
SELECT messages.id, author, content, timestamp
|
SELECT messages.id, author, content, timestamp
|
||||||
FROM messages
|
FROM messages
|
||||||
@ -153,17 +156,18 @@ tfrpc.register(async function collection(ids, kind, parent, max_rowid, data) {
|
|||||||
messages.rowid <= ?3 AND
|
messages.rowid <= ?3 AND
|
||||||
((json_extract(messages.content, '$.type') = ?4 AND
|
((json_extract(messages.content, '$.type') = ?4 AND
|
||||||
(?5 IS NULL OR json_extract(messages.content, '$.parent') = ?5)) OR
|
(?5 IS NULL OR json_extract(messages.content, '$.parent') = ?5)) OR
|
||||||
content LIKE '"%')
|
(?6 AND content LIKE '"%'))
|
||||||
`, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent], function(row) {
|
`, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent, include_private ? true : false], function(row) {
|
||||||
rows.push(row);
|
rows.push(row);
|
||||||
});
|
});
|
||||||
|
print('done');
|
||||||
max_rowid = rowid;
|
max_rowid = rowid;
|
||||||
for (let row of rows) {
|
for (let row of rows) {
|
||||||
if (await process_message(whoami, data, row, kind, parent)) {
|
if (await process_message(whoami, data, row, kind, parent)) {
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (modified) {
|
if (first || modified) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,10 +41,18 @@ class TfCollectionsAppElement extends LitElement {
|
|||||||
async read_wikis() {
|
async read_wikis() {
|
||||||
let max_rowid;
|
let max_rowid;
|
||||||
let wikis;
|
let wikis;
|
||||||
|
let start_whoami = this.whoami;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
console.log('read_wikis', max_rowid);
|
console.log('read_wikis', this.whoami);
|
||||||
[max_rowid, wikis] = await tfrpc.rpc.collection(this.owner_ids, 'wiki', undefined, max_rowid, wikis);
|
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.wikis = wikis;
|
||||||
this.update_wiki();
|
this.update_wiki();
|
||||||
}
|
}
|
||||||
@ -59,10 +67,8 @@ class TfCollectionsAppElement extends LitElement {
|
|||||||
let wiki_docs;
|
let wiki_docs;
|
||||||
while (true)
|
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);
|
[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) {
|
if (this.wiki?.id !== start_id) {
|
||||||
console.log('ending read_wiki_docs');
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.wiki_docs = wiki_docs;
|
this.wiki_docs = wiki_docs;
|
||||||
@ -188,6 +194,14 @@ class TfCollectionsAppElement extends LitElement {
|
|||||||
this.update_hash();
|
this.update_hash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updated(changed_properties) {
|
||||||
|
if (changed_properties.has('whoami')) {
|
||||||
|
this.wikis = {};
|
||||||
|
this.wiki_docs = {};
|
||||||
|
this.read_wikis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let self = this;
|
let self = this;
|
||||||
return html`
|
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>
|
<tf-id-picker .ids=${this.ids} selected=${this.whoami} @change=${this.on_whoami_changed} ?hidden=${!this.ids?.length}></tf-id-picker>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<tf-collection
|
${keyed(this.whoami, html`<tf-collection
|
||||||
.collection=${this.wikis}
|
.collection=${this.wikis}
|
||||||
whoami=${this.whoami}
|
whoami=${this.whoami}
|
||||||
selected_id=${this.wiki?.id}
|
selected_id=${this.wiki?.id}
|
||||||
@create=${this.on_wiki_create}
|
@create=${this.on_wiki_create}
|
||||||
@rename=${this.on_wiki_rename}
|
@rename=${this.on_wiki_rename}
|
||||||
@tombstone=${this.on_wiki_tombstone}
|
@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
|
${keyed(this.wiki_doc?.id, html`<tf-collection
|
||||||
.collection=${this.wiki_docs}
|
.collection=${this.wiki_docs}
|
||||||
whoami=${this.whoami}
|
whoami=${this.whoami}
|
||||||
|
Loading…
Reference in New Issue
Block a user