Let's get account names to the UI.
This commit is contained in:
parent
26165e30de
commit
dbf28c03e6
10
core/app.js
10
core/app.js
@ -141,18 +141,12 @@ function socket(request, response, client) {
|
||||
}
|
||||
}
|
||||
response.send(
|
||||
JSON.stringify({
|
||||
JSON.stringify(Object.assign({
|
||||
action: 'session',
|
||||
credentials: credentials,
|
||||
identities: await ssb.getIdentities(credentials?.session?.name),
|
||||
identity: await core.getActiveIdentity(
|
||||
credentials?.session?.name,
|
||||
packageOwner,
|
||||
packageName
|
||||
),
|
||||
parentApp: parentApp,
|
||||
id: blobId,
|
||||
}),
|
||||
}, await core.getIdentityInfo(credentials?.session?.name, packageOwner, packageName))),
|
||||
0x1
|
||||
);
|
||||
|
||||
|
@ -58,6 +58,7 @@ class TfNavigationElement extends LitElement {
|
||||
show_version: {type: Boolean},
|
||||
identity: {type: String},
|
||||
identities: {type: Array},
|
||||
names: {type: Object},
|
||||
};
|
||||
}
|
||||
|
||||
@ -68,6 +69,7 @@ class TfNavigationElement extends LitElement {
|
||||
this.status = {};
|
||||
this.spark_lines = {};
|
||||
this.identities = [];
|
||||
this.names = {};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,16 +150,17 @@ class TfNavigationElement extends LitElement {
|
||||
}
|
||||
|
||||
render_identity() {
|
||||
let self = this;
|
||||
if (this.identities?.length) {
|
||||
return html`
|
||||
<link type="text/css" rel="stylesheet" href="/static/w3.css" />
|
||||
<select
|
||||
@change=${this.set_active_identity}
|
||||
class="w3-button w3-cyan w3-bar-item w3-right"
|
||||
style="max-width: 100%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap"
|
||||
style="max-width: 25%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap"
|
||||
>
|
||||
${this.identities.map(
|
||||
(x) => html`<option ?selected=${x === this.identity}>${x}</option>`
|
||||
(x) => html`<option ?selected=${x === this.identity}>${self.names[x]} - ${x}</option>`
|
||||
)}
|
||||
</select>
|
||||
`;
|
||||
@ -1176,6 +1179,7 @@ function _receive_websocket_message(message) {
|
||||
navigation.credentials = message.credentials;
|
||||
navigation.identities = message.identities;
|
||||
navigation.identity = message.identity;
|
||||
navigation.names = message.names;
|
||||
} else if (message && message.action == 'permissions') {
|
||||
let navigation = document.getElementsByTagName('tf-navigation')[0];
|
||||
navigation.permissions = message.permissions ?? {};
|
||||
@ -1183,6 +1187,7 @@ function _receive_websocket_message(message) {
|
||||
let navigation = document.getElementsByTagName('tf-navigation')[0];
|
||||
navigation.identities = message.identities;
|
||||
navigation.identity = message.identity;
|
||||
navigation.names = message.names;
|
||||
} else if (message && message.action == 'ready') {
|
||||
setStatusMessage(null);
|
||||
if (window.location.hash) {
|
||||
|
51
core/core.js
51
core/core.js
@ -540,17 +540,13 @@ async function getProcessBlob(blobId, key, options) {
|
||||
},
|
||||
};
|
||||
process.sendIdentities = async function () {
|
||||
process.app.send({
|
||||
process.app.send(Object.assign({
|
||||
action: 'identities',
|
||||
identities: await ssb.getIdentities(
|
||||
process?.credentials?.session?.name
|
||||
),
|
||||
identity: await getActiveIdentity(
|
||||
}, await getIdentityInfo(
|
||||
process?.credentials?.session?.name,
|
||||
options.packageOwner,
|
||||
options.packageName
|
||||
),
|
||||
});
|
||||
options?.packageOwner,
|
||||
options?.packageName
|
||||
)));
|
||||
};
|
||||
process.setActiveIdentity = async function (identity) {
|
||||
if (
|
||||
@ -1558,6 +1554,42 @@ async function getActiveIdentity(user, packageOwner, packageName) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getIdentityInfo(user, packageOwner, packageName) {
|
||||
let identities = await ssb.getIdentities(
|
||||
user
|
||||
);
|
||||
let names = new Object();
|
||||
for (let identity of identities) {
|
||||
names[identity] = identity;
|
||||
}
|
||||
await ssb.sqlAsync(`
|
||||
SELECT author, name FROM (
|
||||
SELECT
|
||||
messages.author,
|
||||
RANK() OVER (PARTITION BY messages.author ORDER BY messages.sequence DESC) AS author_rank,
|
||||
messages.content ->> 'name' AS name
|
||||
FROM messages
|
||||
JOIN json_each(?) AS ids
|
||||
ON messages.author = ids.value
|
||||
WHERE json_extract(messages.content, '$.type') = 'about' AND content ->> 'about' = messages.author AND name IS NOT NULL)
|
||||
WHERE author_rank = 1
|
||||
`,
|
||||
[JSON.stringify(identities)],
|
||||
function (row) {
|
||||
names[row.author] = row.name;
|
||||
});
|
||||
|
||||
return {
|
||||
identities: identities,
|
||||
identity: await getActiveIdentity(
|
||||
user,
|
||||
packageOwner,
|
||||
packageName
|
||||
),
|
||||
names: names,
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
gGlobalSettings as globalSettings,
|
||||
setGlobalSettings,
|
||||
@ -1565,4 +1597,5 @@ export {
|
||||
invoke,
|
||||
getSessionProcessBlob,
|
||||
getActiveIdentity,
|
||||
getIdentityInfo,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user