make sure we do not save more than one entry in the read_by
Session has read by only for private chats, so we do not care about having more than one entry in read_by
This commit is contained in:
parent
368c0cd01b
commit
4010373a7b
|
@ -18,7 +18,7 @@ export interface MessageAttributes {
|
|||
preview?: any;
|
||||
body?: string;
|
||||
expirationStartTimestamp: number;
|
||||
read_by: Array<string>;
|
||||
read_by: Array<string>; // we actually only care about the length of this. values are not used for anything
|
||||
expires_at?: number;
|
||||
type: MessageModelType;
|
||||
group_update?: MessageGroupUpdate;
|
||||
|
@ -159,7 +159,7 @@ export interface MessageAttributesOptionals {
|
|||
preview?: any;
|
||||
body?: string;
|
||||
expirationStartTimestamp?: number;
|
||||
read_by?: Array<string>;
|
||||
read_by?: Array<string>; // we actually only care about the length of this. values are not used for anything
|
||||
expires_at?: number;
|
||||
type: MessageModelType;
|
||||
group_update?: MessageGroupUpdate;
|
||||
|
|
|
@ -1323,9 +1323,7 @@ function updateToLokiSchemaVersion22(currentVersion: number, db: BetterSqlite3.D
|
|||
console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`);
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
DROP INDEX messages_duplicate_check;
|
||||
`);
|
||||
db.exec(`DROP INDEX messages_duplicate_check;`);
|
||||
|
||||
db.exec(`
|
||||
ALTER TABLE ${MESSAGES_TABLE} DROP sourceDevice;
|
||||
|
@ -1340,6 +1338,15 @@ function updateToLokiSchemaVersion22(currentVersion: number, db: BetterSqlite3.D
|
|||
);
|
||||
`);
|
||||
|
||||
dropFtsAndTriggers(db);
|
||||
// we also want to remove the read_by it could have 20 times the same value set in the array
|
||||
// we do this once, and updated the code to not allow multiple entries in read_by as we do not care about multiple entries
|
||||
// (read_by is only used in private chats)
|
||||
db.exec(`
|
||||
UPDATE ${MESSAGES_TABLE} SET
|
||||
json = json_remove(json, '$.schemaVersion', '$.recipients', '$.decrypted_at', '$.sourceDevice', '$.read_by')
|
||||
`);
|
||||
rebuildFtsTable(db);
|
||||
writeLokiSchemaVersion(targetVersion, db);
|
||||
})();
|
||||
console.log(`updateToLokiSchemaVersion${targetVersion}: success!`);
|
||||
|
@ -3445,7 +3452,6 @@ function cleanUpUnusedNodeForKeyEntries() {
|
|||
|
||||
const swarmUnused = difference(allEntriesInSnodeForPubkey, allIdsToKeep);
|
||||
|
||||
console.log('swarmStored but unused ', swarmUnused.length);
|
||||
if (swarmUnused.length) {
|
||||
const start = Date.now();
|
||||
|
||||
|
@ -3567,6 +3573,8 @@ function cleanUpOldOpengroups() {
|
|||
);
|
||||
}
|
||||
|
||||
cleanUpMessagesJson();
|
||||
|
||||
rebuildFtsTable(assertGlobalInstance());
|
||||
}
|
||||
|
||||
|
|
|
@ -42,12 +42,17 @@ async function onReadReceipt(receipt: { source: string; timestamp: number; readA
|
|||
return;
|
||||
}
|
||||
|
||||
const readBy = message.get('read_by') || [];
|
||||
// readBy is only used for private conversations
|
||||
// we do not care of who read it. If the length is > 0 , it is read and false otherwise
|
||||
let readBy = message.get('read_by') || [];
|
||||
const expirationStartTimestamp = message.get('expirationStartTimestamp');
|
||||
|
||||
if (!readBy.includes(receipt.source)) {
|
||||
if (!readBy.length) {
|
||||
readBy.push(receipt.source);
|
||||
}
|
||||
if (readBy.length > 1) {
|
||||
readBy = readBy.slice(0, 1);
|
||||
}
|
||||
message.set({
|
||||
read_by: readBy,
|
||||
expirationStartTimestamp: expirationStartTimestamp || Date.now(),
|
||||
|
|
Loading…
Reference in New Issue