Fix check for universal timer notification

This commit is contained in:
Fedor Indutny 2021-06-02 13:55:10 -07:00 committed by GitHub
parent 0f4a1d6e28
commit a6ce00ff37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 3 deletions

View file

@ -161,6 +161,7 @@ const dataInterface: ServerInterface = {
searchMessagesInConversation,
getMessageCount,
hasUserInitiatedMessages,
saveMessage,
saveMessages,
removeMessage,
@ -2925,6 +2926,43 @@ async function getMessageCount(conversationId?: string): Promise<number> {
return row['count(*)'];
}
// Called only for private conversations
async function hasUserInitiatedMessages(
conversationId: string
): Promise<boolean> {
const db = getInstance();
// We apply the limit in the sub-query so that `json_extract` wouldn't run
// for additional messages.
const row: { count: number } = db
.prepare<Query>(
`
SELECT COUNT(*) as count FROM
(
SELECT 1 FROM messages
WHERE
conversationId = $conversationId AND
(type IS NULL
OR
type NOT IN (
'profile-change',
'verified-change',
'message-history-unsynced',
'keychange',
'group-v1-migration',
'universal-timer-notification'
)
) AND
json_extract(json, '$.expirationTimerUpdate') IS NULL
LIMIT 1
);
`
)
.get({ conversationId });
return row.count !== 0;
}
function saveMessageSync(
data: MessageType,
options: { forceSave?: boolean; alreadyInTransaction?: boolean } = {}