Don't show group call start notifications more than once
This commit is contained in:
parent
d479427d88
commit
3c91dce993
3 changed files with 37 additions and 44 deletions
|
@ -2722,10 +2722,16 @@ export class ConversationModel extends window.Backbone
|
|||
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(
|
||||
eraId: string,
|
||||
creatorUuid: string
|
||||
): Promise<void> {
|
||||
): Promise<boolean> {
|
||||
// We want to update the cache quickly in case this function is called multiple times.
|
||||
const oldCachedEraId = this.cachedLatestGroupCallEraId;
|
||||
this.cachedLatestGroupCallEraId = eraId;
|
||||
|
@ -2734,14 +2740,17 @@ export class ConversationModel extends window.Backbone
|
|||
(oldCachedEraId && oldCachedEraId === eraId) ||
|
||||
(await window.Signal.Data.hasGroupCallHistoryMessage(this.id, eraId));
|
||||
|
||||
if (!alreadyHasMessage) {
|
||||
this.addCallHistory({
|
||||
callMode: CallMode.Group,
|
||||
creatorUuid,
|
||||
eraId,
|
||||
startedTime: Date.now(),
|
||||
});
|
||||
if (alreadyHasMessage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await this.addCallHistory({
|
||||
callMode: CallMode.Group,
|
||||
creatorUuid,
|
||||
eraId,
|
||||
startedTime: Date.now(),
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
async addProfileChange(
|
||||
|
|
|
@ -2007,10 +2007,10 @@ export class CallingClass {
|
|||
});
|
||||
}
|
||||
|
||||
public updateCallHistoryForGroupCall(
|
||||
public async updateCallHistoryForGroupCall(
|
||||
conversationId: string,
|
||||
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 (!peekInfo || !peekInfo.eraId || !peekInfo.creator) {
|
||||
return;
|
||||
|
@ -2020,6 +2020,7 @@ export class CallingClass {
|
|||
log.error('updateCallHistoryForGroupCall(): bad creator UUID');
|
||||
return;
|
||||
}
|
||||
const creatorConversation = window.ConversationController.get(creatorUuid);
|
||||
|
||||
const conversation = window.ConversationController.get(conversationId);
|
||||
if (!conversation) {
|
||||
|
@ -2027,24 +2028,24 @@ export class CallingClass {
|
|||
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(
|
||||
conversationId: string,
|
||||
creatorBytes: undefined | Readonly<Uint8Array>
|
||||
private notifyForGroupCall(
|
||||
conversation: Readonly<ConversationModel>,
|
||||
creatorConversation: undefined | Readonly<ConversationModel>
|
||||
): 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 notificationMessage: string;
|
||||
|
||||
|
@ -2074,7 +2075,7 @@ export class CallingClass {
|
|||
message: notificationMessage,
|
||||
onNotificationClick: () => {
|
||||
this.uxActions?.startCallingLobby({
|
||||
conversationId,
|
||||
conversationId: conversation.id,
|
||||
isVideoCall: true,
|
||||
});
|
||||
},
|
||||
|
|
|
@ -859,7 +859,6 @@ function peekNotConnectedGroupCall(
|
|||
|
||||
queue.add(async () => {
|
||||
const state = getState();
|
||||
const { ourUuid } = state.user;
|
||||
|
||||
// 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
|
||||
|
@ -893,7 +892,7 @@ function peekNotConnectedGroupCall(
|
|||
return;
|
||||
}
|
||||
|
||||
calling.updateCallHistoryForGroupCall(conversationId, peekInfo);
|
||||
await calling.updateCallHistoryForGroupCall(conversationId, peekInfo);
|
||||
|
||||
const formattedPeekInfo = calling.formatGroupCallPeekInfoForRedux(
|
||||
peekInfo
|
||||
|
@ -907,22 +906,6 @@ function peekNotConnectedGroupCall(
|
|||
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);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue