forked from cory/tildefriends
core: Refresh identity info so that you see your name at the top right when editing your profile in ssb.
This commit is contained in:
45
core/core.js
45
core/core.js
@@ -17,6 +17,8 @@ let gProcesses = {};
|
|||||||
let gStatsTimer = false;
|
let gStatsTimer = false;
|
||||||
/** Effectively a process ID. */
|
/** Effectively a process ID. */
|
||||||
let g_handler_index = 0;
|
let g_handler_index = 0;
|
||||||
|
/** Whether updating accounts information is currently scheduled. */
|
||||||
|
let g_update_accounts_scheduled;
|
||||||
/** Time between pings, in milliseconds. */
|
/** Time between pings, in milliseconds. */
|
||||||
const k_ping_interval = 60 * 1000;
|
const k_ping_interval = 60 * 1000;
|
||||||
|
|
||||||
@@ -275,18 +277,23 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
process.sendIdentities = async function () {
|
process.sendIdentities = async function () {
|
||||||
process.app.send(
|
let identities = await ssb_internal.getIdentityInfo(
|
||||||
Object.assign(
|
process?.credentials?.session?.name,
|
||||||
{
|
options?.packageOwner,
|
||||||
action: 'identities',
|
options?.packageName
|
||||||
},
|
|
||||||
await ssb_internal.getIdentityInfo(
|
|
||||||
process?.credentials?.session?.name,
|
|
||||||
options?.packageOwner,
|
|
||||||
options?.packageName
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
let json = JSON.stringify(identities);
|
||||||
|
if (process._last_sent_identities !== json) {
|
||||||
|
process.app.send(
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
|
action: 'identities',
|
||||||
|
},
|
||||||
|
identities
|
||||||
|
)
|
||||||
|
);
|
||||||
|
process._last_sent_identities = json;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
process.setActiveIdentity = async function (identity) {
|
process.setActiveIdentity = async function (identity) {
|
||||||
if (
|
if (
|
||||||
@@ -624,11 +631,27 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
return process;
|
return process;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send any changed account information.
|
||||||
|
*/
|
||||||
|
function updateAccounts() {
|
||||||
|
let promises = [];
|
||||||
|
for (let process of Object.values(gProcesses)) {
|
||||||
|
promises.push(process.sendIdentities());
|
||||||
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSB message added callback.
|
* SSB message added callback.
|
||||||
*/
|
*/
|
||||||
ssb_internal.addEventListener('message', function () {
|
ssb_internal.addEventListener('message', function () {
|
||||||
broadcastEvent('onMessage', [...arguments]);
|
broadcastEvent('onMessage', [...arguments]);
|
||||||
|
|
||||||
|
if (!g_update_accounts_scheduled) {
|
||||||
|
setTimeout(updateAccounts, 1000);
|
||||||
|
g_update_accounts_scheduled = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ssb_internal.addEventListener('blob', function () {
|
ssb_internal.addEventListener('blob', function () {
|
||||||
|
|||||||
37
src/ssb.db.c
37
src/ssb.db.c
@@ -623,6 +623,12 @@ static char* _tf_ssb_db_get_message_blob_wants(sqlite3* db, int64_t rowid)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef enum _message_type_t
|
||||||
|
{
|
||||||
|
k_message_type_other,
|
||||||
|
k_message_type_post,
|
||||||
|
} message_type_t;
|
||||||
|
|
||||||
typedef struct _message_store_t
|
typedef struct _message_store_t
|
||||||
{
|
{
|
||||||
char id[k_id_base64_len];
|
char id[k_id_base64_len];
|
||||||
@@ -635,6 +641,7 @@ typedef struct _message_store_t
|
|||||||
const char* content;
|
const char* content;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
|
||||||
|
message_type_t type;
|
||||||
bool out_stored;
|
bool out_stored;
|
||||||
char* out_blob_wants;
|
char* out_blob_wants;
|
||||||
|
|
||||||
@@ -717,26 +724,25 @@ static void _tf_ssb_db_store_message_after_work(tf_ssb_t* ssb, int status, void*
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
JSContext* context = tf_ssb_get_context(ssb);
|
if (store->type == k_message_type_post)
|
||||||
JSValue content = JS_ParseJSON(context, store->content, strlen(store->content), NULL);
|
|
||||||
if (JS_IsObject(content))
|
|
||||||
{
|
{
|
||||||
JSValue type_value = JS_GetPropertyStr(context, content, "type");
|
JSContext* context = tf_ssb_get_context(ssb);
|
||||||
const char* type = JS_ToCString(context, type_value);
|
JSValue content = JS_ParseJSON(context, store->content, strlen(store->content), NULL);
|
||||||
if (type && strcmp(type, "post") == 0)
|
if (JS_IsObject(content))
|
||||||
{
|
{
|
||||||
|
JSValue type_value = JS_GetPropertyStr(context, content, "type");
|
||||||
|
const char* type = JS_ToCString(context, type_value);
|
||||||
JSValue text_value = JS_GetPropertyStr(context, content, "text");
|
JSValue text_value = JS_GetPropertyStr(context, content, "text");
|
||||||
const char* text = JS_ToCString(context, text_value);
|
const char* text = JS_ToCString(context, text_value);
|
||||||
|
|
||||||
void tf_notify_message_added_ios(const char* identifier, const char* title, const char* content);
|
void tf_notify_message_added_ios(const char* identifier, const char* title, const char* content);
|
||||||
tf_notify_message_added_ios(store->id, type, text);
|
tf_notify_message_added_ios(store->id, type, text);
|
||||||
JS_FreeCString(context, text);
|
JS_FreeCString(context, text);
|
||||||
JS_FreeValue(context, text_value);
|
JS_FreeValue(context, text_value);
|
||||||
|
JS_FreeCString(context, type);
|
||||||
|
JS_FreeValue(context, type_value);
|
||||||
}
|
}
|
||||||
JS_FreeCString(context, type);
|
JS_FreeValue(context, content);
|
||||||
JS_FreeValue(context, type_value);
|
|
||||||
}
|
}
|
||||||
JS_FreeValue(context, content);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (store->callback)
|
if (store->callback)
|
||||||
@@ -800,6 +806,16 @@ void tf_ssb_db_store_message(
|
|||||||
JS_FreeValue(context, timestampval);
|
JS_FreeValue(context, timestampval);
|
||||||
|
|
||||||
JSValue contentval = JS_GetPropertyStr(context, val, "content");
|
JSValue contentval = JS_GetPropertyStr(context, val, "content");
|
||||||
|
JSValue typeval = JS_IsObject(contentval) ? JS_GetPropertyStr(context, contentval, "type") : JS_UNDEFINED;
|
||||||
|
const char* type = JS_IsString(typeval) ? JS_ToCString(context, typeval) : NULL;
|
||||||
|
message_type_t message_type = k_message_type_other;
|
||||||
|
if (type)
|
||||||
|
{
|
||||||
|
message_type = strcmp(type, "post") == 0 ? k_message_type_post : k_message_type_other;
|
||||||
|
}
|
||||||
|
JS_FreeCString(context, type);
|
||||||
|
JS_FreeValue(context, typeval);
|
||||||
|
|
||||||
JSValue content = JS_JSONStringify(context, contentval, JS_NULL, JS_NULL);
|
JSValue content = JS_JSONStringify(context, contentval, JS_NULL, JS_NULL);
|
||||||
size_t content_len;
|
size_t content_len;
|
||||||
const char* contentstr = JS_ToCStringLen(context, &content_len, content);
|
const char* contentstr = JS_ToCStringLen(context, &content_len, content);
|
||||||
@@ -811,6 +827,7 @@ void tf_ssb_db_store_message(
|
|||||||
.sequence = sequence,
|
.sequence = sequence,
|
||||||
.timestamp = timestamp,
|
.timestamp = timestamp,
|
||||||
.content = contentstr,
|
.content = contentstr,
|
||||||
|
.type = message_type,
|
||||||
.length = content_len,
|
.length = content_len,
|
||||||
.flags = flags,
|
.flags = flags,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user