forked from cory/tildefriends
WIP managing a per-app current identity from the Tilde Friends navigation bar.
This commit is contained in:
51
core/core.js
51
core/core.js
@ -508,6 +508,30 @@ async function getProcessBlob(blobId, key, options) {
|
||||
url: options?.url,
|
||||
},
|
||||
};
|
||||
process.sendIdentities = async function() {
|
||||
process.app.send({
|
||||
action: 'identities',
|
||||
identities: await ssb.getIdentities(process?.credentials?.session?.name),
|
||||
identity: await getActiveIdentity(process?.credentials?.session?.name, options.packageOwner, options.packageName),
|
||||
});
|
||||
};
|
||||
process.setActiveIdentity = async function(identity) {
|
||||
if (process?.credentials?.session?.name && options.packageOwner && options.packageName) {
|
||||
await new Database(process?.credentials?.session?.name).set(`id:${options.packageOwner}:${options.packageName}`, identity);
|
||||
}
|
||||
process.sendIdentities();
|
||||
};
|
||||
process.createIdentity = async function() {
|
||||
if (
|
||||
process.credentials &&
|
||||
process.credentials.session &&
|
||||
process.credentials.session.name
|
||||
) {
|
||||
let id = ssb.createIdentity(process.credentials.session.name);
|
||||
await process.sendIdentities();
|
||||
return id;
|
||||
}
|
||||
}
|
||||
if (process.credentials?.permissions?.administration) {
|
||||
imports.core.globalSettingsDescriptions = function () {
|
||||
let settings = Object.assign({}, k_global_settings);
|
||||
@ -578,15 +602,7 @@ async function getProcessBlob(blobId, key, options) {
|
||||
Object.keys(ssb).map((key) => [key, ssb[key].bind(ssb)])
|
||||
);
|
||||
imports.ssb.port = tildefriends.ssb_port;
|
||||
imports.ssb.createIdentity = function () {
|
||||
if (
|
||||
process.credentials &&
|
||||
process.credentials.session &&
|
||||
process.credentials.session.name
|
||||
) {
|
||||
return ssb.createIdentity(process.credentials.session.name);
|
||||
}
|
||||
};
|
||||
imports.ssb.createIdentity = () => process.createIdentity();
|
||||
imports.ssb.addIdentity = function (id) {
|
||||
if (
|
||||
process.credentials &&
|
||||
@ -613,6 +629,8 @@ async function getProcessBlob(blobId, key, options) {
|
||||
});
|
||||
}
|
||||
};
|
||||
imports.ssb.setActiveIdentity = id => process.setActiveIdentity(id);
|
||||
imports.ssb.getActiveIdentity = () => getActiveIdentity(process.credentials?.session?.name, options.packageOwner, options.packageName);
|
||||
imports.ssb.getOwnerIdentities = function () {
|
||||
if (options.packageOwner) {
|
||||
return ssb.getIdentities(options.packageOwner);
|
||||
@ -1458,10 +1476,25 @@ function storePermission(user, packageOwner, packageName, permission, allow) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function getActiveIdentity(user, packageOwner, packageName) {
|
||||
if (user && packageOwner && packageName) {
|
||||
let id = await new Database(user).get(`id:${packageOwner}:${packageName}`);
|
||||
if (!id) {
|
||||
let ids = await ssb.getIdentities(user);
|
||||
if (ids) {
|
||||
id = ids[0];
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
gGlobalSettings as globalSettings,
|
||||
setGlobalSettings,
|
||||
enableStats,
|
||||
invoke,
|
||||
getSessionProcessBlob,
|
||||
getActiveIdentity,
|
||||
};
|
||||
|
Reference in New Issue
Block a user