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(
|
response.send(
|
||||||
JSON.stringify({
|
JSON.stringify(Object.assign({
|
||||||
action: 'session',
|
action: 'session',
|
||||||
credentials: credentials,
|
credentials: credentials,
|
||||||
identities: await ssb.getIdentities(credentials?.session?.name),
|
|
||||||
identity: await core.getActiveIdentity(
|
|
||||||
credentials?.session?.name,
|
|
||||||
packageOwner,
|
|
||||||
packageName
|
|
||||||
),
|
|
||||||
parentApp: parentApp,
|
parentApp: parentApp,
|
||||||
id: blobId,
|
id: blobId,
|
||||||
}),
|
}, await core.getIdentityInfo(credentials?.session?.name, packageOwner, packageName))),
|
||||||
0x1
|
0x1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ class TfNavigationElement extends LitElement {
|
|||||||
show_version: {type: Boolean},
|
show_version: {type: Boolean},
|
||||||
identity: {type: String},
|
identity: {type: String},
|
||||||
identities: {type: Array},
|
identities: {type: Array},
|
||||||
|
names: {type: Object},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ class TfNavigationElement extends LitElement {
|
|||||||
this.status = {};
|
this.status = {};
|
||||||
this.spark_lines = {};
|
this.spark_lines = {};
|
||||||
this.identities = [];
|
this.identities = [];
|
||||||
|
this.names = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,16 +150,17 @@ class TfNavigationElement extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render_identity() {
|
render_identity() {
|
||||||
|
let self = this;
|
||||||
if (this.identities?.length) {
|
if (this.identities?.length) {
|
||||||
return html`
|
return html`
|
||||||
<link type="text/css" rel="stylesheet" href="/static/w3.css" />
|
<link type="text/css" rel="stylesheet" href="/static/w3.css" />
|
||||||
<select
|
<select
|
||||||
@change=${this.set_active_identity}
|
@change=${this.set_active_identity}
|
||||||
class="w3-button w3-cyan w3-bar-item w3-right"
|
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(
|
${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>
|
</select>
|
||||||
`;
|
`;
|
||||||
@ -1176,6 +1179,7 @@ function _receive_websocket_message(message) {
|
|||||||
navigation.credentials = message.credentials;
|
navigation.credentials = message.credentials;
|
||||||
navigation.identities = message.identities;
|
navigation.identities = message.identities;
|
||||||
navigation.identity = message.identity;
|
navigation.identity = message.identity;
|
||||||
|
navigation.names = message.names;
|
||||||
} else if (message && message.action == 'permissions') {
|
} else if (message && message.action == 'permissions') {
|
||||||
let navigation = document.getElementsByTagName('tf-navigation')[0];
|
let navigation = document.getElementsByTagName('tf-navigation')[0];
|
||||||
navigation.permissions = message.permissions ?? {};
|
navigation.permissions = message.permissions ?? {};
|
||||||
@ -1183,6 +1187,7 @@ function _receive_websocket_message(message) {
|
|||||||
let navigation = document.getElementsByTagName('tf-navigation')[0];
|
let navigation = document.getElementsByTagName('tf-navigation')[0];
|
||||||
navigation.identities = message.identities;
|
navigation.identities = message.identities;
|
||||||
navigation.identity = message.identity;
|
navigation.identity = message.identity;
|
||||||
|
navigation.names = message.names;
|
||||||
} else if (message && message.action == 'ready') {
|
} else if (message && message.action == 'ready') {
|
||||||
setStatusMessage(null);
|
setStatusMessage(null);
|
||||||
if (window.location.hash) {
|
if (window.location.hash) {
|
||||||
|
53
core/core.js
53
core/core.js
@ -540,17 +540,13 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
process.sendIdentities = async function () {
|
process.sendIdentities = async function () {
|
||||||
process.app.send({
|
process.app.send(Object.assign({
|
||||||
action: 'identities',
|
action: 'identities',
|
||||||
identities: await ssb.getIdentities(
|
}, await getIdentityInfo(
|
||||||
process?.credentials?.session?.name
|
process?.credentials?.session?.name,
|
||||||
),
|
options?.packageOwner,
|
||||||
identity: await getActiveIdentity(
|
options?.packageName
|
||||||
process?.credentials?.session?.name,
|
)));
|
||||||
options.packageOwner,
|
|
||||||
options.packageName
|
|
||||||
),
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
process.setActiveIdentity = async function (identity) {
|
process.setActiveIdentity = async function (identity) {
|
||||||
if (
|
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 {
|
export {
|
||||||
gGlobalSettings as globalSettings,
|
gGlobalSettings as globalSettings,
|
||||||
setGlobalSettings,
|
setGlobalSettings,
|
||||||
@ -1565,4 +1597,5 @@ export {
|
|||||||
invoke,
|
invoke,
|
||||||
getSessionProcessBlob,
|
getSessionProcessBlob,
|
||||||
getActiveIdentity,
|
getActiveIdentity,
|
||||||
|
getIdentityInfo,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user