signal-desktop/libtextsecure/test/fake_api.js

30 lines
904 B
JavaScript
Raw Normal View History

var getKeysForNumberMap = {};
TextSecureServer.getKeysForNumber = function(number, deviceId) {
2018-05-02 16:51:22 +00:00
var res = getKeysForNumberMap[number];
if (res !== undefined) {
delete getKeysForNumberMap[number];
return Promise.resolve(res);
} else throw new Error('getKeysForNumber of unknown/used number');
};
var messagesSentMap = {};
TextSecureServer.sendMessages = function(destination, messageArray) {
2018-05-02 16:51:22 +00:00
for (i in messageArray) {
var msg = messageArray[i];
if (
(msg.type != 1 && msg.type != 3) ||
msg.destinationDeviceId === undefined ||
msg.destinationRegistrationId === undefined ||
msg.body === undefined ||
msg.timestamp == undefined ||
msg.relay !== undefined ||
msg.destination !== undefined
)
throw new Error('Invalid message');
2018-05-02 16:51:22 +00:00
messagesSentMap[
destination + '.' + messageArray[i].destinationDeviceId
] = msg;
}
};