Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

only dispatch an action for self-membership #2160

Merged
merged 2 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/actions/MatrixActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,21 @@ function createRoomTimelineAction(matrixClient, timelineEvent, room, toStartOfTi
*/

/**
* Create a MatrixActions.RoomMember.membership action that represents
* a MatrixClient `RoomMember.membership` matrix event, emitted when a
* member's membership is updated.
* Create a MatrixActions.Room.selfMembership action that represents
* a MatrixClient `RoomMember.membership` matrix event for the syncing user,
* emitted when the member's membership is updated.
*
* @param {MatrixClient} matrixClient the matrix client.
* @param {MatrixEvent} membershipEvent the m.room.member event.
* @param {RoomMember} member the member whose membership was updated.
* @param {string} oldMembership the member's previous membership.
* @returns {RoomMembershipAction} an action of type `MatrixActions.RoomMember.membership`.
*/
function createRoomMembershipAction(matrixClient, membershipEvent, member, oldMembership) {
return { action: 'MatrixActions.RoomMember.membership', member };
function createSelfRoomMembershipAction(matrixClient, membershipEvent, member, oldMembership) {
if (member.userId === matrixClient.getUserId()) {
return { action: 'MatrixActions.Room.selfMembership', member };
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly a return null for clarity?

return null;
}

/**
Expand Down Expand Up @@ -202,7 +205,7 @@ export default {
this._addMatrixClientListener(matrixClient, 'Room', createRoomAction);
this._addMatrixClientListener(matrixClient, 'Room.tags', createRoomTagsAction);
this._addMatrixClientListener(matrixClient, 'Room.timeline', createRoomTimelineAction);
this._addMatrixClientListener(matrixClient, 'RoomMember.membership', createRoomMembershipAction);
this._addMatrixClientListener(matrixClient, 'RoomMember.membership', createSelfRoomMembershipAction);
this._addMatrixClientListener(matrixClient, 'Event.decrypted', createEventDecryptedAction);
},

Expand All @@ -217,7 +220,10 @@ export default {
*/
_addMatrixClientListener(matrixClient, eventName, actionCreator) {
const listener = (...args) => {
dis.dispatch(actionCreator(matrixClient, ...args), true);
const payload = actionCreator(matrixClient, ...args);
if (payload) {
dis.dispatch(payload, true);
}
};
matrixClient.on(eventName, listener);
this._matrixClientListenersStop.push(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/stores/RoomListStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ class RoomListStore extends Store {
this._generateRoomLists();
}
break;
case 'MatrixActions.RoomMember.membership': {
if (!this._matrixClient || payload.member.userId !== this._matrixClient.credentials.userId) break;
case 'MatrixActions.Room.selfMembership': {
this._generateRoomLists();
}
break;
Expand Down