fix: messages are no longer randomly deleted

forgot to expire only unread disappearing messages and not all messages
pull/2971/head
William Grant 2 years ago
parent 250e3d0238
commit 515805b94d

@ -345,6 +345,17 @@ async function getUnreadByConversation(
return new MessageCollection(messages); return new MessageCollection(messages);
} }
async function getDisappearingUnreadByConversation(
conversationId: string,
sentBeforeTimestamp: number
): Promise<MessageCollection> {
const messages = await channels.getDisappearingUnreadByConversation(
conversationId,
sentBeforeTimestamp
);
return new MessageCollection(messages);
}
async function markAllAsReadByConversationNoExpiration( async function markAllAsReadByConversationNoExpiration(
conversationId: string, conversationId: string,
returnMessagesUpdated: boolean // for performance reason we do not return them because usually they are not needed returnMessagesUpdated: boolean // for performance reason we do not return them because usually they are not needed
@ -795,6 +806,7 @@ export const Data = {
getMessageByServerId, getMessageByServerId,
filterAlreadyFetchedOpengroupMessage, filterAlreadyFetchedOpengroupMessage,
getUnreadByConversation, getUnreadByConversation,
getDisappearingUnreadByConversation,
getUnreadCountByConversation, getUnreadCountByConversation,
markAllAsReadByConversationNoExpiration, markAllAsReadByConversationNoExpiration,
getMessageCountByType, getMessageCountByType,

@ -42,6 +42,7 @@ const channelsToMake = new Set([
'removeMessage', 'removeMessage',
'removeMessagesByIds', 'removeMessagesByIds',
'getUnreadByConversation', 'getUnreadByConversation',
'getDisappearingUnreadByConversation',
'markAllAsReadByConversationNoExpiration', 'markAllAsReadByConversationNoExpiration',
'getUnreadCountByConversation', 'getUnreadCountByConversation',
'getMessageCountByType', 'getMessageCountByType',

@ -1143,6 +1143,24 @@ function getUnreadByConversation(conversationId: string, sentBeforeTimestamp: nu
return map(rows, row => jsonToObject(row.json)); return map(rows, row => jsonToObject(row.json));
} }
function getDisappearingUnreadByConversation(conversationId: string, sentBeforeTimestamp: number) {
const rows = assertGlobalInstance()
.prepare(
`SELECT * FROM ${MESSAGES_TABLE} WHERE
unread = $unread AND expireTimer > 0 AND
conversationId = $conversationId AND
COALESCE(serverTimestamp, sent_at) <= $sentBeforeTimestamp
${orderByClauseASC};`
)
.all({
unread: toSqliteBoolean(true),
conversationId,
sentBeforeTimestamp,
});
return map(rows, row => jsonToObject(row.json));
}
/** /**
* Warning: This does not start expiration timer * Warning: This does not start expiration timer
*/ */
@ -2383,6 +2401,7 @@ export const sqlNode = {
removeMessagesByIds, removeMessagesByIds,
removeAllMessagesInConversation, removeAllMessagesInConversation,
getUnreadByConversation, getUnreadByConversation,
getDisappearingUnreadByConversation,
markAllAsReadByConversationNoExpiration, markAllAsReadByConversationNoExpiration,
getUnreadCountByConversation, getUnreadCountByConversation,
getMessageCountByType, getMessageCountByType,

@ -698,7 +698,10 @@ async function applyConvoVolatileUpdateFromWrapper(
foundConvo.get('expirationMode') === 'legacy') && foundConvo.get('expirationMode') === 'legacy') &&
foundConvo.get('expireTimer') > 0 foundConvo.get('expireTimer') > 0
) { ) {
const messages2Expire = await Data.getUnreadByConversation(convoId, lastReadMessageTimestamp); const messages2Expire = await Data.getDisappearingUnreadByConversation(
convoId,
lastReadMessageTimestamp
);
if (messages2Expire.length) { if (messages2Expire.length) {
const messageHashes = compact( const messageHashes = compact(

Loading…
Cancel
Save