Use textsecure.messaging to create groups

Not textsecure.storage. Sigh. Also accomodate the fact that
the group id is not returned directly, but rather at the end
of a promise chain.
This commit is contained in:
lilia 2014-10-16 14:14:00 -07:00
parent fa4c385598
commit 4f21bbd21f
2 changed files with 14 additions and 9 deletions

View file

@ -36,7 +36,7 @@ var Whisper = Whisper || {};
var promise = textsecure.messaging.sendMessageToNumber(this.get('id'), message, []);
}
else {
var promise = textsecure.messaging.sendMessageToGroup(this.get('id'), message, []);
var promise = textsecure.messaging.sendMessageToGroup(this.get('groupId'), message, []);
}
promise.then(
function(result) {
@ -68,15 +68,18 @@ var Whisper = Whisper || {};
},
createGroup: function(recipients, name) {
var group = textsecure.storage.groups.createNewGroup(recipients);
var attributes = {};
attributes = {
id : group.id,
name : name,
numbers : group.numbers,
numbers : recipients,
type : 'group',
};
return this.findOrCreate(attributes);
var thread = this.findOrCreate(attributes);
return textsecure.messaging.createGroup(recipients, name).then(function(groupId) {
thread.set('groupId', groupId);
thread.save();
return thread;
});
},
findOrCreateForRecipient: function(recipient) {

View file

@ -36,10 +36,12 @@ var Whisper = Whisper || {};
e.preventDefault();
var numbers = this.$el.find('input.numbers').val().split(',');
var name = this.$el.find('input.name').val();
var thread = Whisper.Threads.createGroup(numbers, name);
thread.sendMessage(this.$el.find('input.send-message').val());
this.remove();
thread.trigger('render');
var view = this;
Whisper.Threads.createGroup(numbers, name).then(function(thread){
thread.sendMessage(view.$el.find('input.send-message').val());
view.remove();
thread.trigger('render');
});
},
render: function() {