2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2014-11-13 22:36:09 +00:00
|
|
|
*/
|
2016-02-05 21:02:48 +00:00
|
|
|
|
2016-03-13 00:58:21 +00:00
|
|
|
function stringToArrayBuffer(str) {
|
|
|
|
if (typeof str !== 'string') {
|
|
|
|
throw new Error('Passed non-string to stringToArrayBuffer');
|
|
|
|
}
|
|
|
|
var res = new ArrayBuffer(str.length);
|
|
|
|
var uint = new Uint8Array(res);
|
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
|
|
uint[i] = str.charCodeAt(i);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-02-05 21:02:48 +00:00
|
|
|
function Message(options) {
|
|
|
|
this.body = options.body;
|
|
|
|
this.attachments = options.attachments || [];
|
|
|
|
this.group = options.group;
|
|
|
|
this.flags = options.flags;
|
|
|
|
this.recipients = options.recipients;
|
|
|
|
this.timestamp = options.timestamp;
|
|
|
|
this.needsSync = options.needsSync;
|
2016-09-28 23:54:05 +00:00
|
|
|
this.expireTimer = options.expireTimer;
|
2017-09-11 16:50:35 +00:00
|
|
|
this.profileKey = options.profileKey;
|
2016-02-23 01:29:17 +00:00
|
|
|
|
|
|
|
if (!(this.recipients instanceof Array) || this.recipients.length < 1) {
|
|
|
|
throw new Error('Invalid recipient list');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.group && this.recipients.length > 1) {
|
|
|
|
throw new Error('Invalid recipient list for non-group');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof this.timestamp !== 'number') {
|
|
|
|
throw new Error('Invalid timestamp');
|
|
|
|
}
|
|
|
|
|
2016-10-02 23:38:20 +00:00
|
|
|
if (this.expireTimer !== undefined && this.expireTimer !== null) {
|
2016-09-28 23:54:05 +00:00
|
|
|
if (typeof this.expireTimer !== 'number' || !(this.expireTimer >= 0)) {
|
|
|
|
throw new Error('Invalid expireTimer');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 01:29:17 +00:00
|
|
|
if (this.attachments) {
|
|
|
|
if (!(this.attachments instanceof Array)) {
|
|
|
|
throw new Error('Invalid message attachments');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.flags !== undefined) {
|
|
|
|
if (typeof this.flags !== 'number') {
|
|
|
|
throw new Error('Invalid message flags');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.isEndSession()) {
|
|
|
|
if (this.body !== null || this.group !== null || this.attachments.length !== 0) {
|
|
|
|
throw new Error('Invalid end session message');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( (typeof this.timestamp !== 'number') ||
|
|
|
|
(this.body && typeof this.body !== 'string') ) {
|
|
|
|
throw new Error('Invalid message body');
|
|
|
|
}
|
|
|
|
if (this.group) {
|
|
|
|
if ( (typeof this.group.id !== 'string') ||
|
|
|
|
(typeof this.group.type !== 'number') ) {
|
|
|
|
throw new Error('Invalid group context');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-05 21:02:48 +00:00
|
|
|
}
|
2016-02-06 00:42:53 +00:00
|
|
|
|
2016-02-05 21:02:48 +00:00
|
|
|
Message.prototype = {
|
|
|
|
constructor: Message,
|
2016-02-23 01:29:17 +00:00
|
|
|
isEndSession: function() {
|
|
|
|
return (this.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION);
|
|
|
|
},
|
2016-02-05 21:02:48 +00:00
|
|
|
toProto: function() {
|
|
|
|
if (this.dataMessage instanceof textsecure.protobuf.DataMessage) {
|
2016-02-05 21:41:30 +00:00
|
|
|
return this.dataMessage;
|
2016-02-05 21:02:48 +00:00
|
|
|
}
|
2016-02-05 22:46:15 +00:00
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
2016-09-29 00:10:39 +00:00
|
|
|
if (this.body) {
|
|
|
|
proto.body = this.body;
|
|
|
|
}
|
2016-02-24 23:22:51 +00:00
|
|
|
proto.attachments = this.attachmentPointers;
|
2016-02-05 21:41:30 +00:00
|
|
|
if (this.flags) {
|
|
|
|
proto.flags = this.flags;
|
|
|
|
}
|
|
|
|
if (this.group) {
|
2016-02-05 22:46:15 +00:00
|
|
|
proto.group = new textsecure.protobuf.GroupContext();
|
2016-03-13 00:58:21 +00:00
|
|
|
proto.group.id = stringToArrayBuffer(this.group.id);
|
2016-02-05 22:46:15 +00:00
|
|
|
proto.group.type = this.group.type
|
2016-02-05 21:41:30 +00:00
|
|
|
}
|
2016-09-28 23:54:05 +00:00
|
|
|
if (this.expireTimer) {
|
|
|
|
proto.expireTimer = this.expireTimer;
|
|
|
|
}
|
2016-02-05 21:02:48 +00:00
|
|
|
|
2017-09-11 16:50:35 +00:00
|
|
|
if (this.profileKey) {
|
|
|
|
proto.profileKey = this.profileKey;
|
|
|
|
}
|
|
|
|
|
2016-02-05 21:41:30 +00:00
|
|
|
this.dataMessage = proto;
|
2016-02-05 21:02:48 +00:00
|
|
|
return proto;
|
2016-02-05 21:41:30 +00:00
|
|
|
},
|
|
|
|
toArrayBuffer: function() {
|
|
|
|
return this.toProto().toArrayBuffer();
|
2016-02-05 21:02:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-11 16:50:35 +00:00
|
|
|
function MessageSender(url, username, password, cdn_url) {
|
|
|
|
this.server = new TextSecureServer(url, username, password, cdn_url);
|
2015-10-19 20:52:44 +00:00
|
|
|
this.pendingMessages = {};
|
2015-09-25 01:01:13 +00:00
|
|
|
}
|
2015-08-28 21:45:44 +00:00
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
MessageSender.prototype = {
|
|
|
|
constructor: MessageSender,
|
|
|
|
makeAttachmentPointer: function(attachment) {
|
|
|
|
if (typeof attachment !== 'object' || attachment == null) {
|
|
|
|
return Promise.resolve(undefined);
|
2015-08-28 21:45:44 +00:00
|
|
|
}
|
2015-09-25 01:01:13 +00:00
|
|
|
var proto = new textsecure.protobuf.AttachmentPointer();
|
2016-05-08 00:49:45 +00:00
|
|
|
proto.key = libsignal.crypto.getRandomBytes(64);
|
2015-09-25 01:01:13 +00:00
|
|
|
|
2016-05-08 00:49:45 +00:00
|
|
|
var iv = libsignal.crypto.getRandomBytes(16);
|
2017-03-08 00:54:15 +00:00
|
|
|
return textsecure.crypto.encryptAttachment(attachment.data, proto.key, iv).then(function(result) {
|
|
|
|
return this.server.putAttachment(result.ciphertext).then(function(id) {
|
2015-09-25 01:01:13 +00:00
|
|
|
proto.id = id;
|
|
|
|
proto.contentType = attachment.contentType;
|
2017-03-08 00:54:15 +00:00
|
|
|
proto.digest = result.digest;
|
2017-04-18 18:26:05 +00:00
|
|
|
if (attachment.fileName) {
|
|
|
|
proto.fileName = attachment.fileName;
|
|
|
|
}
|
2017-04-18 18:44:03 +00:00
|
|
|
if (attachment.size) {
|
|
|
|
proto.size = attachment.size;
|
|
|
|
}
|
2017-05-10 22:32:05 +00:00
|
|
|
if (attachment.flags) {
|
|
|
|
proto.flags = attachment.flags;
|
|
|
|
}
|
2015-09-25 01:01:13 +00:00
|
|
|
return proto;
|
|
|
|
});
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2015-11-17 20:00:41 +00:00
|
|
|
retransmitMessage: function(number, jsonData, timestamp) {
|
|
|
|
var outgoing = new OutgoingMessage(this.server);
|
|
|
|
return outgoing.transmitMessage(number, jsonData, timestamp);
|
|
|
|
},
|
|
|
|
|
2017-08-12 00:16:22 +00:00
|
|
|
validateRetryContentMessage: function(content) {
|
|
|
|
// We want at least one field set, but not more than one
|
|
|
|
var count = 0;
|
|
|
|
count += content.syncMessage ? 1 : 0;
|
|
|
|
count += content.dataMessage ? 1 : 0;
|
|
|
|
count += content.callMessage ? 1 : 0;
|
|
|
|
count += content.nullMessage ? 1 : 0;
|
|
|
|
if (count !== 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's most likely that dataMessage will be populated, so we look at it in detail
|
|
|
|
var data = content.dataMessage;
|
|
|
|
if (data && !data.attachments.length && !data.body && !data.expireTimer && !data.flags && !data.group) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
getRetryProto: function(message, timestamp) {
|
|
|
|
// If message was sent before v0.41.3 was released on Aug 7, then it was most certainly a DataMessage
|
|
|
|
//
|
|
|
|
// var d = new Date('2017-08-07T07:00:00.000Z');
|
|
|
|
// d.getTime();
|
|
|
|
var august7 = 1502089200000;
|
|
|
|
if (timestamp < august7) {
|
|
|
|
return textsecure.protobuf.DataMessage.decode(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is ugly. But we don't know what kind of proto we need to decode...
|
|
|
|
try {
|
|
|
|
// Simply decoding as a Content message may throw
|
|
|
|
var proto = textsecure.protobuf.Content.decode(message);
|
|
|
|
|
|
|
|
// But it might also result in an invalid object, so we try to detect that
|
|
|
|
if (this.validateRetryContentMessage(proto)) {
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
return textsecure.protobuf.DataMessage.decode(message);
|
|
|
|
} catch(e) {
|
|
|
|
// If this call throws, something has really gone wrong, we'll fail to send
|
|
|
|
return textsecure.protobuf.DataMessage.decode(message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
tryMessageAgain: function(number, encodedMessage, timestamp) {
|
2017-08-12 00:16:22 +00:00
|
|
|
var proto = this.getRetryProto(encodedMessage, timestamp);
|
2015-10-01 20:30:23 +00:00
|
|
|
return this.sendIndividualProto(number, proto, timestamp);
|
2015-09-25 01:01:13 +00:00
|
|
|
},
|
|
|
|
|
2015-11-17 20:00:41 +00:00
|
|
|
queueJobForNumber: function(number, runJob) {
|
2017-07-19 19:05:24 +00:00
|
|
|
var taskWithTimeout = textsecure.createTaskWithTimeout(runJob, 'queueJobForNumber ' + number);
|
|
|
|
|
2015-11-17 20:00:41 +00:00
|
|
|
var runPrevious = this.pendingMessages[number] || Promise.resolve();
|
2017-07-19 19:05:24 +00:00
|
|
|
var runCurrent = this.pendingMessages[number] = runPrevious.then(taskWithTimeout, taskWithTimeout);
|
2015-11-17 20:00:41 +00:00
|
|
|
runCurrent.then(function() {
|
|
|
|
if (this.pendingMessages[number] === runCurrent) {
|
|
|
|
delete this.pendingMessages[number];
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2016-02-24 23:22:51 +00:00
|
|
|
uploadMedia: function(message) {
|
2016-02-05 21:41:30 +00:00
|
|
|
return Promise.all(
|
|
|
|
message.attachments.map(this.makeAttachmentPointer.bind(this))
|
|
|
|
).then(function(attachmentPointers) {
|
2016-02-24 23:22:51 +00:00
|
|
|
message.attachmentPointers = attachmentPointers;
|
|
|
|
}).catch(function(error) {
|
|
|
|
if (error instanceof Error && error.name === 'HTTPError') {
|
|
|
|
throw new textsecure.MessageError(message, error);
|
|
|
|
} else {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
sendMessage: function(attrs) {
|
|
|
|
var message = new Message(attrs);
|
|
|
|
return this.uploadMedia(message).then(function() {
|
2016-02-05 21:41:30 +00:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
this.sendMessageProto(
|
|
|
|
message.timestamp,
|
|
|
|
message.recipients,
|
|
|
|
message.toProto(),
|
|
|
|
function(res) {
|
|
|
|
res.dataMessage = message.toArrayBuffer();
|
|
|
|
if (res.errors.length > 0) {
|
|
|
|
reject(res);
|
|
|
|
} else {
|
|
|
|
resolve(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}.bind(this));
|
2016-02-24 23:22:51 +00:00
|
|
|
}.bind(this));
|
2016-02-05 21:41:30 +00:00
|
|
|
},
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
sendMessageProto: function(timestamp, numbers, message, callback, silent) {
|
2017-02-16 02:27:06 +00:00
|
|
|
var rejections = textsecure.storage.get('signedKeyRotationRejected', 0);
|
|
|
|
if (rejections > 5) {
|
|
|
|
throw new textsecure.SignedPreKeyRotationError(numbers, message.toArrayBuffer(), timestamp);
|
|
|
|
}
|
|
|
|
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
var outgoing = new OutgoingMessage(this.server, timestamp, numbers, message, silent, callback);
|
2015-11-17 20:00:41 +00:00
|
|
|
|
|
|
|
numbers.forEach(function(number) {
|
|
|
|
this.queueJobForNumber(number, function() {
|
|
|
|
return outgoing.sendToNumber(number);
|
|
|
|
});
|
|
|
|
}.bind(this));
|
2015-09-25 01:01:13 +00:00
|
|
|
},
|
|
|
|
|
2017-02-16 02:27:06 +00:00
|
|
|
retrySendMessageProto: function(numbers, encodedMessage, timestamp) {
|
|
|
|
var proto = textsecure.protobuf.DataMessage.decode(encodedMessage);
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
this.sendMessageProto(timestamp, numbers, proto, function(res) {
|
2017-12-01 21:31:48 +00:00
|
|
|
if (res.errors.length > 0) {
|
2017-02-16 02:27:06 +00:00
|
|
|
reject(res);
|
2017-12-01 21:31:48 +00:00
|
|
|
} else {
|
2017-02-16 02:27:06 +00:00
|
|
|
resolve(res);
|
2017-12-01 21:31:48 +00:00
|
|
|
}
|
2017-02-16 02:27:06 +00:00
|
|
|
});
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
sendIndividualProto: function(number, proto, timestamp, silent) {
|
2015-09-25 01:01:13 +00:00
|
|
|
return new Promise(function(resolve, reject) {
|
2017-11-21 23:20:07 +00:00
|
|
|
var callback = function(res) {
|
|
|
|
if (res.errors.length > 0) {
|
2015-11-20 00:50:14 +00:00
|
|
|
reject(res);
|
2017-11-21 23:20:07 +00:00
|
|
|
} else {
|
2015-11-20 00:50:14 +00:00
|
|
|
resolve(res);
|
2017-11-21 23:20:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
this.sendMessageProto(timestamp, [number], proto, callback, silent);
|
2015-09-25 01:01:13 +00:00
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2017-06-21 23:21:47 +00:00
|
|
|
createSyncMessage: function() {
|
|
|
|
var syncMessage = new textsecure.protobuf.SyncMessage();
|
|
|
|
|
|
|
|
// Generate a random int from 1 and 512
|
|
|
|
var buffer = libsignal.crypto.getRandomBytes(1);
|
|
|
|
var paddingLength = (new Uint8Array(buffer)[0] & 0x1ff) + 1;
|
|
|
|
|
|
|
|
// Generate a random padding buffer of the chosen size
|
|
|
|
syncMessage.padding = libsignal.crypto.getRandomBytes(paddingLength);
|
|
|
|
|
|
|
|
return syncMessage;
|
|
|
|
},
|
|
|
|
|
2016-09-29 00:37:57 +00:00
|
|
|
sendSyncMessage: function(encodedDataMessage, timestamp, destination, expirationStartTimestamp) {
|
2015-09-25 01:01:13 +00:00
|
|
|
var myNumber = textsecure.storage.user.getNumber();
|
|
|
|
var myDevice = textsecure.storage.user.getDeviceId();
|
2015-11-28 00:29:38 +00:00
|
|
|
if (myDevice == 1) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
var dataMessage = textsecure.protobuf.DataMessage.decode(encodedDataMessage);
|
|
|
|
var sentMessage = new textsecure.protobuf.SyncMessage.Sent();
|
|
|
|
sentMessage.timestamp = timestamp;
|
|
|
|
sentMessage.message = dataMessage;
|
|
|
|
if (destination) {
|
|
|
|
sentMessage.destination = destination;
|
2015-08-28 21:45:44 +00:00
|
|
|
}
|
2016-09-29 00:37:57 +00:00
|
|
|
if (expirationStartTimestamp) {
|
|
|
|
sentMessage.expirationStartTimestamp = expirationStartTimestamp;
|
|
|
|
}
|
2017-06-21 23:21:47 +00:00
|
|
|
var syncMessage = this.createSyncMessage();
|
2015-11-28 00:29:38 +00:00
|
|
|
syncMessage.sent = sentMessage;
|
|
|
|
var contentMessage = new textsecure.protobuf.Content();
|
|
|
|
contentMessage.syncMessage = syncMessage;
|
2017-12-01 21:31:48 +00:00
|
|
|
|
|
|
|
var silent = true;
|
|
|
|
return this.sendIndividualProto(myNumber, contentMessage, Date.now(), silent);
|
2015-09-25 01:01:13 +00:00
|
|
|
},
|
|
|
|
|
2017-05-24 20:28:40 +00:00
|
|
|
getProfile: function(number) {
|
2017-05-27 00:05:49 +00:00
|
|
|
return this.server.getProfile(number);
|
2017-05-24 20:28:40 +00:00
|
|
|
},
|
2017-09-11 16:50:35 +00:00
|
|
|
getAvatar: function(path) {
|
|
|
|
return this.server.getAvatar(path);
|
|
|
|
},
|
2017-05-24 20:28:40 +00:00
|
|
|
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
sendRequestConfigurationSyncMessage: function() {
|
|
|
|
var myNumber = textsecure.storage.user.getNumber();
|
|
|
|
var myDevice = textsecure.storage.user.getDeviceId();
|
|
|
|
if (myDevice != 1) {
|
|
|
|
var request = new textsecure.protobuf.SyncMessage.Request();
|
|
|
|
request.type = textsecure.protobuf.SyncMessage.Request.Type.CONFIGURATION;
|
|
|
|
var syncMessage = this.createSyncMessage();
|
|
|
|
syncMessage.request = request;
|
|
|
|
var contentMessage = new textsecure.protobuf.Content();
|
|
|
|
contentMessage.syncMessage = syncMessage;
|
|
|
|
|
2017-12-01 21:31:48 +00:00
|
|
|
var silent = true;
|
|
|
|
return this.sendIndividualProto(myNumber, contentMessage, Date.now(), silent);
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
},
|
2015-09-25 01:01:13 +00:00
|
|
|
sendRequestGroupSyncMessage: function() {
|
|
|
|
var myNumber = textsecure.storage.user.getNumber();
|
|
|
|
var myDevice = textsecure.storage.user.getDeviceId();
|
|
|
|
if (myDevice != 1) {
|
|
|
|
var request = new textsecure.protobuf.SyncMessage.Request();
|
|
|
|
request.type = textsecure.protobuf.SyncMessage.Request.Type.GROUPS;
|
2017-06-21 23:21:47 +00:00
|
|
|
var syncMessage = this.createSyncMessage();
|
2015-09-25 01:01:13 +00:00
|
|
|
syncMessage.request = request;
|
|
|
|
var contentMessage = new textsecure.protobuf.Content();
|
|
|
|
contentMessage.syncMessage = syncMessage;
|
|
|
|
|
2017-12-01 21:31:48 +00:00
|
|
|
var silent = true;
|
|
|
|
return this.sendIndividualProto(myNumber, contentMessage, Date.now(), silent);
|
2015-08-28 21:45:44 +00:00
|
|
|
}
|
2017-08-17 19:20:40 +00:00
|
|
|
|
|
|
|
return Promise.resolve();
|
2015-09-25 01:01:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sendRequestContactSyncMessage: function() {
|
|
|
|
var myNumber = textsecure.storage.user.getNumber();
|
|
|
|
var myDevice = textsecure.storage.user.getDeviceId();
|
|
|
|
if (myDevice != 1) {
|
|
|
|
var request = new textsecure.protobuf.SyncMessage.Request();
|
|
|
|
request.type = textsecure.protobuf.SyncMessage.Request.Type.CONTACTS;
|
2017-06-21 23:21:47 +00:00
|
|
|
var syncMessage = this.createSyncMessage();
|
2015-09-25 01:01:13 +00:00
|
|
|
syncMessage.request = request;
|
|
|
|
var contentMessage = new textsecure.protobuf.Content();
|
|
|
|
contentMessage.syncMessage = syncMessage;
|
|
|
|
|
2017-12-01 21:31:48 +00:00
|
|
|
var silent = true;
|
|
|
|
return this.sendIndividualProto(myNumber, contentMessage, Date.now(), silent);
|
2015-08-28 21:45:44 +00:00
|
|
|
}
|
2017-08-17 19:20:40 +00:00
|
|
|
|
|
|
|
return Promise.resolve();
|
2015-09-25 01:01:13 +00:00
|
|
|
},
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
sendReadReceipts: function(sender, timestamps) {
|
|
|
|
var receiptMessage = new textsecure.protobuf.ReceiptMessage();
|
|
|
|
receiptMessage.type = textsecure.protobuf.ReceiptMessage.Type.READ;
|
|
|
|
receiptMessage.timestamps = timestamps;
|
|
|
|
|
|
|
|
var contentMessage = new textsecure.protobuf.Content();
|
|
|
|
contentMessage.receiptMessage = receiptMessage;
|
|
|
|
|
2017-12-01 21:31:48 +00:00
|
|
|
var silent = true;
|
|
|
|
return this.sendIndividualProto(sender, contentMessage, Date.now(), silent);
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
},
|
2016-02-26 01:10:22 +00:00
|
|
|
syncReadMessages: function(reads) {
|
2016-02-20 00:28:08 +00:00
|
|
|
var myNumber = textsecure.storage.user.getNumber();
|
|
|
|
var myDevice = textsecure.storage.user.getDeviceId();
|
|
|
|
if (myDevice != 1) {
|
2017-06-21 23:21:47 +00:00
|
|
|
var syncMessage = this.createSyncMessage();
|
2016-02-20 00:28:08 +00:00
|
|
|
syncMessage.read = [];
|
2016-02-26 01:10:22 +00:00
|
|
|
for (var i = 0; i < reads.length; ++i) {
|
2016-02-20 00:28:08 +00:00
|
|
|
var read = new textsecure.protobuf.SyncMessage.Read();
|
2016-02-26 01:10:22 +00:00
|
|
|
read.timestamp = reads[i].timestamp;
|
|
|
|
read.sender = reads[i].sender;
|
2016-02-20 00:28:08 +00:00
|
|
|
syncMessage.read.push(read);
|
|
|
|
}
|
|
|
|
var contentMessage = new textsecure.protobuf.Content();
|
|
|
|
contentMessage.syncMessage = syncMessage;
|
|
|
|
|
2017-12-01 21:31:48 +00:00
|
|
|
var silent = true;
|
|
|
|
return this.sendIndividualProto(myNumber, contentMessage, Date.now(), silent);
|
2016-02-20 00:28:08 +00:00
|
|
|
}
|
2017-08-17 19:20:40 +00:00
|
|
|
|
|
|
|
return Promise.resolve();
|
2016-02-20 00:28:08 +00:00
|
|
|
},
|
2017-06-16 01:11:18 +00:00
|
|
|
syncVerification: function(destination, state, identityKey) {
|
2017-06-15 22:00:04 +00:00
|
|
|
var myNumber = textsecure.storage.user.getNumber();
|
|
|
|
var myDevice = textsecure.storage.user.getDeviceId();
|
2017-12-04 23:28:38 +00:00
|
|
|
var now = Date.now();
|
|
|
|
|
2018-01-11 02:12:24 +00:00
|
|
|
if (myDevice == 1) {
|
2017-12-04 23:28:38 +00:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
// First send a null message to mask the sync message.
|
|
|
|
var nullMessage = new textsecure.protobuf.NullMessage();
|
2017-06-15 22:00:04 +00:00
|
|
|
|
2017-12-04 23:28:38 +00:00
|
|
|
// Generate a random int from 1 and 512
|
2017-06-22 22:24:01 +00:00
|
|
|
var buffer = libsignal.crypto.getRandomBytes(1);
|
2017-12-04 23:28:38 +00:00
|
|
|
var paddingLength = (new Uint8Array(buffer)[0] & 0x1ff) + 1;
|
2017-06-22 22:24:01 +00:00
|
|
|
|
2017-12-04 23:28:38 +00:00
|
|
|
// Generate a random padding buffer of the chosen size
|
|
|
|
nullMessage.padding = libsignal.crypto.getRandomBytes(paddingLength);
|
2017-06-15 22:00:04 +00:00
|
|
|
|
2017-12-04 23:28:38 +00:00
|
|
|
var contentMessage = new textsecure.protobuf.Content();
|
|
|
|
contentMessage.nullMessage = nullMessage;
|
2017-06-15 22:00:04 +00:00
|
|
|
|
2017-12-04 23:28:38 +00:00
|
|
|
// We want the NullMessage to look like a normal outgoing message; not silent
|
|
|
|
const promise = this.sendIndividualProto(destination, contentMessage, now);
|
2017-06-22 22:24:01 +00:00
|
|
|
|
2017-12-04 23:28:38 +00:00
|
|
|
return promise.then(function() {
|
|
|
|
var verified = new textsecure.protobuf.Verified();
|
|
|
|
verified.state = state;
|
|
|
|
verified.destination = destination;
|
|
|
|
verified.identityKey = identityKey;
|
|
|
|
verified.nullMessage = nullMessage.padding;
|
2017-06-22 22:24:01 +00:00
|
|
|
|
2017-12-04 23:28:38 +00:00
|
|
|
var syncMessage = this.createSyncMessage();
|
|
|
|
syncMessage.verified = verified;
|
2017-06-22 22:24:01 +00:00
|
|
|
|
2017-12-04 23:28:38 +00:00
|
|
|
var contentMessage = new textsecure.protobuf.Content();
|
|
|
|
contentMessage.syncMessage = syncMessage;
|
2017-08-17 19:20:40 +00:00
|
|
|
|
2017-12-04 23:28:38 +00:00
|
|
|
var silent = true;
|
|
|
|
return this.sendIndividualProto(myNumber, contentMessage, now, silent);
|
|
|
|
}.bind(this));
|
2017-06-15 22:00:04 +00:00
|
|
|
},
|
2015-09-25 01:01:13 +00:00
|
|
|
|
|
|
|
sendGroupProto: function(numbers, proto, timestamp) {
|
|
|
|
timestamp = timestamp || Date.now();
|
|
|
|
var me = textsecure.storage.user.getNumber();
|
|
|
|
numbers = numbers.filter(function(number) { return number != me; });
|
2015-11-07 02:51:18 +00:00
|
|
|
if (numbers.length === 0) {
|
|
|
|
return Promise.reject(new Error('No other members in the group'));
|
|
|
|
}
|
2015-09-25 01:01:13 +00:00
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
2017-12-01 21:31:48 +00:00
|
|
|
var silent = true;
|
|
|
|
var callback = function(res) {
|
2015-11-20 00:57:48 +00:00
|
|
|
res.dataMessage = proto.toArrayBuffer();
|
2017-11-21 23:20:07 +00:00
|
|
|
if (res.errors.length > 0) {
|
2015-11-20 00:50:14 +00:00
|
|
|
reject(res);
|
2017-11-21 23:20:07 +00:00
|
|
|
} else {
|
2015-11-20 00:50:14 +00:00
|
|
|
resolve(res);
|
2017-11-21 23:20:07 +00:00
|
|
|
}
|
2017-12-01 21:31:48 +00:00
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
this.sendMessageProto(timestamp, numbers, proto, callback, silent);
|
2015-11-20 00:57:48 +00:00
|
|
|
}.bind(this));
|
2015-09-25 01:01:13 +00:00
|
|
|
},
|
|
|
|
|
2017-09-11 16:50:35 +00:00
|
|
|
sendMessageToNumber: function(number, messageText, attachments, timestamp, expireTimer, profileKey) {
|
2016-02-06 00:42:53 +00:00
|
|
|
return this.sendMessage({
|
2016-02-05 21:02:48 +00:00
|
|
|
recipients : [number],
|
|
|
|
body : messageText,
|
|
|
|
timestamp : timestamp,
|
2016-02-05 21:41:30 +00:00
|
|
|
attachments : attachments,
|
2016-09-28 23:54:05 +00:00
|
|
|
needsSync : true,
|
2017-09-11 16:50:35 +00:00
|
|
|
expireTimer : expireTimer,
|
|
|
|
profileKey : profileKey
|
2016-02-05 21:02:48 +00:00
|
|
|
});
|
2015-09-25 01:01:13 +00:00
|
|
|
},
|
|
|
|
|
2017-11-21 23:20:07 +00:00
|
|
|
resetSession: function(number, timestamp) {
|
|
|
|
console.log('resetting secure session');
|
2015-09-25 01:01:13 +00:00
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
|
|
|
proto.body = "TERMINATE";
|
|
|
|
proto.flags = textsecure.protobuf.DataMessage.Flags.END_SESSION;
|
2017-11-21 23:20:07 +00:00
|
|
|
|
|
|
|
var logError = function(prefix) {
|
|
|
|
return function(error) {
|
|
|
|
console.log(
|
|
|
|
prefix,
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
throw error;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var deleteAllSessions = function(number) {
|
|
|
|
return textsecure.storage.protocol.getDeviceIds(number)
|
|
|
|
.then(function(deviceIds) {
|
2016-02-04 02:18:42 +00:00
|
|
|
return Promise.all(deviceIds.map(function(deviceId) {
|
|
|
|
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
2017-11-21 23:20:07 +00:00
|
|
|
console.log('deleting sessions for', address.toString());
|
|
|
|
var sessionCipher = new libsignal.SessionCipher(
|
|
|
|
textsecure.storage.protocol,
|
|
|
|
address
|
|
|
|
);
|
|
|
|
return sessionCipher.deleteAllSessionsForDevice();
|
|
|
|
}));
|
2015-09-22 22:55:47 +00:00
|
|
|
});
|
2017-11-21 23:20:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var sendToContact = deleteAllSessions(number)
|
|
|
|
.catch(logError('resetSession/deleteAllSessions1 error:'))
|
|
|
|
.then(function() {
|
|
|
|
console.log('finished closing local sessions, now sending to contact');
|
|
|
|
return this.sendIndividualProto(number, proto, timestamp)
|
|
|
|
.catch(logError('resetSession/sendToContact error:'))
|
|
|
|
}.bind(this))
|
|
|
|
.then(function() {
|
|
|
|
return deleteAllSessions(number)
|
|
|
|
.catch(logError('resetSession/deleteAllSessions2 error:'));
|
2015-08-28 21:45:44 +00:00
|
|
|
});
|
2017-11-21 23:20:07 +00:00
|
|
|
|
|
|
|
var buffer = proto.toArrayBuffer();
|
|
|
|
var sendSync = this.sendSyncMessage(buffer, timestamp, number)
|
|
|
|
.catch(logError('resetSession/sendSync error:'));
|
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
sendToContact,
|
|
|
|
sendSync
|
|
|
|
]);
|
2015-09-25 01:01:13 +00:00
|
|
|
},
|
2015-01-13 23:27:18 +00:00
|
|
|
|
2017-09-11 16:50:35 +00:00
|
|
|
sendMessageToGroup: function(groupId, messageText, attachments, timestamp, expireTimer, profileKey) {
|
2015-09-25 01:01:13 +00:00
|
|
|
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
|
|
|
if (numbers === undefined)
|
|
|
|
return Promise.reject(new Error("Unknown Group"));
|
2015-01-13 23:27:18 +00:00
|
|
|
|
2016-02-05 22:46:15 +00:00
|
|
|
var me = textsecure.storage.user.getNumber();
|
|
|
|
numbers = numbers.filter(function(number) { return number != me; });
|
|
|
|
if (numbers.length === 0) {
|
|
|
|
return Promise.reject(new Error('No other members in the group'));
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:42:53 +00:00
|
|
|
return this.sendMessage({
|
2016-02-05 22:46:15 +00:00
|
|
|
recipients : numbers,
|
|
|
|
body : messageText,
|
|
|
|
timestamp : timestamp,
|
|
|
|
attachments : attachments,
|
|
|
|
needsSync : true,
|
2016-09-28 23:54:05 +00:00
|
|
|
expireTimer : expireTimer,
|
2017-09-11 16:50:35 +00:00
|
|
|
profileKey : profileKey,
|
2016-02-05 22:46:15 +00:00
|
|
|
group: {
|
|
|
|
id: groupId,
|
|
|
|
type: textsecure.protobuf.GroupContext.Type.DELIVER
|
|
|
|
}
|
|
|
|
});
|
2015-09-25 01:01:13 +00:00
|
|
|
}.bind(this));
|
|
|
|
},
|
2015-08-28 21:45:44 +00:00
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
createGroup: function(numbers, name, avatar) {
|
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
|
|
|
proto.group = new textsecure.protobuf.GroupContext();
|
2015-08-28 21:45:44 +00:00
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
return textsecure.storage.groups.createNewGroup(numbers).then(function(group) {
|
2016-03-13 00:58:21 +00:00
|
|
|
proto.group.id = stringToArrayBuffer(group.id);
|
2015-09-25 01:01:13 +00:00
|
|
|
var numbers = group.numbers;
|
2015-08-28 21:45:44 +00:00
|
|
|
|
|
|
|
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
2015-09-25 01:01:13 +00:00
|
|
|
proto.group.members = numbers;
|
2015-08-28 21:45:44 +00:00
|
|
|
proto.group.name = name;
|
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
return this.makeAttachmentPointer(avatar).then(function(attachment) {
|
|
|
|
proto.group.avatar = attachment;
|
|
|
|
return this.sendGroupProto(numbers, proto).then(function() {
|
|
|
|
return proto.group.id;
|
|
|
|
});
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
},
|
2015-08-28 21:45:44 +00:00
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
updateGroup: function(groupId, name, avatar, numbers) {
|
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
|
|
|
proto.group = new textsecure.protobuf.GroupContext();
|
2015-08-28 21:45:44 +00:00
|
|
|
|
2016-03-13 00:58:21 +00:00
|
|
|
proto.group.id = stringToArrayBuffer(groupId);
|
2015-09-25 01:01:13 +00:00
|
|
|
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
|
|
|
proto.group.name = name;
|
2015-08-28 21:45:44 +00:00
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
return textsecure.storage.groups.addNumbers(groupId, numbers).then(function(numbers) {
|
|
|
|
if (numbers === undefined) {
|
|
|
|
return Promise.reject(new Error("Unknown Group"));
|
|
|
|
}
|
|
|
|
proto.group.members = numbers;
|
2015-08-28 21:45:44 +00:00
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
return this.makeAttachmentPointer(avatar).then(function(attachment) {
|
|
|
|
proto.group.avatar = attachment;
|
|
|
|
return this.sendGroupProto(numbers, proto).then(function() {
|
|
|
|
return proto.group.id;
|
2015-08-28 21:45:44 +00:00
|
|
|
});
|
2015-09-25 01:01:13 +00:00
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
addNumberToGroup: function(groupId, number) {
|
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
|
|
|
proto.group = new textsecure.protobuf.GroupContext();
|
2016-03-13 00:58:21 +00:00
|
|
|
proto.group.id = stringToArrayBuffer(groupId);
|
2015-09-25 01:01:13 +00:00
|
|
|
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
|
|
|
|
|
|
|
return textsecure.storage.groups.addNumbers(groupId, [number]).then(function(numbers) {
|
|
|
|
if (numbers === undefined)
|
|
|
|
return Promise.reject(new Error("Unknown Group"));
|
|
|
|
proto.group.members = numbers;
|
|
|
|
|
|
|
|
return this.sendGroupProto(numbers, proto);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
setGroupName: function(groupId, name) {
|
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
|
|
|
proto.group = new textsecure.protobuf.GroupContext();
|
2016-03-13 00:58:21 +00:00
|
|
|
proto.group.id = stringToArrayBuffer(groupId);
|
2015-09-25 01:01:13 +00:00
|
|
|
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
|
|
|
proto.group.name = name;
|
|
|
|
|
|
|
|
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
|
|
|
if (numbers === undefined)
|
|
|
|
return Promise.reject(new Error("Unknown Group"));
|
|
|
|
proto.group.members = numbers;
|
|
|
|
|
|
|
|
return this.sendGroupProto(numbers, proto);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
setGroupAvatar: function(groupId, avatar) {
|
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
|
|
|
proto.group = new textsecure.protobuf.GroupContext();
|
2016-03-13 00:58:21 +00:00
|
|
|
proto.group.id = stringToArrayBuffer(groupId);
|
2015-09-25 01:01:13 +00:00
|
|
|
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
|
|
|
|
|
|
|
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
|
|
|
if (numbers === undefined)
|
|
|
|
return Promise.reject(new Error("Unknown Group"));
|
|
|
|
proto.group.members = numbers;
|
|
|
|
|
|
|
|
return this.makeAttachmentPointer(avatar).then(function(attachment) {
|
|
|
|
proto.group.avatar = attachment;
|
|
|
|
return this.sendGroupProto(numbers, proto);
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
leaveGroup: function(groupId) {
|
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
|
|
|
proto.group = new textsecure.protobuf.GroupContext();
|
2016-03-13 00:58:21 +00:00
|
|
|
proto.group.id = stringToArrayBuffer(groupId);
|
2015-09-25 01:01:13 +00:00
|
|
|
proto.group.type = textsecure.protobuf.GroupContext.Type.QUIT;
|
|
|
|
|
|
|
|
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
|
|
|
if (numbers === undefined)
|
|
|
|
return Promise.reject(new Error("Unknown Group"));
|
|
|
|
return textsecure.storage.groups.deleteGroup(groupId).then(function() {
|
|
|
|
return this.sendGroupProto(numbers, proto);
|
|
|
|
}.bind(this));
|
|
|
|
});
|
2016-09-29 00:10:39 +00:00
|
|
|
},
|
2017-09-11 16:50:35 +00:00
|
|
|
sendExpirationTimerUpdateToGroup: function(groupId, expireTimer, timestamp, profileKey) {
|
2016-09-29 00:10:39 +00:00
|
|
|
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
|
|
|
if (numbers === undefined)
|
|
|
|
return Promise.reject(new Error("Unknown Group"));
|
|
|
|
|
|
|
|
var me = textsecure.storage.user.getNumber();
|
|
|
|
numbers = numbers.filter(function(number) { return number != me; });
|
|
|
|
if (numbers.length === 0) {
|
|
|
|
return Promise.reject(new Error('No other members in the group'));
|
|
|
|
}
|
|
|
|
return this.sendMessage({
|
|
|
|
recipients : numbers,
|
|
|
|
timestamp : timestamp,
|
|
|
|
needsSync : true,
|
|
|
|
expireTimer : expireTimer,
|
2017-09-11 16:50:35 +00:00
|
|
|
profileKey : profileKey,
|
2016-09-29 00:10:39 +00:00
|
|
|
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
|
|
|
|
group: {
|
|
|
|
id: groupId,
|
|
|
|
type: textsecure.protobuf.GroupContext.Type.DELIVER
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}.bind(this));
|
|
|
|
},
|
2017-09-11 16:50:35 +00:00
|
|
|
sendExpirationTimerUpdateToNumber: function(number, expireTimer, timestamp, profileKey) {
|
2016-09-29 00:10:39 +00:00
|
|
|
var proto = new textsecure.protobuf.DataMessage();
|
|
|
|
return this.sendMessage({
|
|
|
|
recipients : [number],
|
|
|
|
timestamp : timestamp,
|
|
|
|
needsSync : true,
|
|
|
|
expireTimer : expireTimer,
|
2017-09-11 16:50:35 +00:00
|
|
|
profileKey : profileKey,
|
2016-09-29 00:10:39 +00:00
|
|
|
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE
|
|
|
|
});
|
2015-09-25 01:01:13 +00:00
|
|
|
}
|
|
|
|
};
|
2015-08-28 21:45:44 +00:00
|
|
|
|
2015-09-25 01:01:13 +00:00
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
|
2017-09-11 16:50:35 +00:00
|
|
|
textsecure.MessageSender = function(url, username, password, cdn_url) {
|
|
|
|
var sender = new MessageSender(url, username, password, cdn_url);
|
2015-10-03 01:31:07 +00:00
|
|
|
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.ENCRYPT_MESSAGE);
|
2015-11-17 20:00:41 +00:00
|
|
|
textsecure.replay.registerFunction(sender.retransmitMessage.bind(sender), textsecure.replay.Type.TRANSMIT_MESSAGE);
|
2016-02-06 00:42:53 +00:00
|
|
|
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
|
2017-02-16 02:27:06 +00:00
|
|
|
textsecure.replay.registerFunction(sender.retrySendMessageProto.bind(sender), textsecure.replay.Type.RETRY_SEND_MESSAGE_PROTO);
|
2015-09-25 01:01:13 +00:00
|
|
|
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
this.sendExpirationTimerUpdateToNumber = sender.sendExpirationTimerUpdateToNumber.bind(sender);
|
|
|
|
this.sendExpirationTimerUpdateToGroup = sender.sendExpirationTimerUpdateToGroup .bind(sender);
|
|
|
|
this.sendRequestGroupSyncMessage = sender.sendRequestGroupSyncMessage .bind(sender);
|
|
|
|
this.sendRequestContactSyncMessage = sender.sendRequestContactSyncMessage .bind(sender);
|
|
|
|
this.sendRequestConfigurationSyncMessage = sender.sendRequestConfigurationSyncMessage.bind(sender);
|
|
|
|
this.sendMessageToNumber = sender.sendMessageToNumber .bind(sender);
|
2017-11-21 23:20:07 +00:00
|
|
|
this.resetSession = sender.resetSession .bind(sender);
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
this.sendMessageToGroup = sender.sendMessageToGroup .bind(sender);
|
|
|
|
this.createGroup = sender.createGroup .bind(sender);
|
|
|
|
this.updateGroup = sender.updateGroup .bind(sender);
|
|
|
|
this.addNumberToGroup = sender.addNumberToGroup .bind(sender);
|
|
|
|
this.setGroupName = sender.setGroupName .bind(sender);
|
|
|
|
this.setGroupAvatar = sender.setGroupAvatar .bind(sender);
|
|
|
|
this.leaveGroup = sender.leaveGroup .bind(sender);
|
|
|
|
this.sendSyncMessage = sender.sendSyncMessage .bind(sender);
|
|
|
|
this.getProfile = sender.getProfile .bind(sender);
|
|
|
|
this.getAvatar = sender.getAvatar .bind(sender);
|
|
|
|
this.syncReadMessages = sender.syncReadMessages .bind(sender);
|
|
|
|
this.syncVerification = sender.syncVerification .bind(sender);
|
|
|
|
this.sendReadReceipts = sender.sendReadReceipts .bind(sender);
|
2015-09-25 01:01:13 +00:00
|
|
|
};
|
2014-12-24 23:45:51 +00:00
|
|
|
|
2015-10-02 22:02:25 +00:00
|
|
|
textsecure.MessageSender.prototype = {
|
|
|
|
constructor: textsecure.MessageSender
|
2015-08-28 21:45:44 +00:00
|
|
|
};
|