Send timer update messages when changing the timer

This commit is contained in:
lilia 2016-09-28 17:10:39 -07:00
parent 824b7417e9
commit 6074a29046
3 changed files with 112 additions and 30 deletions

View file

@ -38873,7 +38873,9 @@ Message.prototype = {
return this.dataMessage;
}
var proto = new textsecure.protobuf.DataMessage();
proto.body = this.body;
if (this.body) {
proto.body = this.body;
}
proto.attachments = this.attachmentPointers;
if (this.flags) {
proto.flags = this.flags;
@ -39244,6 +39246,39 @@ MessageSender.prototype = {
return this.sendGroupProto(numbers, proto);
}.bind(this));
});
},
sendExpirationTimerUpdateToGroup: function(groupId, expireTimer, timestamp) {
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,
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
group: {
id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER
}
});
}.bind(this));
},
sendExpirationTimerUpdateToNumber: function(number, expireTimer, timestamp) {
var proto = new textsecure.protobuf.DataMessage();
return this.sendMessage({
recipients : [number],
timestamp : timestamp,
needsSync : true,
expireTimer : expireTimer,
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE
});
}
};
@ -39255,19 +39290,21 @@ textsecure.MessageSender = function(url, ports, username, password, attachment_s
textsecure.replay.registerFunction(sender.retransmitMessage.bind(sender), textsecure.replay.Type.TRANSMIT_MESSAGE);
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
this.sendRequestGroupSyncMessage = sender.sendRequestGroupSyncMessage .bind(sender);
this.sendRequestContactSyncMessage = sender.sendRequestContactSyncMessage.bind(sender);
this.sendMessageToNumber = sender.sendMessageToNumber .bind(sender);
this.closeSession = sender.closeSession .bind(sender);
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.syncReadMessages = sender.syncReadMessages .bind(sender);
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.sendMessageToNumber = sender.sendMessageToNumber .bind(sender);
this.closeSession = sender.closeSession .bind(sender);
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.syncReadMessages = sender.syncReadMessages .bind(sender);
};
textsecure.MessageSender.prototype = {

View file

@ -182,10 +182,18 @@
}
});
message.save();
return message;
},
sendExpirationTimerUpdate: function(time) {
this.addExpirationTimerUpdate(time, textsecure.storage.user.getNumber());
// todo: send.
var message = this.addExpirationTimerUpdate(time, textsecure.storage.user.getNumber());
var sendFunc;
if (this.get('type') == 'private') {
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToNumber;
}
else {
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToGroup;
}
message.send(sendFunc(this.get('id'), this.get('expireTimer'), message.get('sent_at')));
},
isSearchable: function() {

View file

@ -80,7 +80,9 @@ Message.prototype = {
return this.dataMessage;
}
var proto = new textsecure.protobuf.DataMessage();
proto.body = this.body;
if (this.body) {
proto.body = this.body;
}
proto.attachments = this.attachmentPointers;
if (this.flags) {
proto.flags = this.flags;
@ -451,6 +453,39 @@ MessageSender.prototype = {
return this.sendGroupProto(numbers, proto);
}.bind(this));
});
},
sendExpirationTimerUpdateToGroup: function(groupId, expireTimer, timestamp) {
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,
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
group: {
id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER
}
});
}.bind(this));
},
sendExpirationTimerUpdateToNumber: function(number, expireTimer, timestamp) {
var proto = new textsecure.protobuf.DataMessage();
return this.sendMessage({
recipients : [number],
timestamp : timestamp,
needsSync : true,
expireTimer : expireTimer,
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE
});
}
};
@ -462,19 +497,21 @@ textsecure.MessageSender = function(url, ports, username, password, attachment_s
textsecure.replay.registerFunction(sender.retransmitMessage.bind(sender), textsecure.replay.Type.TRANSMIT_MESSAGE);
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
this.sendRequestGroupSyncMessage = sender.sendRequestGroupSyncMessage .bind(sender);
this.sendRequestContactSyncMessage = sender.sendRequestContactSyncMessage.bind(sender);
this.sendMessageToNumber = sender.sendMessageToNumber .bind(sender);
this.closeSession = sender.closeSession .bind(sender);
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.syncReadMessages = sender.syncReadMessages .bind(sender);
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.sendMessageToNumber = sender.sendMessageToNumber .bind(sender);
this.closeSession = sender.closeSession .bind(sender);
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.syncReadMessages = sender.syncReadMessages .bind(sender);
};
textsecure.MessageSender.prototype = {