Merge pull request #2102 from matrix-org/bwindels/selfmembershipchecks
Lazy loading: don't assume we have our own member available
This commit is contained in:
commit
5bb028d474
8 changed files with 26 additions and 31 deletions
|
@ -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;
|
||||||
|
|
|
@ -84,7 +84,7 @@ ConferenceCall.prototype._getConferenceUserRoom = function() {
|
||||||
preset: "private_chat",
|
preset: "private_chat",
|
||||||
invite: [this.confUserId]
|
invite: [this.confUserId]
|
||||||
}).then(function(res) {
|
}).then(function(res) {
|
||||||
return new Room(res.room_id);
|
return new Room(res.room_id, client.getUserId());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -758,15 +758,13 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateDMState() {
|
_updateDMState() {
|
||||||
const me = this.state.room.getMember(MatrixClientPeg.get().getUserId());
|
const room = this.state.room;
|
||||||
if (!me || me.membership !== "join") {
|
if (room.getMyMembership() != "join") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const roomId = this.state.room.roomId;
|
const dmInviter = room.getDMInviter();
|
||||||
const dmInviter = me.getDMInviter();
|
|
||||||
|
|
||||||
if (dmInviter) {
|
if (dmInviter) {
|
||||||
Rooms.setDMRoom(roomId, dmInviter);
|
Rooms.setDMRoom(room.roomId, dmInviter);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
|
@ -774,15 +774,15 @@ 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();
|
||||||
|
|
||||||
// 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;
|
if (myMembership !== 'join') continue;
|
||||||
// not a DM room if they are not joined
|
|
||||||
const them = this.props.member;
|
const them = this.props.member;
|
||||||
|
// not a DM room if they are not joined
|
||||||
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;
|
||||||
|
|
||||||
tiles.push(
|
tiles.push(
|
||||||
<RoomTile key={room.roomId} room={room}
|
<RoomTile key={room.roomId} room={room}
|
||||||
|
@ -791,7 +791,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={false}
|
||||||
onClick={this.onRoomTileClick}
|
onClick={this.onRoomTileClick}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,15 +20,16 @@ function generateRoomId() {
|
||||||
return '!' + Math.random().toString().slice(2, 10) + ':domain';
|
return '!' + Math.random().toString().slice(2, 10) + ':domain';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
describe('RoomList', () => {
|
||||||
function createRoom(opts) {
|
function createRoom(opts) {
|
||||||
const room = new Room(generateRoomId());
|
const room = new Room(generateRoomId(), client.getUserId());
|
||||||
if (opts) {
|
if (opts) {
|
||||||
Object.assign(room, opts);
|
Object.assign(room, opts);
|
||||||
}
|
}
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('RoomList', () => {
|
|
||||||
let parentDiv = null;
|
let parentDiv = null;
|
||||||
let sandbox = null;
|
let sandbox = null;
|
||||||
let client = null;
|
let client = null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue