Make the issues app use the global id picker, fix jsonb issues, and fix the global id picker.

This commit is contained in:
Cory McWilliams 2024-04-14 13:47:28 +01:00
parent e2c0f82ec0
commit 96cb6f4b12
4 changed files with 10 additions and 50 deletions

View File

@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "🦟", "emoji": "🦟",
"previous": "&TegdzvFE+im94shygaHkgDYSaSrwY2h0OKUXSRPBQDM=.sha256" "previous": "&cUqvSDUls3jn0haD85LPFAGdkc8wFuy347TtATNcJgg=.sha256"
} }

View File

@ -85,6 +85,9 @@ tfrpc.register(async function store_message(message) {
tfrpc.register(function apps() { tfrpc.register(function apps() {
return core.apps(); return core.apps();
}); });
tfrpc.register(function getActiveIdentity() {
return ssb.getActiveIdentity();
});
tfrpc.register(async function try_decrypt(id, content) { tfrpc.register(async function try_decrypt(id, content) {
return await ssb.privateMessageDecrypt(id, content); return await ssb.privateMessageDecrypt(id, content);
}); });

View File

@ -4,48 +4,6 @@ import * as tfutils from './tf-utils.js';
const k_project = '%Hr+4xEVtjplidSKBlRWi4Aw/0Tfw7B+1OR9BzlDKmOI=.sha256'; const k_project = '%Hr+4xEVtjplidSKBlRWi4Aw/0Tfw7B+1OR9BzlDKmOI=.sha256';
class TfIdPickerElement extends LitElement {
static get properties() {
return {
ids: {type: Array},
selected: {type: String},
};
}
constructor() {
super();
this.load();
}
async load() {
this.selected = await tfrpc.rpc.localStorageGet('whoami');
this.ids = (await tfrpc.rpc.getIdentities()) || [];
}
changed(event) {
this.selected = event.srcElement.value;
tfrpc.rpc.localStorageSet('whoami', this.selected);
}
render() {
if (this.ids) {
return html`
<select @change=${this.changed} style="max-width: 100%">
${this.ids.map(
(id) =>
html`<option ?selected=${id == this.selected} value=${id}>
${id}
</option>`
)}
</select>
`;
} else {
return html`<div>Loading...</div>`;
}
}
}
customElements.define('tf-id-picker', TfIdPickerElement);
class TfComposeElement extends LitElement { class TfComposeElement extends LitElement {
static get properties() { static get properties() {
return { return {
@ -105,10 +63,10 @@ class TfIssuesAppElement extends LitElement {
let issues = {}; let issues = {};
let messages = await tfrpc.rpc.query( let messages = await tfrpc.rpc.query(
` `
WITH issues AS (SELECT messages.* FROM messages_refs JOIN messages ON WITH issues AS (SELECT messages.id, json(messages.content) AS content, messages.author, messages.timestamp FROM messages_refs JOIN messages ON
messages.id = messages_refs.message messages.id = messages_refs.message
WHERE messages_refs.ref = ? AND json_extract(messages.content, '$.type') = 'issue'), WHERE messages_refs.ref = ? AND json_extract(messages.content, '$.type') = 'issue'),
edits AS (SELECT messages.* FROM issues JOIN messages_refs ON edits AS (SELECT messages.id, json(messages.content) AS content, messages.author, messages.timestamp FROM issues JOIN messages_refs ON
issues.id = messages_refs.ref JOIN messages ON issues.id = messages_refs.ref JOIN messages ON
messages.id = messages_refs.message messages.id = messages_refs.message
WHERE json_extract(messages.content, '$.type') IN ('issue-edit', 'post')) WHERE json_extract(messages.content, '$.type') IN ('issue-edit', 'post'))
@ -206,7 +164,7 @@ class TfIssuesAppElement extends LitElement {
if ( if (
confirm(`Are you sure you want to ${open ? 'open' : 'close'} this issue?`) confirm(`Are you sure you want to ${open ? 'open' : 'close'} this issue?`)
) { ) {
let whoami = this.shadowRoot.getElementById('picker').selected; let whoami = await tfrpc.rpc.getActiveIdentity();
await tfrpc.rpc.appendMessage(whoami, { await tfrpc.rpc.appendMessage(whoami, {
type: 'issue-edit', type: 'issue-edit',
issues: [ issues: [
@ -221,7 +179,7 @@ class TfIssuesAppElement extends LitElement {
} }
async create_issue(event) { async create_issue(event) {
let whoami = this.shadowRoot.getElementById('picker').selected; let whoami = await tfrpc.rpc.getActiveIdentity();
await tfrpc.rpc.appendMessage(whoami, { await tfrpc.rpc.appendMessage(whoami, {
type: 'issue', type: 'issue',
project: k_project, project: k_project,
@ -231,7 +189,7 @@ class TfIssuesAppElement extends LitElement {
} }
async reply_to_issue(event) { async reply_to_issue(event) {
let whoami = this.shadowRoot.getElementById('picker').selected; let whoami = await tfrpc.rpc.getActiveIdentity();
await tfrpc.rpc.appendMessage(whoami, { await tfrpc.rpc.appendMessage(whoami, {
type: 'post', type: 'post',
text: event.detail.value, text: event.detail.value,
@ -251,7 +209,6 @@ class TfIssuesAppElement extends LitElement {
render() { render() {
let header = html` let header = html`
<h1>Tilde Friends Issues</h1> <h1>Tilde Friends Issues</h1>
<tf-id-picker id="picker"></tf-id-picker>
`; `;
if (this.selected) { if (this.selected) {
return html` return html`

View File

@ -160,7 +160,7 @@ class TfNavigationElement extends LitElement {
style="text-overflow: ellipsis; overflow: hidden; white-space: nowrap; max-width: 100%" style="text-overflow: ellipsis; overflow: hidden; white-space: nowrap; max-width: 100%"
> >
${this.identities.map( ${this.identities.map(
(x) => html`<option ?selected=${x === this.identity}>${self.names[x]}${self.names[x] === x ? '' : html` - ${x}`}</option>` (x) => html`<option ?selected=${x === this.identity} value=${x}>${self.names[x]}${self.names[x] === x ? '' : html` - ${x}`}</option>`
)} )}
</select> </select>
`; `;