Track groups I've left
// FREEBIE
This commit is contained in:
parent
83b25c0bfa
commit
010297f4c5
5 changed files with 54 additions and 40 deletions
|
@ -131,13 +131,17 @@
|
||||||
|
|
||||||
function onGroupReceived(ev) {
|
function onGroupReceived(ev) {
|
||||||
var groupDetails = ev.groupDetails;
|
var groupDetails = ev.groupDetails;
|
||||||
ConversationController.create({
|
var conversation = ConversationController.create({
|
||||||
id: groupDetails.id,
|
id: groupDetails.id,
|
||||||
name: groupDetails.name,
|
name: groupDetails.name,
|
||||||
members: groupDetails.members,
|
members: groupDetails.members,
|
||||||
avatar: groupDetails.avatar,
|
avatar: groupDetails.avatar,
|
||||||
type: 'group',
|
type: 'group',
|
||||||
}).save();
|
});
|
||||||
|
if (!groupDetails.active) {
|
||||||
|
conversation.set({left: true});
|
||||||
|
}
|
||||||
|
conversation.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMessageReceived(ev) {
|
function onMessageReceived(ev) {
|
||||||
|
|
|
@ -37077,25 +37077,29 @@ MessageReceiver.prototype.extend({
|
||||||
while (groupDetails !== undefined) {
|
while (groupDetails !== undefined) {
|
||||||
var promise = (function(groupDetails) {
|
var promise = (function(groupDetails) {
|
||||||
groupDetails.id = getString(groupDetails.id);
|
groupDetails.id = getString(groupDetails.id);
|
||||||
return textsecure.storage.groups.getGroup(groupDetails.id).
|
if (groupDetails.active) {
|
||||||
then(function(existingGroup) {
|
return textsecure.storage.groups.getGroup(groupDetails.id).
|
||||||
if (existingGroup === undefined) {
|
then(function(existingGroup) {
|
||||||
return textsecure.storage.groups.createNewGroup(
|
if (existingGroup === undefined) {
|
||||||
groupDetails.members, groupDetails.id
|
return textsecure.storage.groups.createNewGroup(
|
||||||
);
|
groupDetails.members, groupDetails.id
|
||||||
} else {
|
);
|
||||||
return textsecure.storage.groups.updateNumbers(
|
} else {
|
||||||
groupDetails.id, groupDetails.members
|
return textsecure.storage.groups.updateNumbers(
|
||||||
);
|
groupDetails.id, groupDetails.members
|
||||||
}
|
);
|
||||||
}).then(function() {
|
}
|
||||||
var ev = new Event('group');
|
}).then(function() { return groupDetails });
|
||||||
ev.groupDetails = groupDetails;
|
} else {
|
||||||
eventTarget.dispatchEvent(ev);
|
return Promise.resolve(groupDetails);
|
||||||
}).catch(function(e) {
|
}
|
||||||
console.log('error processing group', groupDetails.id, e);
|
})(groupDetails).then(function(groupDetails) {
|
||||||
});
|
var ev = new Event('group');
|
||||||
})(groupDetails);
|
ev.groupDetails = groupDetails;
|
||||||
|
eventTarget.dispatchEvent(ev);
|
||||||
|
}).catch(function(e) {
|
||||||
|
console.log('error processing group', e);
|
||||||
|
});
|
||||||
groupDetails = groupBuffer.next();
|
groupDetails = groupBuffer.next();
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,7 @@
|
||||||
leaveGroup: function() {
|
leaveGroup: function() {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
if (this.get('type') === 'group') {
|
if (this.get('type') === 'group') {
|
||||||
|
this.save({left: true});
|
||||||
var message = this.messageCollection.create({
|
var message = this.messageCollection.create({
|
||||||
group_update: { left: 'You' },
|
group_update: { left: 'You' },
|
||||||
conversationId : this.id,
|
conversationId : this.id,
|
||||||
|
|
|
@ -241,25 +241,29 @@ MessageReceiver.prototype.extend({
|
||||||
while (groupDetails !== undefined) {
|
while (groupDetails !== undefined) {
|
||||||
var promise = (function(groupDetails) {
|
var promise = (function(groupDetails) {
|
||||||
groupDetails.id = getString(groupDetails.id);
|
groupDetails.id = getString(groupDetails.id);
|
||||||
return textsecure.storage.groups.getGroup(groupDetails.id).
|
if (groupDetails.active) {
|
||||||
then(function(existingGroup) {
|
return textsecure.storage.groups.getGroup(groupDetails.id).
|
||||||
if (existingGroup === undefined) {
|
then(function(existingGroup) {
|
||||||
return textsecure.storage.groups.createNewGroup(
|
if (existingGroup === undefined) {
|
||||||
groupDetails.members, groupDetails.id
|
return textsecure.storage.groups.createNewGroup(
|
||||||
);
|
groupDetails.members, groupDetails.id
|
||||||
} else {
|
);
|
||||||
return textsecure.storage.groups.updateNumbers(
|
} else {
|
||||||
groupDetails.id, groupDetails.members
|
return textsecure.storage.groups.updateNumbers(
|
||||||
);
|
groupDetails.id, groupDetails.members
|
||||||
}
|
);
|
||||||
}).then(function() {
|
}
|
||||||
var ev = new Event('group');
|
}).then(function() { return groupDetails });
|
||||||
ev.groupDetails = groupDetails;
|
} else {
|
||||||
eventTarget.dispatchEvent(ev);
|
return Promise.resolve(groupDetails);
|
||||||
}).catch(function(e) {
|
}
|
||||||
console.log('error processing group', groupDetails.id, e);
|
})(groupDetails).then(function(groupDetails) {
|
||||||
});
|
var ev = new Event('group');
|
||||||
})(groupDetails);
|
ev.groupDetails = groupDetails;
|
||||||
|
eventTarget.dispatchEvent(ev);
|
||||||
|
}).catch(function(e) {
|
||||||
|
console.log('error processing group', e);
|
||||||
|
});
|
||||||
groupDetails = groupBuffer.next();
|
groupDetails = groupBuffer.next();
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,7 @@ message GroupDetails {
|
||||||
optional string name = 2;
|
optional string name = 2;
|
||||||
repeated string members = 3;
|
repeated string members = 3;
|
||||||
optional Avatar avatar = 4;
|
optional Avatar avatar = 4;
|
||||||
|
optional bool active = 5 [default = true];
|
||||||
}
|
}
|
||||||
|
|
||||||
message ContactDetails {
|
message ContactDetails {
|
||||||
|
|
Loading…
Reference in a new issue