Simplify pushMessageContent handler slightly

New private conversations have their type set in onMessageReceived. New
group conversations should be handled the same way as normal group
updates. It was pointed out we should never have to handle a group
message without a preceding group update, as those would be rejected by
textsecure.processDecrypted. An exception would be if you delete the
group from indexedDB but not localStorage, but that's not a mode we
should be supporting.

Also in this change I switched to instantiating a new conversation
object on every call to handlePushMessageContent. Originally, I thought
to use the local conversation list as a cache, but it's a bit simpler to
re-read from the database every time for now. Later on we should revisit
and optimize for fewer read/writes per incoming message.
This commit is contained in:
lilia 2014-12-24 15:03:03 -08:00
parent 0ea176dfa0
commit fca67d7b0e

View file

@ -127,27 +127,13 @@
return textsecure.processDecrypted(pushMessageContent, source).then(function(pushMessageContent) {
var now = new Date().getTime();
var conversationId = pushMessageContent.group ? pushMessageContent.group.id : source;
var conversation = conversations.add({id: conversationId}, {merge: true});
var conversation = new Whisper.Conversation({id: conversationId});
var attributes = {};
conversation.fetch().fail(function() {
// this is a new conversation
if (pushMessageContent.group) {
attributes = {
type : 'group',
groupId : pushMessageContent.group.id,
name : pushMessageContent.group.name || '',
avatar : pushMessageContent.group.avatar,
members : pushMessageContent.group.members,
};
} else {
attributes = {
type : 'private'
};
}
}).always(function() {
conversation.fetch().always(function() {
if (pushMessageContent.group &&
pushMessageContent.group.type === textsecure.protobuf.PushMessageContent.GroupContext.Type.UPDATE) {
attributes = {
type : 'group',
groupId : pushMessageContent.group.id,
name : pushMessageContent.group.name,
avatar : pushMessageContent.group.avatar,