Merge pull request #1223 from Bilb/various-closed-group-fixes

* fix display name and avatar to be shown when message is coming from a secondary device
* fix show of expiretimer in the group conversation when it is for it.
* fix a bug creating empty conversation when sync closed group message is received on secondary device
* trigger an expiretimer update message to all members when updating a group.
* trigger an expiretimer update message when sending back group details (after a requestGroupInfo)
pull/1227/head
Audric Ackermann 5 years ago committed by GitHub
commit d5cfcf9edc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -626,24 +626,24 @@
window.doUpdateGroup = async (groupId, groupName, members, avatar) => {
const ourKey = textsecure.storage.user.getNumber();
const convo = await ConversationController.getOrCreateAndWait(
groupId,
'group'
);
const ev = {
groupDetails: {
id: groupId,
name: groupName,
members,
active: true,
expireTimer: 0,
avatar: '',
expireTimer: convo.get('expireTimer'),
avatar,
is_medium_group: false,
},
confirm: () => {},
};
const convo = await ConversationController.getOrCreateAndWait(
groupId,
'group'
);
const recipients = _.union(convo.get('members'), members);
await window.NewReceiver.onGroupReceived(ev);

@ -1901,9 +1901,20 @@
);
await this.sendClosedGroupMessageWithSync(groupUpdateMessage, recipients);
const expireUpdate = {
timestamp: Date.now(),
expireTimer: this.get('expireTimer'),
groupId: this.get('id'),
};
const expirationTimerMessage = new libsession.Messages.Outgoing.ExpirationTimerUpdateMessage(
expireUpdate
);
await libsession.getMessageQueue().sendToGroup(expirationTimerMessage);
},
sendGroupInfo(recipient) {
async sendGroupInfo(recipient) {
// Only send group info if we're a closed group and we haven't left
if (this.isClosedGroup() && !this.get('left')) {
const updateParams = {
@ -1922,10 +1933,28 @@
window.console.warn('sendGroupInfo invalid pubkey:', recipient);
return;
}
libsession
.getMessageQueue()
.send(recipientPubKey, groupUpdateMessage)
.catch(log.error);
try {
await libsession
.getMessageQueue()
.send(recipientPubKey, groupUpdateMessage);
const expireUpdate = {
timestamp: Date.now(),
expireTimer: this.get('expireTimer'),
groupId: this.get('id'),
};
const expirationTimerMessage = new libsession.Messages.Outgoing.ExpirationTimerUpdateMessage(
expireUpdate
);
await libsession
.getMessageQueue()
.sendUsingMultiDevice(recipientPubKey, expirationTimerMessage);
} catch (e) {
log.error('Failed to send groupInfo:', e);
}
}
},

@ -1096,7 +1096,7 @@
attachments,
preview,
quote,
lokiProfile: this.getOurProfile(),
lokiProfile: this.conversation.getOurProfile(),
});
// Special-case the self-send case - we send only a sync message

