1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00
This commit is contained in:
Bruno Windels
2018-07-25 18:45:52 +02:00
parent e61c6b89c8
commit 9541aa7dbf
4 changed files with 17 additions and 14 deletions

View File

@@ -110,7 +110,7 @@ RoomState.prototype.getJoinedMemberCount = function() {
*/
RoomState.prototype.setJoinedMemberCount = function(count) {
this._joinedMemberCount = count;
}
};
/**
* Returns the number of invited members in this room
* @return {integer} The number of members in this room whose membership is 'invite'
@@ -130,7 +130,7 @@ RoomState.prototype.getInvitedMemberCount = function() {
*/
RoomState.prototype.setInvitedMemberCount = function(count) {
this._invitedMemberCount = count;
}
};
/**
* Get all RoomMembers in this room.

View File

@@ -391,7 +391,7 @@ Room.prototype.setSummary = function(summary) {
if (heroes) {
this._summaryHeroes = heroes;
}
}
};
/**
* Whether to send encrypted messages to devices within this room.
@@ -1301,11 +1301,15 @@ function calculateRoomName(room, userId, ignoreRoomNameEvent) {
// get members that are NOT ourselves and are actually in the room.
let otherMembers = null;
if (room._summaryHeroes) {
// if we have a summary, the member state events should have been in the room state
otherMembers = room._summaryHeroes.map((userId) => room.currentState.getMember(userId));
// if we have a summary, the member state events
// should be in the room state
otherMembers = room._summaryHeroes.map((userId) => {
return room.currentState.getMember(userId);
});
} else {
otherMembers = room.currentState.getMembers().filter((m) => {
return m.userId !== userId && (m.membership === "invite" || m.membership === "join");
return m.userId !== userId &&
(m.membership === "invite" || m.membership === "join");
});
// make sure members have stable order
otherMembers.sort((a, b) => a.userId.localeCompare(b.userId));
@@ -1323,7 +1327,7 @@ function calculateRoomName(room, userId, ignoreRoomNameEvent) {
if (myMembership == 'join') {
const thirdPartyInvites =
room.currentState.getStateEvents("m.room.third_party_invite");
if (thirdPartyInvites && thirdPartyInvites.length) {
const thirdPartyNames = thirdPartyInvites.map((i) => {
return {name: i.getContent().display_name};
@@ -1344,17 +1348,16 @@ function calculateRoomName(room, userId, ignoreRoomNameEvent) {
}
if(leftMembers.length) {
return `Empty room (was ${memberListToRoomName(leftMembers)})`;
}
else {
} else {
return "Empty room";
}
}
function memberListToRoomName(members, count = members.length) {
switch (members.length) {
case 0: return null;
case 1: return members[0].name;
case 2: return members[0].name + " and " + members[1].name;
case 0: return null;
case 1: return members[0].name;
case 2: return members[0].name + " and " + members[1].name;
default: return members[0].name + " and " + (count - 1) + " others";
}
}

View File

@@ -268,7 +268,7 @@ class SyncAccumulator {
const HEROES_KEY = "m.heroes";
const INVITED_COUNT_KEY = "m.invited_member_count";
const JOINED_COUNT_KEY = "m.joined_member_count";
const acc = currentData._summary;
const sum = data.summary;
acc[HEROES_KEY] = sum[HEROES_KEY] || acc[HEROES_KEY];

View File

@@ -1067,7 +1067,7 @@ SyncApi.prototype._processSyncResponse = async function(
if (joinObj.summary) {
room.setSummary(joinObj.summary);
}
// XXX: should we be adding ephemeralEvents to the timeline?
// It feels like that for symmetry with room.addAccountData()
// there should be a room.addEphemeralEvents() or similar.