Skip to content

Commit

Permalink
Don't show group call start notifications more than once
Browse files Browse the repository at this point in the history
Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
  • Loading branch information
automated-signal and EvanHahn-Signal committed Oct 5, 2021
1 parent 9aaef0d commit 52e1358
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 44 deletions.
25 changes: 17 additions & 8 deletions ts/models/conversations.ts
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
37 changes: 19 additions & 18 deletions ts/services/calling.ts
Expand Up @@ -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;
Expand All @@ -2020,31 +2020,32 @@ export class CallingClass {
log.error('updateCallHistoryForGroupCall(): bad creator UUID');
return;
}
const creatorConversation = window.ConversationController.get(creatorUuid);

const conversation = window.ConversationController.get(conversationId);
if (!conversation) {
log.error('updateCallHistoryForGroupCall(): could not find conversation');
return;
}

conversation.updateCallHistoryForGroupCall(peekInfo.eraId, creatorUuid);
}

public notifyForGroupCall(
conversationId: string,
creatorBytes: undefined | Readonly<Uint8Array>
): void {
const conversation = window.ConversationController.get(conversationId);
if (conversation?.isMuted()) {
return;
}
const isNewCall = await conversation.updateCallHistoryForGroupCall(
peekInfo.eraId,
creatorUuid
);
const wasStartedByMe = Boolean(
creatorConversation && isMe(creatorConversation.attributes)
);
const isAnybodyElseInGroupCall = Boolean(peekInfo.joinedMembers.length);

const creatorUuid = creatorBytes ? bytesToUuid(creatorBytes) : undefined;
const creatorConversation = window.ConversationController.get(creatorUuid);
if (creatorConversation && isMe(creatorConversation.attributes)) {
return;
if (isNewCall && !wasStartedByMe && isAnybodyElseInGroupCall) {
this.notifyForGroupCall(conversation, creatorConversation);
}
}

private notifyForGroupCall(
conversation: Readonly<ConversationModel>,
creatorConversation: undefined | Readonly<ConversationModel>
): void {
let notificationTitle: string;
let notificationMessage: string;

Expand Down Expand Up @@ -2074,7 +2075,7 @@ export class CallingClass {
message: notificationMessage,
onNotificationClick: () => {
this.uxActions?.startCallingLobby({
conversationId,
conversationId: conversation.id,
isVideoCall: true,
});
},
Expand Down
19 changes: 1 addition & 18 deletions ts/state/ducks/calling.ts
Expand Up @@ -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
Expand Down Expand Up @@ -893,7 +892,7 @@ function peekNotConnectedGroupCall(
return;
}

calling.updateCallHistoryForGroupCall(conversationId, peekInfo);
await calling.updateCallHistoryForGroupCall(conversationId, peekInfo);

const formattedPeekInfo = calling.formatGroupCallPeekInfoForRedux(
peekInfo
Expand All @@ -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);
});
};
}
Expand Down

0 comments on commit 52e1358

Please sign in to comment.