Rename some things to be a little more semantic

The 'sender' field actually holds the recipient for outgoing
messages. Rename that field to 'person', indicating the 2nd
party generically.

Also decouples the thread name from thread recipients at the
view layer, in preparation for group support.
This commit is contained in:
lilia 2014-05-18 13:36:56 -07:00
parent 0362ecf709
commit 2601c3cc3a
3 changed files with 12 additions and 13 deletions

View File

@ -11,7 +11,7 @@ var Whisper = Whisper || {};
addIncomingMessage: function(decrypted) {
Whisper.Messages.add({
sender: decrypted.pushMessage.source,
person: decrypted.pushMessage.source,
group: decrypted.message.group,
body: decrypted.message.body,
type: 'incoming',
@ -19,9 +19,9 @@ var Whisper = Whisper || {};
}).save();
},
addOutgoingMessage: function(messageProto, sender) {
addOutgoingMessage: function(messageProto, recipients) {
Whisper.Messages.add({
sender: sender,
person: recipients[0], // TODO: groups
body: messageProto.body,
type: 'outgoing',
timestamp: new Date().getTime()

View File

@ -53,7 +53,7 @@ textsecure.registerOnLoadFunction(function() {
}
var messageProto = new PushMessageContentProtobuf();
messageProto.body = $("#popup_send_text").val();
Whisper.Messages.addOutgoingMessage(messageProto, numbers[0]);
Whisper.Messages.addOutgoingMessage(messageProto, numbers);
textsecure.sendMessage(numbers, messageProto,
//TODO: Handle result
function(thing) {console.log(thing);});

View File

@ -45,15 +45,14 @@ var Whisper = Whisper || {};
initialize: function(options) {
this.$el.addClass('closed');
this.$header = $('<div class="header">').
append($('<span>').text(options.sender)).appendTo(this.$el);
append($('<span>').text(options.name)).appendTo(this.$el);
this.$header.prepend($('<div class="avatar">'));
this.$collapsable = $('<div class="collapsable">').hide();
this.$messages = $('<ul>').addClass('messages').appendTo(this.$collapsable);
this.$button = $('<button class="btn">').attr('id', 'button' + this.id).
append($('<span>').text('Send'));
this.$input = $('<input type="text" id="text' + options.threadId + '">').
attr('autocomplete','off');
this.$input = $('<input type="text">').attr('autocomplete','off');
this.$form = $("<form class='container'>").append(this.$input, this.$button);
this.$form.appendTo(this.$collapsable);
this.$collapsable.appendTo(this.$el);
@ -82,14 +81,12 @@ var Whisper = Whisper || {};
$button.attr("disabled", "disabled");
$button.find('span').text("Sending");
var sendDestinations = [options.sender];
var messageProto = new PushMessageContentProtobuf();
messageProto.body = $input.val();
Whisper.Messages.addOutgoingMessage(messageProto, options.sender);
Whisper.Messages.addOutgoingMessage(messageProto, options.recipients);
textsecure.sendMessage(sendDestinations, messageProto, function(result) {
textsecure.sendMessage(options.recipients, messageProto, function(result) {
console.log(result);
$button.removeAttr("disabled");
$button.find('span').text("Send");
@ -127,9 +124,11 @@ var Whisper = Whisper || {};
addMessage: function (message) {
// todo: find the right existing view
var threadId = message.get('sender'); // TODO: groups
var threadId = message.get('person'); // TODO: groups
if (this.views[threadId] === undefined) {
this.views[threadId] = new ConversationView({threadId: threadId, sender: message.get('sender')});
this.views[threadId] = new ConversationView({
name: threadId, recipients: [threadId]
});
this.$el.append(this.views[threadId].render().el);
}