@ -222,7 +222,7 @@ export class SessionGroupSettings extends React.Component<Props, any> {
const leaveGroupString = isPublic
? window.i18n('leaveOpenGroup')
: isKickedFromGroup
? window.i18n('youGotKickedFromThisGroup')
? window.i18n('youGotKickedFromGroup')
: window.i18n('leaveClosedGroup');
const disappearingMessagesOptions = timerOptions.map(option => {

@ -70,12 +70,20 @@ export async function updateProfile(
newProfile.avatar = null;
}
await conversation.setLokiProfile(newProfile);
if (conversation.isSecondaryDevice()) {
const primaryConversation = await conversation.getPrimaryConversation();
await primaryConversation.setLokiProfile(newProfile);
}
const allUserDevices = await MultiDeviceProtocol.getAllDevices(
conversation.id
);
const { ConversationController } = window;
await Promise.all(
allUserDevices.map(async device => {
const conv = await ConversationController.getOrCreateAndWait(
device.key,
'private'
);
await conv.setLokiProfile(newProfile);
})
);
}
function cleanAttachment(attachment: any) {
@ -298,15 +306,7 @@ export async function handleDataMessage(
}
const source = envelope.senderIdentity || senderPubKey;
const isOwnDevice = async (device: string) => {
const pubKey = new PubKey(device);
const allDevices = await MultiDeviceProtocol.getAllDevices(pubKey);
return allDevices.some(d => d.isEqual(pubKey));
};
const ownDevice = await isOwnDevice(source);
const ownDevice = await MultiDeviceProtocol.isOurDevice(source);
const ownMessage = conversation.isMediumGroup() && ownDevice;
@ -413,6 +413,7 @@ interface MessageCreationData {
isRss: boolean;
source: boolean;
serverId: string;
message: any;
// Needed for synced outgoing messages
unidentifiedStatus: any; // ???
@ -430,9 +431,13 @@ export function initIncomingMessage(data: MessageCreationData): MessageModel {
isRss,
source,
serverId,
message,
} = data;
const type = 'incoming';
const messageGroupId = message?.group?.id;
const groupId =
messageGroupId && messageGroupId.length > 0 ? messageGroupId : null;
const messageData: any = {
source,
@ -440,7 +445,7 @@ export function initIncomingMessage(data: MessageCreationData): MessageModel {
serverId, // + (not present below in `createSentMessage`)
sent_at: timestamp,
received_at: receivedAt || Date.now(),
conversationId: source,
conversationId: groupId ?? source,
unidentifiedDeliveryReceived, // +
type,
direction: 'incoming', // +
@ -617,10 +622,11 @@ export async function handleMessageEvent(event: MessageEvent): Promise<void> {
const primarySource = await MultiDeviceProtocol.getPrimaryDevice(source);
if (isGroupMessage) {
/* handle one part of the group logic here:
handle requesting info of a new group,
dropping an admin only update from a non admin, ...
*/
handle requesting info of a new group,
dropping an admin only update from a non admin, ...
*/
conversationId = message.group.id;
const shouldReturn = await preprocessGroupMessage(
source,
message.group,

@ -13,18 +13,15 @@ async function handleGroups(
group: any,
source: any
): Promise<any> {
const textsecure = window.textsecure;
const GROUP_TYPES = SignalService.GroupContext.Type;
// TODO: this should be primary device id!
const ourNumber = textsecure.storage.user.getNumber();
let groupUpdate = null;
// conversation attributes
const attributes: any = {
type: 'group',
groupId: group.id,
...conversation.attributes,
};
const oldMembers = conversation.get('members');
@ -54,15 +51,21 @@ async function handleGroups(
// Check if anyone got kicked:
const removedMembers = _.difference(oldMembers, attributes.members);
const isOurDeviceMap = await Promise.all(
removedMembers.map(async member =>
MultiDeviceProtocol.isOurDevice(member)
)
);
const ourDeviceWasRemoved = isOurDeviceMap.includes(true);
if (removedMembers.includes(ourNumber)) {
if (ourDeviceWasRemoved) {
groupUpdate.kicked = 'You';
attributes.isKickedFromGroup = true;
} else if (removedMembers.length) {
groupUpdate.kicked = removedMembers;
}
} else if (group.type === GROUP_TYPES.QUIT) {
if (source === ourNumber) {
if (await MultiDeviceProtocol.isOurDevice(source)) {
attributes.left = true;
groupUpdate = { left: 'You' };
} else {

@ -66,6 +66,8 @@ export abstract class ClosedGroupUpdateMessage extends ClosedGroupMessage {
groupContext.admins = this.admins;
}
groupContext.avatar = this.avatar;
return groupContext;
}
}

@ -8,7 +8,9 @@ import ByteBuffer from 'bytebuffer';
*/
export function convertToTS(object: any): any {
// No idea why js `ByteBuffer` and ts `ByteBuffer` differ ...
if (
if (object instanceof Uint8Array) {
return object;
} else if (
object &&
object.constructor &&
object.constructor.name === 'ByteBuffer'

Loading…
Cancel
Save