From 96cc74ab62ef8c8f8b10e3a7ffdc981b3e0d7ca8 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 18 Oct 2017 15:00:54 +0100 Subject: [PATCH] Attempt to relate a group to a room when adding it So as to remove another step on "The Route To Flair" (the steps taken for a user to get flair to appear on their SenderProfile in a room). --- src/GroupAddressPicker.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/GroupAddressPicker.js b/src/GroupAddressPicker.js index ca495de16d..b710524ce3 100644 --- a/src/GroupAddressPicker.js +++ b/src/GroupAddressPicker.js @@ -94,13 +94,30 @@ function _onGroupInviteFinished(groupId, addrs) { } function _onGroupAddRoomFinished(groupId, addrs) { - const groupStore = GroupStoreCache.getGroupStore(MatrixClientPeg.get(), groupId); + const matrixClient = MatrixClientPeg.get(); + const groupStore = GroupStoreCache.getGroupStore(matrixClient, groupId); const errorList = []; return Promise.all(addrs.map((addr) => { return groupStore .addRoomToGroup(addr.address) .catch(() => { errorList.push(addr.address); }) - .reflect(); + .then(() => { + const roomId = addr.address; + const room = matrixClient.getRoom(roomId); + // Can the user change related groups? + if (!room || !room.currentState.mayClientSendStateEvent("m.room.related_groups", matrixClient)) { + return; + } + // Get the related groups + const relatedGroupsEvent = room.currentState.getStateEvents('m.room.related_groups', ''); + const groups = relatedGroupsEvent ? relatedGroupsEvent.getContent().groups || [] : []; + + // Add this group as related + if (!groups.includes(groupId)) { + groups.push(groupId); + return MatrixClientPeg.get().sendStateEvent(roomId, 'm.room.related_groups', {groups}, ''); + } + }).reflect(); })).then(() => { if (errorList.length === 0) { return;