-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
message_requests.js
99 lines (89 loc) · 2.58 KB
/
message_requests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* global
Backbone,
Whisper,
ConversationController,
*/
/* eslint-disable more/no-then */
// eslint-disable-next-line func-names
(function () {
window.Whisper = window.Whisper || {};
Whisper.MessageRequests = new (Backbone.Collection.extend({
forConversation(conversation) {
if (conversation.get('e164')) {
const syncByE164 = this.findWhere({
threadE164: conversation.get('e164'),
});
if (syncByE164) {
window.log.info(
`Found early message request response for E164 ${conversation.get(
'e164'
)}`
);
this.remove(syncByE164);
return syncByE164;
}
}
if (conversation.get('uuid')) {
const syncByUuid = this.findWhere({
threadUuid: conversation.get('uuid'),
});
if (syncByUuid) {
window.log.info(
`Found early message request response for UUID ${conversation.get(
'uuid'
)}`
);
this.remove(syncByUuid);
return syncByUuid;
}
}
if (conversation.get('groupId')) {
const syncByGroupId = this.findWhere({
groupId: conversation.get('groupId'),
});
if (syncByGroupId) {
window.log.info(
`Found early message request response for GROUP ID ${conversation.get(
'groupId'
)}`
);
this.remove(syncByGroupId);
return syncByGroupId;
}
}
return null;
},
async onResponse(sync) {
try {
const threadE164 = sync.get('threadE164');
const threadUuid = sync.get('threadUuid');
const groupId = sync.get('groupId');
const conversation = groupId
? ConversationController.get(groupId)
: ConversationController.get(
ConversationController.ensureContactIds({
e164: threadE164,
uuid: threadUuid,
})
);
if (!conversation) {
window.log(
`Received message request response for unknown conversation: ${groupId} ${threadUuid} ${threadE164}`
);
return;
}
conversation.applyMessageRequestResponse(sync.get('type'), {
fromSync: true,
});
this.remove(sync);
} catch (error) {
window.log.error(
'MessageRequests.onResponse error:',
error && error.stack ? error.stack : error
);
}
},
}))();
})();