Don't show group call start notifications more than once

This commit is contained in:
Evan Hahn 2021-10-05 16:11:40 -05:00 committed by GitHub
parent d479427d88
commit 3c91dce993
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 44 deletions

View file

@ -2722,10 +2722,16 @@ export class ConversationModel extends window.Backbone
this.trigger('newmessage', model); this.trigger('newmessage', model);
} }
/**
* Adds a group call history message if one is needed. It won't add history messages for
* the same group call era ID.
*
* Resolves with `true` if a new message was added, and `false` otherwise.
*/
async updateCallHistoryForGroupCall( async updateCallHistoryForGroupCall(
eraId: string, eraId: string,
creatorUuid: string creatorUuid: string
): Promise<void> { ): Promise<boolean> {
// We want to update the cache quickly in case this function is called multiple times. // We want to update the cache quickly in case this function is called multiple times.
const oldCachedEraId = this.cachedLatestGroupCallEraId; const oldCachedEraId = this.cachedLatestGroupCallEraId;
this.cachedLatestGroupCallEraId = eraId; this.cachedLatestGroupCallEraId = eraId;
@ -2734,14 +2740,17 @@ export class ConversationModel extends window.Backbone
(oldCachedEraId && oldCachedEraId === eraId) || (oldCachedEraId && oldCachedEraId === eraId) ||
(await window.Signal.Data.hasGroupCallHistoryMessage(this.id, eraId)); (await window.Signal.Data.hasGroupCallHistoryMessage(this.id, eraId));
if (!alreadyHasMessage) { if (alreadyHasMessage) {
this.addCallHistory({ return false;
callMode: CallMode.Group,
creatorUuid,
eraId,
startedTime: Date.now(),
});
} }
await this.addCallHistory({
callMode: CallMode.Group,
creatorUuid,
eraId,
startedTime: Date.now(),
});
return true;
} }
async addProfileChange( async addProfileChange(

View file

@ -2007,10 +2007,10 @@ export class CallingClass {
}); });
} }
public updateCallHistoryForGroupCall( public async updateCallHistoryForGroupCall(
conversationId: string, conversationId: string,
peekInfo: undefined | PeekInfo peekInfo: undefined | PeekInfo
): void { ): Promise<void> {
// If we don't have the necessary pieces to peek, bail. (It's okay if we don't.) // If we don't have the necessary pieces to peek, bail. (It's okay if we don't.)
if (!peekInfo || !peekInfo.eraId || !peekInfo.creator) { if (!peekInfo || !peekInfo.eraId || !peekInfo.creator) {
return; return;
@ -2020,6 +2020,7 @@ export class CallingClass {
log.error('updateCallHistoryForGroupCall(): bad creator UUID'); log.error('updateCallHistoryForGroupCall(): bad creator UUID');
return; return;
} }
const creatorConversation = window.ConversationController.get(creatorUuid);
const conversation = window.ConversationController.get(conversationId); const conversation = window.ConversationController.get(conversationId);
if (!conversation) { if (!conversation) {
@ -2027,24 +2028,24 @@ export class CallingClass {
return; return;
} }
conversation.updateCallHistoryForGroupCall(peekInfo.eraId, creatorUuid); const isNewCall = await conversation.updateCallHistoryForGroupCall(
peekInfo.eraId,
creatorUuid
);
const wasStartedByMe = Boolean(
creatorConversation && isMe(creatorConversation.attributes)
);
const isAnybodyElseInGroupCall = Boolean(peekInfo.joinedMembers.length);
if (isNewCall && !wasStartedByMe && isAnybodyElseInGroupCall) {
this.notifyForGroupCall(conversation, creatorConversation);
}
} }
public notifyForGroupCall( private notifyForGroupCall(
conversationId: string, conversation: Readonly<ConversationModel>,
creatorBytes: undefined | Readonly<Uint8Array> creatorConversation: undefined | Readonly<ConversationModel>
): void { ): void {
const conversation = window.ConversationController.get(conversationId);
if (conversation?.isMuted()) {
return;
}
const creatorUuid = creatorBytes ? bytesToUuid(creatorBytes) : undefined;
const creatorConversation = window.ConversationController.get(creatorUuid);
if (creatorConversation && isMe(creatorConversation.attributes)) {
return;
}
let notificationTitle: string; let notificationTitle: string;
let notificationMessage: string; let notificationMessage: string;
@ -2074,7 +2075,7 @@ export class CallingClass {
message: notificationMessage, message: notificationMessage,
onNotificationClick: () => { onNotificationClick: () => {
this.uxActions?.startCallingLobby({ this.uxActions?.startCallingLobby({
conversationId, conversationId: conversation.id,
isVideoCall: true, isVideoCall: true,
}); });
}, },

View file

@ -859,7 +859,6 @@ function peekNotConnectedGroupCall(
queue.add(async () => { queue.add(async () => {
const state = getState(); const state = getState();
const { ourUuid } = state.user;
// We make sure we're not trying to peek at a connected (or connecting, or // We make sure we're not trying to peek at a connected (or connecting, or
// reconnecting) call. Because this is asynchronous, it's possible that the call // reconnecting) call. Because this is asynchronous, it's possible that the call
@ -893,7 +892,7 @@ function peekNotConnectedGroupCall(
return; return;
} }
calling.updateCallHistoryForGroupCall(conversationId, peekInfo); await calling.updateCallHistoryForGroupCall(conversationId, peekInfo);
const formattedPeekInfo = calling.formatGroupCallPeekInfoForRedux( const formattedPeekInfo = calling.formatGroupCallPeekInfoForRedux(
peekInfo peekInfo
@ -907,22 +906,6 @@ function peekNotConnectedGroupCall(
ourConversationId: state.user.ourConversationId, ourConversationId: state.user.ourConversationId,
}, },
}); });
// We want to show "Alice started a group call" only if a call isn't ringing or
// active. We wait a moment to make sure that we don't accidentally show a ring
// notification followed swiftly by a less urgent notification.
if (!isAnybodyElseInGroupCall(formattedPeekInfo, ourUuid)) {
return;
}
await sleep(1000);
const newCallingState = getState().calling;
if (
getActiveCall(newCallingState)?.conversationId === conversationId ||
getIncomingCall(newCallingState.callsByConversation, ourUuid)
) {
return;
}
calling.notifyForGroupCall(conversationId, peekInfo.creator);
}); });
}; };
} }