forked from cory/tildefriends
Made it possible to add wiki editors.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4628 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
1484a87cad
commit
5b2ace80d4
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "📝",
|
||||
"previous": "&dWRvF06sP9/nrZmGjF+px+KFPEjT6bg2/u7vENWvUyM=.sha256"
|
||||
"previous": "&Unu5AZjyD0RF/QzPh2/u7DuU8IPuSFSjYFkmiWAWcqk=.sha256"
|
||||
}
|
@ -32,6 +32,7 @@ tfrpc.register(async function following(ids, depth) {
|
||||
});
|
||||
|
||||
tfrpc.register(async function appendMessage(id, message) {
|
||||
print('APPENDING', message);
|
||||
return ssb.appendMessageWithIdentity(id, message);
|
||||
});
|
||||
|
||||
@ -123,6 +124,9 @@ async function process_message(whoami, collection, message, kind, parent) {
|
||||
}
|
||||
} else {
|
||||
collection[message.id] = Object.assign(content, {id: message.id});
|
||||
if (!collection[message.id].editors) {
|
||||
collection[message.id].editors = [message.author];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ class TfCollectionsAppElement extends LitElement {
|
||||
ids: {type: Array},
|
||||
owner_ids: {type: Array},
|
||||
whoami: {type: String},
|
||||
following: {type: Array},
|
||||
|
||||
wikis: {type: Object},
|
||||
wiki_docs: {type: Object},
|
||||
@ -14,6 +15,8 @@ class TfCollectionsAppElement extends LitElement {
|
||||
wiki: {type: Object},
|
||||
wiki_doc: {type: Object},
|
||||
hash: {type: String},
|
||||
|
||||
adding_editor: {type: Boolean},
|
||||
};
|
||||
}
|
||||
|
||||
@ -21,6 +24,7 @@ class TfCollectionsAppElement extends LitElement {
|
||||
super();
|
||||
this.ids = [];
|
||||
this.owner_ids = [];
|
||||
this.following = [];
|
||||
this.load();
|
||||
let self = this;
|
||||
tfrpc.register(function hash_changed(hash) {
|
||||
@ -33,6 +37,7 @@ class TfCollectionsAppElement extends LitElement {
|
||||
this.ids = await tfrpc.rpc.getIdentities();
|
||||
this.owner_ids = await tfrpc.rpc.getOwnerIdentities();
|
||||
this.whoami = await tfrpc.rpc.localStorageGet('collections_whoami');
|
||||
this.following = Object.keys(await tfrpc.rpc.following([this.whoami], 2)).sort();
|
||||
|
||||
await this.read_wikis();
|
||||
await this.read_Wiki_docs();
|
||||
@ -45,8 +50,7 @@ class TfCollectionsAppElement extends LitElement {
|
||||
while (true)
|
||||
{
|
||||
console.log('read_wikis', this.whoami);
|
||||
let following = Object.keys(await tfrpc.rpc.following([this.whoami], 2)).sort();
|
||||
[max_rowid, wikis] = await tfrpc.rpc.collection(following, 'wiki', undefined, max_rowid, wikis, false);
|
||||
[max_rowid, wikis] = await tfrpc.rpc.collection(this.following, 'wiki', undefined, max_rowid, wikis, false);
|
||||
console.log('read ->', wikis);
|
||||
if (this.whoami !== start_whoami) {
|
||||
break;
|
||||
@ -129,6 +133,7 @@ class TfCollectionsAppElement extends LitElement {
|
||||
this.wiki = event.detail.value;
|
||||
this.wiki_doc = undefined;
|
||||
this.wiki_docs = undefined;
|
||||
this.adding_editor = false;
|
||||
this.update_hash();
|
||||
this.read_wiki_docs();
|
||||
}
|
||||
@ -148,6 +153,21 @@ class TfCollectionsAppElement extends LitElement {
|
||||
});
|
||||
}
|
||||
|
||||
async on_add_editor(event) {
|
||||
let id = this.shadowRoot.getElementById('add_editor').value;
|
||||
let editors = [...this.wiki.editors];
|
||||
if (editors.indexOf(id) == -1) {
|
||||
editors.push(id);
|
||||
editors.sort();
|
||||
}
|
||||
await tfrpc.rpc.appendMessage(this.whoami, {
|
||||
type: 'wiki',
|
||||
key: this.wiki.id,
|
||||
editors: editors,
|
||||
});
|
||||
this.adding_editor = false;
|
||||
}
|
||||
|
||||
async on_wiki_tombstone(event) {
|
||||
await tfrpc.rpc.appendMessage(this.whoami, {
|
||||
type: 'wiki',
|
||||
@ -224,6 +244,16 @@ class TfCollectionsAppElement extends LitElement {
|
||||
@rename=${this.on_wiki_doc_rename}
|
||||
@tombstone=${this.on_wiki_doc_tombstone}
|
||||
@change=${this.on_wiki_doc_changed}></tf-collection>`)}
|
||||
<div ?hidden=${!this.wiki?.editors}>
|
||||
Editors: ${this.wiki?.editors}
|
||||
<button @click=${() => self.adding_editor = true} ?hidden=${this.wiki?.editors?.indexOf(this.whoami) == -1 || this.adding_editor}>+</button>
|
||||
<div ?hidden=${!this.adding_editor}>
|
||||
<label for="add_editor">Add Editor:</label>
|
||||
<input type="text" id="add_editor"></input>
|
||||
<button @click=${this.on_add_editor}>Add Editor</button>
|
||||
<button @click=${() => self.adding_editor = false}>x</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
${this.wiki_doc && this.wiki_doc.parent === this.wiki?.id ? html`
|
||||
<tf-wiki-doc
|
||||
|
Loading…
Reference in New Issue
Block a user