replace getMember(myId).membership with getMyMembership

This works with rooms which haven't had their members
loaded yet.
This commit is contained in:
Bruno Windels 2018-08-02 11:42:05 +02:00
parent b9bbb7ee16
commit 908de56c6d
6 changed files with 15 additions and 17 deletions

View file

@ -194,8 +194,7 @@ function _getDirectMessageRooms(addr) {
const rooms = dmRooms.filter((dmRoom) => { const rooms = dmRooms.filter((dmRoom) => {
const room = MatrixClientPeg.get().getRoom(dmRoom); const room = MatrixClientPeg.get().getRoom(dmRoom);
if (room) { if (room) {
const me = room.getMember(MatrixClientPeg.get().credentials.userId); return room.getMyMembership() === 'join';
return me && me.membership == 'join';
} }
}); });
return rooms; return rooms;

View file

@ -759,7 +759,8 @@ module.exports = React.createClass({
_updateDMState() { _updateDMState() {
const me = this.state.room.getMember(MatrixClientPeg.get().getUserId()); const me = this.state.room.getMember(MatrixClientPeg.get().getUserId());
if (!me || me.membership !== "join") { const room = this.state.room;
if (room.getMyMembership() != "join") {
return; return;
} }
const roomId = this.state.room.roomId; const roomId = this.state.room.roomId;

View file

@ -54,8 +54,8 @@ export default class ChatCreateOrReuseDialog extends React.Component {
for (const roomId of dmRooms) { for (const roomId of dmRooms) {
const room = client.getRoom(roomId); const room = client.getRoom(roomId);
if (room) { if (room) {
const me = room.getMember(client.credentials.userId); const isInvite = room.getMyMembership() === "invite";
const highlight = room.getUnreadNotificationCount('highlight') > 0 || me.membership === "invite"; const highlight = room.getUnreadNotificationCount('highlight') > 0 || isInvite;
tiles.push( tiles.push(
<RoomTile key={room.roomId} room={room} <RoomTile key={room.roomId} room={room}
transparent={true} transparent={true}
@ -63,7 +63,7 @@ export default class ChatCreateOrReuseDialog extends React.Component {
selected={false} selected={false}
unread={Unread.doesRoomHaveUnreadMessages(room)} unread={Unread.doesRoomHaveUnreadMessages(room)}
highlight={highlight} highlight={highlight}
isInvite={me.membership === "invite"} isInvite={isInvite}
onClick={this.onRoomTileClick} onClick={this.onRoomTileClick}
/>, />,
); );

View file

@ -774,15 +774,16 @@ module.exports = withMatrixClient(React.createClass({
for (const roomId of dmRooms) { for (const roomId of dmRooms) {
const room = this.props.matrixClient.getRoom(roomId); const room = this.props.matrixClient.getRoom(roomId);
if (room) { if (room) {
const me = room.getMember(this.props.matrixClient.credentials.userId); const myMembership = room.getMyMembership();
if (myMembership !== 'join') continue;
const isInvite = myMembership === "invite";
// not a DM room if we have are not joined // not a DM room if we have are not joined
if (!me.membership || me.membership !== 'join') continue;
// not a DM room if they are not joined // not a DM room if they are not joined
const them = this.props.member; const them = this.props.member;
if (!them.membership || them.membership !== 'join') continue; if (!them.membership || them.membership !== 'join') continue;
const highlight = room.getUnreadNotificationCount('highlight') > 0 || me.membership === 'invite'; const highlight = room.getUnreadNotificationCount('highlight') > 0 || isInvite;
tiles.push( tiles.push(
<RoomTile key={room.roomId} room={room} <RoomTile key={room.roomId} room={room}
@ -791,7 +792,7 @@ module.exports = withMatrixClient(React.createClass({
selected={false} selected={false}
unread={Unread.doesRoomHaveUnreadMessages(room)} unread={Unread.doesRoomHaveUnreadMessages(room)}
highlight={highlight} highlight={highlight}
isInvite={me.membership === "invite"} isInvite={isInvite}
onClick={this.onRoomTileClick} onClick={this.onRoomTileClick}
/>, />,
); );

View file

@ -243,9 +243,7 @@ module.exports = React.createClass({
}, },
render: function() { render: function() {
const myUserId = MatrixClientPeg.get().credentials.userId; const isInvite = this.props.room.getMyMembership() === "invite";
const me = this.props.room.currentState.members[myUserId];
const notificationCount = this.state.notificationCount; const notificationCount = this.state.notificationCount;
// var highlightCount = this.props.room.getUnreadNotificationCount("highlight"); // var highlightCount = this.props.room.getUnreadNotificationCount("highlight");
@ -259,7 +257,7 @@ module.exports = React.createClass({
'mx_RoomTile_unread': this.props.unread, 'mx_RoomTile_unread': this.props.unread,
'mx_RoomTile_unreadNotify': notifBadges, 'mx_RoomTile_unreadNotify': notifBadges,
'mx_RoomTile_highlight': mentionBadges, 'mx_RoomTile_highlight': mentionBadges,
'mx_RoomTile_invited': (me && me.membership === 'invite'), 'mx_RoomTile_invited': isInvite,
'mx_RoomTile_menuDisplayed': this.state.menuDisplayed, 'mx_RoomTile_menuDisplayed': this.state.menuDisplayed,
'mx_RoomTile_noBadges': !badges, 'mx_RoomTile_noBadges': !badges,
'mx_RoomTile_transparent': this.props.transparent, 'mx_RoomTile_transparent': this.props.transparent,

View file

@ -77,8 +77,7 @@ export default class WidgetUtils {
return false; return false;
} }
const member = room.getMember(me); if (room.getMyMembership() !== "join") {
if (!member || member.membership !== "join") {
console.warn(`User ${me} is not in room ${roomId}`); console.warn(`User ${me} is not in room ${roomId}`);
return false; return false;
} }