Remove refreshGroup
1. This is nonstandard behavior, not supported by any other clients. It may help sometimes but will also cause bugs (see 2) 2. iOS doesn't handle group updates with missing fields. all fields must be populated, and libtextsecure doesn't have any knowledge of the group name or avatar, so these updates will clobber group state on iOS. // FREEBIE
This commit is contained in:
@@ -39736,46 +39736,6 @@ window.textsecure.messaging = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var refreshGroup = function(number, groupId, devicesForNumber) {
|
|
||||||
groupId = getString(groupId);
|
|
||||||
|
|
||||||
var doUpdate = false;
|
|
||||||
return Promise.all(devicesForNumber.map(function(device) {
|
|
||||||
return textsecure.protocol_wrapper.getRegistrationId(device.encodedNumber).then(function(registrationId) {
|
|
||||||
return textsecure.storage.groups.needUpdateByDeviceRegistrationId(
|
|
||||||
groupId, number, device.encodedNumber, registrationId
|
|
||||||
).then(function(needUpdate) {
|
|
||||||
if (needUpdate) doUpdate = true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})).then(function() {
|
|
||||||
if (!doUpdate) return;
|
|
||||||
|
|
||||||
return textsecure.storage.groups.getGroup(groupId).then(function(group) {
|
|
||||||
var numberIndex = group.numbers.indexOf(number);
|
|
||||||
if (numberIndex < 0) // This is potentially a multi-message rare racing-AJAX race
|
|
||||||
return Promise.reject("Tried to refresh group to non-member");
|
|
||||||
|
|
||||||
var proto = new textsecure.protobuf.DataMessage();
|
|
||||||
proto.group = new textsecure.protobuf.GroupContext();
|
|
||||||
|
|
||||||
proto.group.id = toArrayBuffer(group.id);
|
|
||||||
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
|
||||||
proto.group.members = group.numbers;
|
|
||||||
proto.group.name = group.name === undefined ? null : group.name;
|
|
||||||
|
|
||||||
if (group.avatar !== undefined) {
|
|
||||||
return makeAttachmentPointer(group.avatar).then(function(attachment) {
|
|
||||||
proto.group.avatar = attachment;
|
|
||||||
return sendMessageToDevices(Date.now(), number, devicesForNumber, proto);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return sendMessageToDevices(Date.now(), number, devicesForNumber, proto);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var tryMessageAgain = function(number, encodedMessage, timestamp) {
|
var tryMessageAgain = function(number, encodedMessage, timestamp) {
|
||||||
var proto = textsecure.protobuf.DataMessage.decode(encodedMessage);
|
var proto = textsecure.protobuf.DataMessage.decode(encodedMessage);
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
@@ -39853,14 +39813,9 @@ window.textsecure.messaging = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var doSendMessage = function(number, devicesForNumber, recurse) {
|
var doSendMessage = function(number, devicesForNumber, recurse) {
|
||||||
var groupUpdate = Promise.resolve(true);
|
return sendMessageToDevices(timestamp, number, devicesForNumber, message).then(function(result) {
|
||||||
if (message.group && message.group.id && message.group.type != textsecure.protobuf.GroupContext.Type.QUIT)
|
successfulNumbers[successfulNumbers.length] = number;
|
||||||
groupUpdate = refreshGroup(number, message.group.id, devicesForNumber);
|
numberCompleted();
|
||||||
return groupUpdate.then(function() {
|
|
||||||
return sendMessageToDevices(timestamp, number, devicesForNumber, message).then(function(result) {
|
|
||||||
successfulNumbers[successfulNumbers.length] = number;
|
|
||||||
numberCompleted();
|
|
||||||
});
|
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
if (error instanceof Error && error.name == "HTTPError" && (error.code == 410 || error.code == 409)) {
|
if (error instanceof Error && error.name == "HTTPError" && (error.code == 410 || error.code == 409)) {
|
||||||
if (!recurse)
|
if (!recurse)
|
||||||
|
@@ -55,46 +55,6 @@ window.textsecure.messaging = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var refreshGroup = function(number, groupId, devicesForNumber) {
|
|
||||||
groupId = getString(groupId);
|
|
||||||
|
|
||||||
var doUpdate = false;
|
|
||||||
return Promise.all(devicesForNumber.map(function(device) {
|
|
||||||
return textsecure.protocol_wrapper.getRegistrationId(device.encodedNumber).then(function(registrationId) {
|
|
||||||
return textsecure.storage.groups.needUpdateByDeviceRegistrationId(
|
|
||||||
groupId, number, device.encodedNumber, registrationId
|
|
||||||
).then(function(needUpdate) {
|
|
||||||
if (needUpdate) doUpdate = true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})).then(function() {
|
|
||||||
if (!doUpdate) return;
|
|
||||||
|
|
||||||
return textsecure.storage.groups.getGroup(groupId).then(function(group) {
|
|
||||||
var numberIndex = group.numbers.indexOf(number);
|
|
||||||
if (numberIndex < 0) // This is potentially a multi-message rare racing-AJAX race
|
|
||||||
return Promise.reject("Tried to refresh group to non-member");
|
|
||||||
|
|
||||||
var proto = new textsecure.protobuf.DataMessage();
|
|
||||||
proto.group = new textsecure.protobuf.GroupContext();
|
|
||||||
|
|
||||||
proto.group.id = toArrayBuffer(group.id);
|
|
||||||
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
|
||||||
proto.group.members = group.numbers;
|
|
||||||
proto.group.name = group.name === undefined ? null : group.name;
|
|
||||||
|
|
||||||
if (group.avatar !== undefined) {
|
|
||||||
return makeAttachmentPointer(group.avatar).then(function(attachment) {
|
|
||||||
proto.group.avatar = attachment;
|
|
||||||
return sendMessageToDevices(Date.now(), number, devicesForNumber, proto);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return sendMessageToDevices(Date.now(), number, devicesForNumber, proto);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var tryMessageAgain = function(number, encodedMessage, timestamp) {
|
var tryMessageAgain = function(number, encodedMessage, timestamp) {
|
||||||
var proto = textsecure.protobuf.DataMessage.decode(encodedMessage);
|
var proto = textsecure.protobuf.DataMessage.decode(encodedMessage);
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
@@ -172,14 +132,9 @@ window.textsecure.messaging = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var doSendMessage = function(number, devicesForNumber, recurse) {
|
var doSendMessage = function(number, devicesForNumber, recurse) {
|
||||||
var groupUpdate = Promise.resolve(true);
|
return sendMessageToDevices(timestamp, number, devicesForNumber, message).then(function(result) {
|
||||||
if (message.group && message.group.id && message.group.type != textsecure.protobuf.GroupContext.Type.QUIT)
|
successfulNumbers[successfulNumbers.length] = number;
|
||||||
groupUpdate = refreshGroup(number, message.group.id, devicesForNumber);
|
numberCompleted();
|
||||||
return groupUpdate.then(function() {
|
|
||||||
return sendMessageToDevices(timestamp, number, devicesForNumber, message).then(function(result) {
|
|
||||||
successfulNumbers[successfulNumbers.length] = number;
|
|
||||||
numberCompleted();
|
|
||||||
});
|
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
if (error instanceof Error && error.name == "HTTPError" && (error.code == 410 || error.code == 409)) {
|
if (error instanceof Error && error.name == "HTTPError" && (error.code == 410 || error.code == 409)) {
|
||||||
if (!recurse)
|
if (!recurse)
|
||||||
|
Reference in New Issue
Block a user