Run prettier.
This commit is contained in:
@ -2,7 +2,7 @@ async function process_message(whoami, collection, message, kind, parent) {
|
||||
let content = JSON.parse(message.content);
|
||||
if (typeof content == 'string') {
|
||||
let x;
|
||||
for (let id of (whoami || [])) {
|
||||
for (let id of whoami || []) {
|
||||
x = await ssb.privateMessageDecrypt(id, content);
|
||||
if (x) {
|
||||
try {
|
||||
@ -17,8 +17,7 @@ async function process_message(whoami, collection, message, kind, parent) {
|
||||
if (!x) {
|
||||
return;
|
||||
}
|
||||
if (content.type !== kind ||
|
||||
(parent && content.parent !== parent)) {
|
||||
if (content.type !== kind || (parent && content.parent !== parent)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -28,7 +27,10 @@ async function process_message(whoami, collection, message, kind, parent) {
|
||||
if (content?.tombstone) {
|
||||
delete collection[content.key];
|
||||
} else {
|
||||
collection[content.key] = Object.assign(collection[content.key] || {}, content);
|
||||
collection[content.key] = Object.assign(
|
||||
collection[content.key] || {},
|
||||
content
|
||||
);
|
||||
}
|
||||
} else {
|
||||
collection[message.id] = Object.assign(content, {id: message.id});
|
||||
@ -40,7 +42,7 @@ async function process_message(whoami, collection, message, kind, parent) {
|
||||
}
|
||||
|
||||
let g_new_message_resolve;
|
||||
let g_new_message_promise = new Promise(function(resolve, reject) {
|
||||
let g_new_message_promise = new Promise(function (resolve, reject) {
|
||||
g_new_message_resolve = resolve;
|
||||
});
|
||||
|
||||
@ -48,9 +50,9 @@ function new_message() {
|
||||
return g_new_message_promise;
|
||||
}
|
||||
|
||||
ssb.addEventListener('message', function(id) {
|
||||
ssb.addEventListener('message', function (id) {
|
||||
let resolve = g_new_message_resolve;
|
||||
g_new_message_promise = new Promise(function(resolve, reject) {
|
||||
g_new_message_promise = new Promise(function (resolve, reject) {
|
||||
g_new_message_resolve = resolve;
|
||||
});
|
||||
if (resolve) {
|
||||
@ -58,26 +60,42 @@ ssb.addEventListener('message', function(id) {
|
||||
}
|
||||
});
|
||||
|
||||
export async function collection(ids, kind, parent, max_rowid, data, include_private) {
|
||||
export async function collection(
|
||||
ids,
|
||||
kind,
|
||||
parent,
|
||||
max_rowid,
|
||||
data,
|
||||
include_private
|
||||
) {
|
||||
let whoami = await ssb.getIdentities();
|
||||
data = data ?? {};
|
||||
let rowid = 0;
|
||||
let first = true;
|
||||
await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) {
|
||||
rowid = row.rowid;
|
||||
});
|
||||
await ssb.sqlAsync(
|
||||
'SELECT MAX(rowid) AS rowid FROM messages',
|
||||
[],
|
||||
function (row) {
|
||||
rowid = row.rowid;
|
||||
}
|
||||
);
|
||||
while (true) {
|
||||
if (rowid == max_rowid) {
|
||||
await new_message();
|
||||
await ssb.sqlAsync('SELECT MAX(rowid) AS rowid FROM messages', [], function(row) {
|
||||
rowid = row.rowid;
|
||||
});
|
||||
await ssb.sqlAsync(
|
||||
'SELECT MAX(rowid) AS rowid FROM messages',
|
||||
[],
|
||||
function (row) {
|
||||
rowid = row.rowid;
|
||||
}
|
||||
);
|
||||
first = false;
|
||||
}
|
||||
|
||||
let modified = false;
|
||||
let rows = [];
|
||||
await ssb.sqlAsync(`
|
||||
await ssb.sqlAsync(
|
||||
`
|
||||
SELECT messages.id, author, content, timestamp
|
||||
FROM messages
|
||||
JOIN json_each(?1) AS id ON messages.author = id.value
|
||||
@ -88,9 +106,19 @@ export async function collection(ids, kind, parent, max_rowid, data, include_pri
|
||||
(?5 IS NULL OR json_extract(messages.content, '$.parent') = ?5)) OR
|
||||
(?6 AND content LIKE '"%'))
|
||||
ORDER BY timestamp
|
||||
`, [JSON.stringify(ids), max_rowid ?? -1, rowid, kind, parent, include_private ? true : false], function(row) {
|
||||
rows.push(row);
|
||||
});
|
||||
`,
|
||||
[
|
||||
JSON.stringify(ids),
|
||||
max_rowid ?? -1,
|
||||
rowid,
|
||||
kind,
|
||||
parent,
|
||||
include_private ? true : false,
|
||||
],
|
||||
function (row) {
|
||||
rows.push(row);
|
||||
}
|
||||
);
|
||||
max_rowid = rowid;
|
||||
for (let row of rows) {
|
||||
if (await process_message(whoami, data, row, kind, parent)) {
|
||||
@ -102,4 +130,4 @@ export async function collection(ids, kind, parent, max_rowid, data, include_pri
|
||||
}
|
||||
}
|
||||
return [rowid, data];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user