Let group messages use new Message class
// FREEBIE
This commit is contained in:
parent
3bffdd96f5
commit
910e37649a
2 changed files with 48 additions and 28 deletions
|
@ -37445,7 +37445,9 @@ Message.prototype = {
|
||||||
proto.flags = this.flags;
|
proto.flags = this.flags;
|
||||||
}
|
}
|
||||||
if (this.group) {
|
if (this.group) {
|
||||||
proto.group = this.group;
|
proto.group = new textsecure.protobuf.GroupContext();
|
||||||
|
proto.group.id = toArrayBuffer(this.group.id);
|
||||||
|
proto.group.type = this.group.type
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataMessage = proto;
|
this.dataMessage = proto;
|
||||||
|
@ -37643,20 +37645,28 @@ MessageSender.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMessageToGroup: function(groupId, messageText, attachments, timestamp) {
|
sendMessageToGroup: function(groupId, messageText, attachments, timestamp) {
|
||||||
var proto = new textsecure.protobuf.DataMessage();
|
|
||||||
proto.body = messageText;
|
|
||||||
proto.group = new textsecure.protobuf.GroupContext();
|
|
||||||
proto.group.id = toArrayBuffer(groupId);
|
|
||||||
proto.group.type = textsecure.protobuf.GroupContext.Type.DELIVER;
|
|
||||||
|
|
||||||
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
||||||
if (numbers === undefined)
|
if (numbers === undefined)
|
||||||
return Promise.reject(new Error("Unknown Group"));
|
return Promise.reject(new Error("Unknown Group"));
|
||||||
|
|
||||||
return Promise.all(attachments.map(this.makeAttachmentPointer.bind(this))).then(function(attachmentsArray) {
|
var me = textsecure.storage.user.getNumber();
|
||||||
proto.attachments = attachmentsArray;
|
numbers = numbers.filter(function(number) { return number != me; });
|
||||||
return this.sendGroupProto(numbers, proto, timestamp);
|
if (numbers.length === 0) {
|
||||||
}.bind(this));
|
return Promise.reject(new Error('No other members in the group'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = new Message({
|
||||||
|
recipients : numbers,
|
||||||
|
body : messageText,
|
||||||
|
timestamp : timestamp,
|
||||||
|
attachments : attachments,
|
||||||
|
needsSync : true,
|
||||||
|
group: {
|
||||||
|
id: groupId,
|
||||||
|
type: textsecure.protobuf.GroupContext.Type.DELIVER
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this.sendMessage(message);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,9 @@ Message.prototype = {
|
||||||
proto.flags = this.flags;
|
proto.flags = this.flags;
|
||||||
}
|
}
|
||||||
if (this.group) {
|
if (this.group) {
|
||||||
proto.group = this.group;
|
proto.group = new textsecure.protobuf.GroupContext();
|
||||||
|
proto.group.id = toArrayBuffer(this.group.id);
|
||||||
|
proto.group.type = this.group.type
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataMessage = proto;
|
this.dataMessage = proto;
|
||||||
|
@ -222,20 +224,28 @@ MessageSender.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMessageToGroup: function(groupId, messageText, attachments, timestamp) {
|
sendMessageToGroup: function(groupId, messageText, attachments, timestamp) {
|
||||||
var proto = new textsecure.protobuf.DataMessage();
|
|
||||||
proto.body = messageText;
|
|
||||||
proto.group = new textsecure.protobuf.GroupContext();
|
|
||||||
proto.group.id = toArrayBuffer(groupId);
|
|
||||||
proto.group.type = textsecure.protobuf.GroupContext.Type.DELIVER;
|
|
||||||
|
|
||||||
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
||||||
if (numbers === undefined)
|
if (numbers === undefined)
|
||||||
return Promise.reject(new Error("Unknown Group"));
|
return Promise.reject(new Error("Unknown Group"));
|
||||||
|
|
||||||
return Promise.all(attachments.map(this.makeAttachmentPointer.bind(this))).then(function(attachmentsArray) {
|
var me = textsecure.storage.user.getNumber();
|
||||||
proto.attachments = attachmentsArray;
|
numbers = numbers.filter(function(number) { return number != me; });
|
||||||
return this.sendGroupProto(numbers, proto, timestamp);
|
if (numbers.length === 0) {
|
||||||
}.bind(this));
|
return Promise.reject(new Error('No other members in the group'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = new Message({
|
||||||
|
recipients : numbers,
|
||||||
|
body : messageText,
|
||||||
|
timestamp : timestamp,
|
||||||
|
attachments : attachments,
|
||||||
|
needsSync : true,
|
||||||
|
group: {
|
||||||
|
id: groupId,
|
||||||
|
type: textsecure.protobuf.GroupContext.Type.DELIVER
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this.sendMessage(message);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue