Fix check for universal timer notification
This commit is contained in:
parent
0f4a1d6e28
commit
a6ce00ff37
4 changed files with 49 additions and 3 deletions
|
@ -2797,12 +2797,11 @@ export class ConversationModel extends window.Backbone
|
|||
return;
|
||||
}
|
||||
|
||||
if (this.get('pendingUniversalTimer') || this.get('expireTimer')) {
|
||||
if (await window.Signal.Data.hasUserInitiatedMessages(this.get('id'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeAt = this.get('active_at');
|
||||
if (activeAt) {
|
||||
if (this.get('pendingUniversalTimer') || this.get('expireTimer')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2824,6 +2823,9 @@ export class ConversationModel extends window.Backbone
|
|||
const message = window.MessageController.getById(notificationId);
|
||||
if (message) {
|
||||
message.cleanup();
|
||||
window.Signal.Data.removeMessage(message.id, {
|
||||
Message: window.Whisper.Message,
|
||||
});
|
||||
}
|
||||
|
||||
if (this.get('expireTimer')) {
|
||||
|
|
|
@ -171,6 +171,7 @@ const dataInterface: ClientInterface = {
|
|||
searchMessagesInConversation,
|
||||
|
||||
getMessageCount,
|
||||
hasUserInitiatedMessages,
|
||||
saveMessage,
|
||||
saveMessages,
|
||||
removeMessage,
|
||||
|
@ -976,6 +977,10 @@ async function getMessageCount(conversationId?: string) {
|
|||
return channels.getMessageCount(conversationId);
|
||||
}
|
||||
|
||||
async function hasUserInitiatedMessages(conversationId: string) {
|
||||
return channels.hasUserInitiatedMessages(conversationId);
|
||||
}
|
||||
|
||||
async function saveMessage(
|
||||
data: MessageType,
|
||||
{ forceSave, Message }: { forceSave?: boolean; Message: typeof MessageModel }
|
||||
|
|
|
@ -215,6 +215,7 @@ export type DataInterface = {
|
|||
) => Promise<Array<ConversationType>>;
|
||||
|
||||
getMessageCount: (conversationId?: string) => Promise<number>;
|
||||
hasUserInitiatedMessages: (conversationId: string) => Promise<boolean>;
|
||||
saveMessages: (
|
||||
arrayOfMessages: Array<MessageType>,
|
||||
options: { forceSave?: boolean }
|
||||
|
|
|
@ -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 } = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue