Skip to content

Commit

Permalink
refactor: Move ping sound playing out of the message sending method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc authored Feb 2, 2023
1 parent 8ebae63 commit 57c2c28
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@emotion/react": "11.10.5",
"@types/eslint": "^8.4.10",
"@wireapp/avs": "9.0.20",
"@wireapp/core": "38.8.1",
"@wireapp/core": "38.9.0",
"@wireapp/lru-cache": "3.8.1",
"@wireapp/react-ui-kit": "9.3.4",
"@wireapp/store-engine-dexie": "2.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/script/calling/CallingRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ export class CallingRepository {
}

const message = await this.messageRepository.sendCallingMessage(conversation, content, options);
if (message.state === MessageSendingState.CANCELLED) {
if (message.state === MessageSendingState.CANCELED) {
// If the user has cancelled message sending because of a degradation warning, we abort the call
this.abortCall(
conversationId,
Expand Down
24 changes: 9 additions & 15 deletions src/script/conversation/MessageRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ export class MessageRepository {
legalHoldStatus: conversation.legalHoldStatus(),
});

return this.sendAndInjectMessage(ping, conversation, {enableEphemeral: true, playPingAudio: true});
amplify.publish(WebAppEvents.AUDIO.PLAY, AudioType.OUTGOING_PING);
return this.sendAndInjectMessage(ping, conversation, {enableEphemeral: true});
}

/**
Expand Down Expand Up @@ -336,7 +337,7 @@ export class MessageRepository {
quote: quoteEntity,
};
const {state} = await this.sendText(textPayload);
if (state !== MessageSendingState.CANCELLED) {
if (state !== MessageSendingState.CANCELED) {
await this.handleLinkPreview(textPayload);
}
}
Expand Down Expand Up @@ -375,7 +376,7 @@ export class MessageRepository {
originalMessageId: originalMessage.id,
};
const {state} = await this.sendEdit(messagePayload);
if (state !== MessageSendingState.CANCELLED) {
if (state !== MessageSendingState.CANCELED) {
await this.handleLinkPreview(messagePayload);
}
}
Expand Down Expand Up @@ -472,7 +473,7 @@ export class MessageRepository {
): Promise<EventRecord | void> {
const uploadStarted = Date.now();
const {id, state} = await this.sendAssetMetadata(conversation, file, asImage);
if (state === MessageSendingState.CANCELLED) {
if (state === MessageSendingState.CANCELED) {
throw new ConversationError(
ConversationError.TYPE.DEGRADED_CONVERSATION_CANCELLATION,
ConversationError.MESSAGE.DEGRADED_CONVERSATION_CANCELLATION,
Expand Down Expand Up @@ -664,7 +665,6 @@ export class MessageRepository {
* @param conversation - the conversation the message should be sent to
* @param options
* @param options.syncTimestamp should the message timestamp be synchronized with backend response timestamp
* @param options.playPingAudio should the 'ping' audio be played when message is being sent
* @param options.nativePush use nativePush for sending to mobile devices
* @param options.recipients can be used to target specific users of the conversation. Will send to all the conversation participants if not defined
* @param options.skipSelf do not forward this message to self user (will not encrypt and send to all self clients)
Expand All @@ -675,7 +675,6 @@ export class MessageRepository {
conversation: Conversation,
{
syncTimestamp = true,
playPingAudio = false,
nativePush = true,
enableEphemeral = false,
targetMode,
Expand All @@ -685,7 +684,6 @@ export class MessageRepository {
silentDegradationWarning,
consentType = CONSENT_TYPE.MESSAGE,
}: MessageSendingOptions & {
playPingAudio?: boolean;
enableEphemeral?: boolean;
silentDegradationWarning?: boolean;
skipInjection?: boolean;
Expand All @@ -694,7 +692,6 @@ export class MessageRepository {
targetMode?: MessageTargetMode;
consentType?: CONSENT_TYPE;
} = {
playPingAudio: false,
syncTimestamp: true,
},
) {
Expand All @@ -704,9 +701,6 @@ export class MessageRepository {
const payload = enableEphemeral && messageTimer ? MessageBuilder.wrapInEphemeral(message, messageTimer) : message;

const injectOptimisticEvent = async () => {
if (playPingAudio) {
amplify.publish(WebAppEvents.AUDIO.PLAY, AudioType.OUTGOING_PING);
}
if (!skipInjection) {
const senderId = this.clientState.currentClient().id;
const currentTimestamp = this.serverTimeHandler.toServerTimestamp();
Expand All @@ -728,7 +722,7 @@ export class MessageRepository {
// Trigger an empty mismatch to check for users that have no devices and that could have been removed from the team
await this.onClientMismatch?.({time: preMessageTimestamp}, conversation, silentDegradationWarning);
if (!skipInjection) {
this.updateMessageAsSent(conversation, payload.messageId, syncTimestamp ? sentAt : undefined);
await this.updateMessageAsSent(conversation, payload.messageId, syncTimestamp ? sentAt : undefined);
}
};

Expand All @@ -754,13 +748,13 @@ export class MessageRepository {

const shouldProceedSending = await injectOptimisticEvent();
if (shouldProceedSending === false) {
return {id: payload.messageId, state: MessageSendingState.CANCELLED};
return {id: payload.messageId, state: MessageSendingState.CANCELED};
}

const result = await this.conversationService.send(sendOptions);

if (result.state === MessageSendingState.OUTGOING_SENT) {
handleSuccess(result.sentAt);
await handleSuccess(result.sentAt);
}
return result;
}
Expand Down Expand Up @@ -870,7 +864,7 @@ export class MessageRepository {
targetMode: MessageTargetMode.USERS,
};
const {state} = await this.sendAndInjectMessage(confirmationMessage, conversationEntity, sendingOptions);
if (state === MessageSendingState.CANCELLED) {
if (state === MessageSendingState.CANCELED) {
this.sendAndInjectMessage(confirmationMessage, conversationEntity, {
...sendingOptions,
// If the message was auto cancelled because of a mismatch, we will force sending the message only to the clients we know of (ignoring unverified clients)
Expand Down
32 changes: 16 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4235,22 +4235,22 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/api-client@npm:^22.15.0":
version: 22.15.0
resolution: "@wireapp/api-client@npm:22.15.0"
"@wireapp/api-client@npm:^22.15.1":
version: 22.15.1
resolution: "@wireapp/api-client@npm:22.15.1"
dependencies:
"@wireapp/commons": ^5.0.4
"@wireapp/priority-queue": ^2.0.3
"@wireapp/protocol-messaging": 1.44.0
axios: 1.2.6
axios: 1.3.0
axios-retry: 3.4.0
http-status-codes: 2.2.0
logdown: 3.3.1
reconnecting-websocket: 4.4.0
spark-md5: 3.0.2
tough-cookie: 4.1.2
ws: 8.11.0
checksum: 61cb242765314dd0dbe804daecbba97ea178bc39b91de2442337e4b6ba23e608b3fa2719802982be0c63e4f9118bdb9888cbb7113bacc9bf5521f3fe425f3d2e
checksum: 76c3878319c5114964b8d0f64fcc4c5f6ccc8c5831af3cd1972b2e56cc66ec0b1fd6d9277c98d68d6e046feb4891dc6af810b2295f182d76b0baebf99a56bc55
languageName: node
linkType: hard

Expand Down Expand Up @@ -4303,27 +4303,27 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/core@npm:38.8.1":
version: 38.8.1
resolution: "@wireapp/core@npm:38.8.1"
"@wireapp/core@npm:38.9.0":
version: 38.9.0
resolution: "@wireapp/core@npm:38.9.0"
dependencies:
"@wireapp/api-client": ^22.15.0
"@wireapp/api-client": ^22.15.1
"@wireapp/commons": ^5.0.4
"@wireapp/core-crypto": 0.6.0-rc.3
"@wireapp/cryptobox": 12.8.0
"@wireapp/promise-queue": ^2.1.1
"@wireapp/protocol-messaging": 1.44.0
"@wireapp/store-engine": 5.0.3
"@wireapp/store-engine-dexie": ^2.0.5
axios: 1.2.6
axios: 1.3.0
bazinga64: 6.0.3
hash.js: 1.1.7
http-status-codes: 2.2.0
idb: 7.1.1
logdown: 3.3.1
long: ^5.2.0
uuidjs: 4.2.13
checksum: 0ad3e96226952af61db3b5b0e96fc8a404b7096408f6b8e23ce67b57c30185ccfe0c4cec591dae18ab77b2876222c8102ba2ffb5a27322b9de70611834959d81
checksum: 104115e17468e8fab3aa152eccb6291ec73c74e78280718fe74999d38342af4e21dbcb68d3d3826f885f9492be3f41cb0acda808a62d0494f1df3475bc4d869d
languageName: node
linkType: hard

Expand Down Expand Up @@ -5159,14 +5159,14 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:1.2.6":
version: 1.2.6
resolution: "axios@npm:1.2.6"
"axios@npm:1.3.0":
version: 1.3.0
resolution: "axios@npm:1.3.0"
dependencies:
follow-redirects: ^1.15.0
form-data: ^4.0.0
proxy-from-env: ^1.1.0
checksum: cbd19be3e07d2fbb6a0b126e49880cecdd44c1f68496ae0e7d21e7dc1c31fd59703a8eec51c9fd69034344f519cc1cdc22c22153131063657c4cef50195f0c00
checksum: cdb22319fb0d04d9f1388c6dfeb273e3ef688e803a2bf3bae092771f3c9d334546bd27266ae0db9d6c0108f17ab84df8a39e553fe694810363923427b20080cf
languageName: node
linkType: hard

Expand Down Expand Up @@ -16592,7 +16592,7 @@ __metadata:
"@typescript-eslint/parser": ^5.49.0
"@wireapp/avs": 9.0.20
"@wireapp/copy-config": 2.0.5
"@wireapp/core": 38.8.1
"@wireapp/core": 38.9.0
"@wireapp/eslint-config": 2.1.1
"@wireapp/lru-cache": 3.8.1
"@wireapp/prettier-config": 0.5.2
Expand Down

0 comments on commit 57c2c28

Please sign in to comment.