diff --git a/core/app.js b/core/app.js
index 5b641001..3ac5e7cf 100644
--- a/core/app.js
+++ b/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
);
diff --git a/core/client.js b/core/client.js
index 4d3dc87f..88e8feba 100644
--- a/core/client.js
+++ b/core/client.js
@@ -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`
`;
@@ -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) {
diff --git a/core/core.js b/core/core.js
index 57ab7b0e..55065f47 100644
--- a/core/core.js
+++ b/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(
- process?.credentials?.session?.name,
- options.packageOwner,
- options.packageName
- ),
- });
+ }, await getIdentityInfo(
+ process?.credentials?.session?.name,
+ 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,
};