Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional members #1771

Merged
merged 21 commits into from
Jul 22, 2021
Merged
Changes from 1 commit
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
27 changes: 24 additions & 3 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2039,20 +2039,41 @@ export class Room extends EventEmitter {
// -1 because these numbers include the syncing user
const inviteJoinCount = joinedMemberCount + invitedMemberCount - 1;

// get service members (e.g. helper bots) for exclusion
let excludedUserIds: string[] = [];
const mFunctionalMembers = this.currentState.getStateEvents(EventType.RoomFunctionalMembers, "");
if (mFunctionalMembers && mFunctionalMembers.getContent() && Array.isArray(mFunctionalMembers.getContent().service_members)) {
jaller94 marked this conversation as resolved.
Show resolved Hide resolved
excludedUserIds = mRoomName.getContent().service_members;
}

// get members that are NOT ourselves and are actually in the room.
let otherNames = null;
if (this.summaryHeroes) {
// if we have a summary, the member state events
// should be in the room state
otherNames = this.summaryHeroes.map((userId) => {
otherNames = [];
this.summaryHeroes.forEach((userId) => {
// filter service members
if (excludedUserIds.includes(userId)) {
inviteJoinCount--;
return;
}
const member = this.getMember(userId);
return member ? member.name : userId;
otherNames.push(member ? member.name : userId);
});
} else {
let otherMembers = this.currentState.getMembers().filter((m) => {
return m.userId !== userId &&
(m.membership === "invite" || m.membership === "join");
});
otherMembers = otherMembers.filter((userId) => {
// filter service members
if (excludedUserIds.includes(userId)) {
inviteJoinCount--;
return false;
}
return true;
});
// make sure members have stable order
otherMembers.sort((a, b) => a.userId.localeCompare(b.userId));
// only 5 first members, immitate summaryHeroes
Expand All @@ -2065,7 +2086,7 @@ export class Room extends EventEmitter {
}

const myMembership = this.getMyMembership();
// if I have created a room and invited people throuh
// if I have created a room and invited people through
// 3rd party invites
if (myMembership == 'join') {
const thirdPartyInvites =
Expand Down