Merge pull request #562 from vector-im/bwindels/diagnose-561

return static string when member is missing and add logging
This commit is contained in:
Bruno Windels 2021-10-26 15:10:08 +02:00 committed by GitHub
commit 5b889f0b32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 9 deletions

View file

@ -208,7 +208,7 @@ export class BaseRoom extends EventEmitter {
if (this._summary.data.needsHeroes) {
this._heroes = new Heroes(this._roomId);
const changes = await this._heroes.calculateChanges(this._summary.data.heroes, [], txn);
this._heroes.applyChanges(changes, this._summary.data);
this._heroes.applyChanges(changes, this._summary.data, log);
}
} catch (err) {
throw new WrappedError(`Could not load room ${this._roomId}`, err);

View file

@ -139,7 +139,7 @@ export class Invite extends EventEmitter {
const summaryData = this._createSummaryData(inviteState);
let heroes;
if (!summaryData.name && !summaryData.canonicalAlias) {
heroes = await this._createHeroes(inviteState);
heroes = await this._createHeroes(inviteState, log);
}
const myInvite = this._getMyInvite(inviteState);
if (!myInvite) {
@ -204,7 +204,7 @@ export class Invite extends EventEmitter {
return inviteState.reduce(processStateEvent, new SummaryData(null, this.id));
}
async _createHeroes(inviteState) {
async _createHeroes(inviteState, log) {
const members = inviteState.filter(e => e.type === MEMBER_EVENT_TYPE);
const otherMembers = members.filter(e => e.state_key !== this._user.id);
const memberChanges = otherMembers.reduce((map, e) => {
@ -220,7 +220,7 @@ export class Invite extends EventEmitter {
const countSummary = new SummaryData(null, this.id);
countSummary.joinCount = members.reduce((sum, e) => sum + (e.content?.membership === "join" ? 1 : 0), 0);
countSummary.inviteCount = members.reduce((sum, e) => sum + (e.content?.membership === "invite" ? 1 : 0), 0);
heroes.applyChanges(changes, countSummary);
heroes.applyChanges(changes, countSummary, log);
return heroes;
}

View file

@ -240,7 +240,7 @@ export class Room extends BaseRoom {
}
if (this._heroes && heroChanges) {
const oldName = this.name;
this._heroes.applyChanges(heroChanges, this._summary.data);
this._heroes.applyChanges(heroChanges, this._summary.data, log);
if (oldName !== this.name) {
emitChange = true;
}

View file

@ -16,7 +16,7 @@ limitations under the License.
import {RoomMember} from "./RoomMember.js";
function calculateRoomName(sortedMembers, summaryData) {
function calculateRoomName(sortedMembers, summaryData, log) {
const countWithoutMe = summaryData.joinCount + summaryData.inviteCount - 1;
if (sortedMembers.length >= countWithoutMe) {
if (sortedMembers.length > 1) {
@ -24,7 +24,13 @@ function calculateRoomName(sortedMembers, summaryData) {
const firstMembers = sortedMembers.slice(0, sortedMembers.length - 1);
return firstMembers.map(m => m.name).join(", ") + " and " + lastMember.name;
} else {
return sortedMembers[0].name;
const otherMember = sortedMembers[0];
if (otherMember) {
return otherMember.name;
} else {
log.log({l: "could get get other member name", length: sortedMembers.length, otherMember: !!otherMember, otherMemberMembership: otherMember?.membership});
return "Unknown DM Name";
}
}
} else if (sortedMembers.length < countWithoutMe) {
return sortedMembers.map(m => m.name).join(", ") + ` and ${countWithoutMe} others`;
@ -74,7 +80,7 @@ export class Heroes {
return {updatedHeroMembers: updatedHeroMembers.values(), removedUserIds};
}
applyChanges({updatedHeroMembers, removedUserIds}, summaryData) {
applyChanges({updatedHeroMembers, removedUserIds}, summaryData, log) {
for (const userId of removedUserIds) {
this._members.delete(userId);
}
@ -82,7 +88,7 @@ export class Heroes {
this._members.set(member.userId, member);
}
const sortedMembers = Array.from(this._members.values()).sort((a, b) => a.name.localeCompare(b.name));
this._roomName = calculateRoomName(sortedMembers, summaryData);
this._roomName = calculateRoomName(sortedMembers, summaryData, log);
}
get roomName() {