2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2018-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-05-26 01:01:56 +00:00
|
|
|
window.setImmediate = window.nodeSetImmediate;
|
|
|
|
|
2020-03-05 21:14:58 +00:00
|
|
|
const getKeysForIdentifierMap = {};
|
2018-05-26 01:01:56 +00:00
|
|
|
const messagesSentMap = {};
|
|
|
|
|
|
|
|
const fakeCall = () => Promise.resolve();
|
|
|
|
|
|
|
|
const fakeAPI = {
|
|
|
|
confirmCode: fakeCall,
|
|
|
|
getAttachment: fakeCall,
|
|
|
|
getAvatar: fakeCall,
|
|
|
|
getDevices: fakeCall,
|
2020-03-05 21:14:58 +00:00
|
|
|
// getKeysForIdentifier : fakeCall,
|
2021-02-18 16:40:26 +00:00
|
|
|
getMessageSocket: () => new window.MockSocket('ws://localhost:8081/'),
|
2018-05-26 01:01:56 +00:00
|
|
|
getMyKeys: fakeCall,
|
|
|
|
getProfile: fakeCall,
|
|
|
|
getProvisioningSocket: fakeCall,
|
|
|
|
putAttachment: fakeCall,
|
|
|
|
registerKeys: fakeCall,
|
|
|
|
requestVerificationSMS: fakeCall,
|
|
|
|
requestVerificationVoice: fakeCall,
|
|
|
|
// sendMessages: fakeCall,
|
|
|
|
setSignedPreKey: fakeCall,
|
|
|
|
|
2020-03-05 21:14:58 +00:00
|
|
|
getKeysForIdentifier(number) {
|
|
|
|
const res = getKeysForIdentifierMap[number];
|
2018-05-26 01:01:56 +00:00
|
|
|
if (res !== undefined) {
|
2020-03-05 21:14:58 +00:00
|
|
|
delete getKeysForIdentifierMap[number];
|
2018-05-26 01:01:56 +00:00
|
|
|
return Promise.resolve(res);
|
2018-07-21 21:51:20 +00:00
|
|
|
}
|
2020-03-05 21:14:58 +00:00
|
|
|
throw new Error('getKeysForIdentfier of unknown/used number');
|
2018-05-26 01:01:56 +00:00
|
|
|
},
|
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
sendMessages(destination, messageArray) {
|
2018-11-02 18:02:53 +00:00
|
|
|
for (let i = 0, max = messageArray.length; i < max; i += 1) {
|
2018-07-21 21:51:20 +00:00
|
|
|
const msg = messageArray[i];
|
2018-05-26 01:01:56 +00:00
|
|
|
if (
|
2018-11-02 18:02:53 +00:00
|
|
|
(msg.type !== 1 && msg.type !== 3) ||
|
2018-05-26 01:01:56 +00:00
|
|
|
msg.destinationDeviceId === undefined ||
|
|
|
|
msg.destinationRegistrationId === undefined ||
|
|
|
|
msg.body === undefined ||
|
2018-11-02 18:02:53 +00:00
|
|
|
msg.timestamp === undefined ||
|
2018-05-26 01:01:56 +00:00
|
|
|
msg.relay !== undefined ||
|
|
|
|
msg.destination !== undefined
|
2021-03-02 21:09:17 +00:00
|
|
|
) {
|
2018-05-26 01:01:56 +00:00
|
|
|
throw new Error('Invalid message');
|
2021-03-02 21:09:17 +00:00
|
|
|
}
|
2018-05-26 01:01:56 +00:00
|
|
|
|
|
|
|
messagesSentMap[
|
2018-07-21 21:51:20 +00:00
|
|
|
`${destination}.${messageArray[i].destinationDeviceId}`
|
2018-05-26 01:01:56 +00:00
|
|
|
] = msg;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
window.WebAPI = {
|
|
|
|
connect: () => fakeAPI,
|
|
|
|
};
|