use Room.myMembership event instead of RoomMember.membership for me

This is more reliable with LL enabled as the syncing user is
only known when it was active in the current timeline
or when the members have been loaded
This commit is contained in:
Bruno Windels 2018-09-17 19:14:52 +02:00
parent 86cbe34181
commit 2ed414494f
4 changed files with 18 additions and 22 deletions

View file

@ -149,7 +149,7 @@ function createRoomTimelineAction(matrixClient, timelineEvent, room, toStartOfTi
*/
/**
* Create a MatrixActions.Room.selfMembership action that represents
* Create a MatrixActions.Room.myMembership action that represents
* a MatrixClient `RoomMember.membership` matrix event for the syncing user,
* emitted when the member's membership is updated.
*
@ -159,11 +159,8 @@ function createRoomTimelineAction(matrixClient, timelineEvent, room, toStartOfTi
* @param {string} oldMembership the member's previous membership.
* @returns {RoomMembershipAction} an action of type `MatrixActions.RoomMember.membership`.
*/
function createSelfRoomMembershipAction(matrixClient, membershipEvent, member, oldMembership) {
if (member.userId === matrixClient.getUserId()) {
return { action: 'MatrixActions.Room.selfMembership', member };
}
return null;
function createSelfMembershipAction(matrixClient, room, membership, oldMembership) {
return { action: 'MatrixActions.Room.myMembership', room, membership, oldMembership};
}
/**
@ -205,7 +202,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', createSelfRoomMembershipAction);
this._addMatrixClientListener(matrixClient, 'Room.myMembership', createSelfMembershipAction);
this._addMatrixClientListener(matrixClient, 'Event.decrypted', createEventDecryptedAction);
},

View file

@ -148,7 +148,7 @@ module.exports = React.createClass({
MatrixClientPeg.get().on("Room.name", this.onRoomName);
MatrixClientPeg.get().on("Room.accountData", this.onRoomAccountData);
MatrixClientPeg.get().on("RoomState.members", this.onRoomStateMember);
MatrixClientPeg.get().on("RoomMember.membership", this.onRoomMemberMembership);
MatrixClientPeg.get().on("Room.myMembership", this.onMyMembership);
MatrixClientPeg.get().on("accountData", this.onAccountData);
// Start listening for RoomViewStore updates
@ -412,8 +412,8 @@ module.exports = React.createClass({
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
MatrixClientPeg.get().removeListener("Room.name", this.onRoomName);
MatrixClientPeg.get().removeListener("Room.accountData", this.onRoomAccountData);
MatrixClientPeg.get().removeListener("Room.myMembership", this.onMyMembership);
MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember);
MatrixClientPeg.get().removeListener("RoomMember.membership", this.onRoomMemberMembership);
MatrixClientPeg.get().removeListener("accountData", this.onAccountData);
}
@ -715,10 +715,10 @@ module.exports = React.createClass({
this._updateRoomMembers();
},
onRoomMemberMembership: function(ev, member, oldMembership) {
if (member.userId == MatrixClientPeg.get().credentials.userId) {
this._loadMembersIfJoined();
onMyMembership: function(room, membership, oldMembership) {
if (room.roomId === this.state.roomId) {
this.forceUpdate();
this._loadMembersIfJoined(room);
}
},

View file

@ -43,11 +43,14 @@ module.exports = React.createClass({
componentWillMount: function() {
this._mounted = false;
const cli = MatrixClientPeg.get();
if (!cli.hasLazyLoadMembersEnabled()) {
if (cli.hasLazyLoadMembersEnabled()) {
// true means will not show a spinner but the
// known members so far if not joined
cli.on("Room.myMembership", this.onMyMembership);
} else {
this._listenForMembersChanges();
}
cli.on("Room", this.onRoom); // invites & joining after peek
cli.on("RoomMember.membership", this.onRoomMembership); // update when accepting an invite
const enablePresenceByHsUrl = SdkConfig.get()["enable_presence_by_hs_url"];
const hsUrl = MatrixClientPeg.get().baseUrl;
this._showPresence = true;
@ -79,7 +82,7 @@ module.exports = React.createClass({
if (cli) {
cli.removeListener("RoomState.members", this.onRoomStateMember);
cli.removeListener("RoomMember.name", this.onRoomMemberName);
cli.removeListener("RoomMember.membership", this.onRoomMembership);
cli.removeListener("Room.myMembership", this.onMyMembership);
cli.removeListener("RoomState.events", this.onRoomStateEvent);
cli.removeListener("Room", this.onRoom);
cli.removeListener("User.lastPresenceTs", this.onUserLastPresenceTs);
@ -182,12 +185,8 @@ module.exports = React.createClass({
this._loadMembersIfNeeded();
},
onRoomMembership: function(ev, member, oldMembership) {
const cli = MatrixClientPeg.get();
const myId = cli.getUserId();
if (member.userId === myId && oldMembership !== "join" && member.membership === "join") {
// once we've joined, no need to listen for membership anymore
cli.removeListener("RoomMember.membership", this.onRoomMembership);
onMyMembership: function(room, membership, oldMembership) {
if (room.roomId === this.props.roomId && membership === "join") {
this._loadMembersIfNeeded();
}
},

View file

@ -120,7 +120,7 @@ class RoomListStore extends Store {
this._generateRoomLists();
}
break;
case 'MatrixActions.Room.selfMembership': {
case 'MatrixActions.Room.myMembership': {
this._generateRoomLists();
}
break;