PushMessageContent is now DataMessage

This commit is contained in:
lilia 2015-06-16 17:46:53 -07:00
parent 316838cfe9
commit 18433419c9
2 changed files with 21 additions and 21 deletions

View file

@ -78,7 +78,7 @@
function onMessageReceived(ev) { function onMessageReceived(ev) {
var data = ev.data; var data = ev.data;
var message = initIncomingMessage(data.source, data.timestamp); var message = initIncomingMessage(data.source, data.timestamp);
message.handlePushMessageContent(data.message); message.handleDataMessage(data.message);
} }
function onSentMessage(ev) { function onSentMessage(ev) {
@ -93,7 +93,7 @@
type : 'outgoing' type : 'outgoing'
}); });
message.handlePushMessageContent(data.message); message.handleDataMessage(data.message);
} }
function initIncomingMessage(source, timestamp) { function initIncomingMessage(source, timestamp) {

View file

@ -102,8 +102,8 @@
if (error) { if (error) {
var promise = new textsecure.ReplayableError(error).replay(); var promise = new textsecure.ReplayableError(error).replay();
if (this.isIncoming()) { if (this.isIncoming()) {
promise.then(function(pushMessageContent) { promise.then(function(dataMessage) {
this.handlePushMessageContent(pushMessageContent); this.handleDataMessage(dataMessage);
this.save('errors', []); this.save('errors', []);
}.bind(this)).catch(function(e) { }.bind(this)).catch(function(e) {
//this.save('errors', [_.pick(e, ['name', 'message'])]); //this.save('errors', [_.pick(e, ['name', 'message'])]);
@ -122,7 +122,7 @@
} }
} }
}, },
handlePushMessageContent: function(pushMessageContent) { handleDataMessage: function(dataMessage) {
// This function can be called from the background script on an // This function can be called from the background script on an
// incoming message or from the frontend after the user accepts an // incoming message or from the frontend after the user accepts an
// identity key change. // identity key change.
@ -131,34 +131,34 @@
var type = source === textsecure.storage.user.getNumber() ? 'outgoing' : 'incoming'; var type = source === textsecure.storage.user.getNumber() ? 'outgoing' : 'incoming';
var timestamp = message.get('sent_at'); var timestamp = message.get('sent_at');
var conversationId = message.get('conversationId'); var conversationId = message.get('conversationId');
if (pushMessageContent.group) { if (dataMessage.group) {
conversationId = pushMessageContent.group.id; conversationId = dataMessage.group.id;
} }
var conversation = new Whisper.Conversation({id: conversationId}); var conversation = new Whisper.Conversation({id: conversationId});
conversation.fetch().always(function() { conversation.fetch().always(function() {
var now = new Date().getTime(); var now = new Date().getTime();
var attributes = { type: 'private' }; var attributes = { type: 'private' };
if (pushMessageContent.group) { if (dataMessage.group) {
var group_update = {}; var group_update = {};
attributes = { attributes = {
type: 'group', type: 'group',
groupId: pushMessageContent.group.id, groupId: dataMessage.group.id,
}; };
if (pushMessageContent.group.type === textsecure.protobuf.GroupContext.Type.UPDATE) { if (dataMessage.group.type === textsecure.protobuf.GroupContext.Type.UPDATE) {
attributes = { attributes = {
type : 'group', type : 'group',
groupId : pushMessageContent.group.id, groupId : dataMessage.group.id,
name : pushMessageContent.group.name, name : dataMessage.group.name,
avatar : pushMessageContent.group.avatar, avatar : dataMessage.group.avatar,
members : pushMessageContent.group.members, members : dataMessage.group.members,
}; };
group_update = conversation.changedAttributes(_.pick(pushMessageContent.group, 'name', 'avatar')); group_update = conversation.changedAttributes(_.pick(dataMessage.group, 'name', 'avatar'));
var difference = _.difference(pushMessageContent.group.members, conversation.get('members')); var difference = _.difference(dataMessage.group.members, conversation.get('members'));
if (difference.length > 0) { if (difference.length > 0) {
group_update.joined = difference; group_update.joined = difference;
} }
} }
else if (pushMessageContent.group.type === textsecure.protobuf.GroupContext.Type.QUIT) { else if (dataMessage.group.type === textsecure.protobuf.GroupContext.Type.QUIT) {
group_update = { left: source }; group_update = { left: source };
attributes.members = _.without(conversation.get('members'), source); attributes.members = _.without(conversation.get('members'), source);
} }
@ -169,7 +169,7 @@
} }
if (type === 'outgoing') { if (type === 'outgoing') {
// lazy hack - check for receipts that arrived early. // lazy hack - check for receipts that arrived early.
if (pushMessageContent.group && pushMessageContent.group.id) { // group sync if (dataMessage.group && dataMessage.group.id) { // group sync
var members = conversation.get('members') || []; var members = conversation.get('members') || [];
var receipts = window.receipts.where({ timestamp: timestamp }); var receipts = window.receipts.where({ timestamp: timestamp });
for (var i in receipts) { for (var i in receipts) {
@ -200,13 +200,13 @@
conversation.set(attributes); conversation.set(attributes);
message.set({ message.set({
body : pushMessageContent.body, body : dataMessage.body,
conversationId : conversation.id, conversationId : conversation.id,
attachments : pushMessageContent.attachments, attachments : dataMessage.attachments,
decrypted_at : now, decrypted_at : now,
type : type, type : type,
sent_at : timestamp, sent_at : timestamp,
flags : pushMessageContent.flags, flags : dataMessage.flags,
errors : [] errors : []
}); });