Thread model and UI improvements

Adds thread model/collection for managing conversation-level state, such
as unreadCounts, group membership, thread order, etc... plus various UI
improvements enabled by thread model, including an improved compose
flow, and thread-destroy button.

Adds Whisper.notify for presenting messages to the user in an orderly
fashion. Currently using a growl-style fade in/out effect.

Also some housekeeping:
Cut up views into separate files.
Partial fix for formatTimestamp.
Tweaked buttons and other styles.
This commit is contained in:
lilia 2014-05-16 21:48:46 -07:00
parent 2d12a33ead
commit 83508abab8
13 changed files with 460 additions and 211 deletions

View file

@ -4,8 +4,18 @@ var Whisper = Whisper || {};
'use strict';
var Message = Backbone.Model.extend({
validate: function(attributes, options) {
var required = ['body', 'timestamp', 'threadId'];
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
if (missing.length) { return "Message must have " + missing; }
},
toProto: function() {
return new textsecure.protos.PushMessageContentProtobuf({body: this.get('body')});
},
thread: function() {
return Whisper.Threads.get(this.get('threadId'));
}
});
@ -20,28 +30,36 @@ var Whisper = Whisper || {};
for (var i = 0; i < decrypted.message.attachments.length; i++)
attachments[i] = "data:" + decrypted.message.attachments[i].contentType + ";base64," + btoa(getString(decrypted.message.attachments[i].decrypted));
var thread = Whisper.Threads.findOrCreateForIncomingMessage(decrypted);
var m = Whisper.Messages.add({
person: decrypted.pushMessage.source,
group: decrypted.message.group,
threadId: thread.id,
body: decrypted.message.body,
attachments: attachments,
type: 'incoming',
timestamp: decrypted.message.timestamp
});
m.save();
if (decrypted.message.timestamp > thread.get('timestamp')) {
thread.set('timestamp', decrypted.message.timestamp);
thread.set('unreadCount', thread.get('unreadCount') + 1);
thread.save();
}
thread.trigger('message', m);
return m;
},
addOutgoingMessage: function(message, recipients) {
addOutgoingMessage: function(message, thread) {
var m = Whisper.Messages.add({
person: recipients[0], // TODO: groups
threadId: thread.id,
body: message,
type: 'outgoing',
timestamp: new Date().getTime()
});
m.save();
thread.trigger('message', m);
return m;
}
}))();
})()