findOrCreateById instead of private-specific method

Anyway, findOrCreateById with no type didn't succeed, because the
conversation didn't validate.

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-07-25 10:33:28 -07:00
parent ef3431af1b
commit 3e8b34f3d0
3 changed files with 11 additions and 22 deletions

View file

@ -158,7 +158,7 @@
return; return;
} }
return ConversationController.findOrCreatePrivateById(id).then(function(conversation) { return ConversationController.findOrCreateById(id, 'private').then(function(conversation) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
conversation.save({ conversation.save({
name: details.name, name: details.name,
@ -174,7 +174,7 @@
var details = ev.groupDetails; var details = ev.groupDetails;
var id = details.id; var id = details.id;
return ConversationController.findOrCreateById(id).then(function(conversation) { return ConversationController.findOrCreateById(id, 'group').then(function(conversation) {
var updates = { var updates = {
name: details.name, name: details.name,
members: details.members, members: details.members,
@ -311,8 +311,10 @@
} }
var envelope = ev.proto; var envelope = ev.proto;
var message = initIncomingMessage(envelope.source, envelope.timestamp.toNumber()); var message = initIncomingMessage(envelope.source, envelope.timestamp.toNumber());
message.saveErrors(e).then(function() { message.saveErrors(e).then(function() {
ConversationController.findOrCreatePrivateById(message.get('conversationId')).then(function(conversation) { var id = message.get('conversationId');
ConversationController.findOrCreateById(id, 'private').then(function(conversation) {
conversation.set({ conversation.set({
active_at: Date.now(), active_at: Date.now(),
unreadCount: conversation.get('unreadCount') + 1 unreadCount: conversation.get('unreadCount') + 1
@ -379,7 +381,7 @@
console.log('got verified sync for', number, state, console.log('got verified sync for', number, state,
ev.viaContactSync ? 'via contact sync' : ''); ev.viaContactSync ? 'via contact sync' : '');
return ConversationController.findOrCreatePrivateById(number).then(function(contact) { return ConversationController.findOrCreateById(number, 'private').then(function(contact) {
var options = { var options = {
viaSyncMessage: true, viaSyncMessage: true,
viaContactSync: ev.viaContactSync, viaContactSync: ev.viaContactSync,

View file

@ -86,24 +86,10 @@
var conversation = conversations.add(attrs, {merge: true}); var conversation = conversations.add(attrs, {merge: true});
return conversation; return conversation;
}, },
findOrCreatePrivateById: function(id) { findOrCreateById: function(id, type) {
var conversation = conversations.add({ var conversation = conversations.add({
id: id, id: id,
type: 'private' type: type
});
return new Promise(function(resolve, reject) {
conversation.fetch().then(function() {
resolve(conversation);
}, function() {
conversation.save().then(function() {
resolve(conversation);
}, reject);
});
});
},
findOrCreateById: function(id) {
var conversation = conversations.add({
id: id
}); });
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
conversation.fetch().then(function() { conversation.fetch().then(function() {

View file

@ -97,8 +97,9 @@
createConversation: function() { createConversation: function() {
var conversation = this.new_contact_view.model; var conversation = this.new_contact_view.model;
if (this.new_contact_view.model.isValid()) { if (this.new_contact_view.model.isValid()) {
ConversationController.findOrCreatePrivateById( ConversationController.findOrCreateById(
this.new_contact_view.model.id this.new_contact_view.model.id,
'private'
).then(function(conversation) { ).then(function(conversation) {
this.trigger('open', conversation); this.trigger('open', conversation);
this.initNewContact(); this.initNewContact();