refactor: Workarounds for missing mHeroes in rooms

Normally we do not need a workaround here at all but we had
one in the displayname calculation for
historical reasons. A "good" server should always send the mHeroes correctly.
Instead of removing this workaround completely we do a compromise and implement a more
lightweight alt behaviour by just saying that in a DM room with no
heroes, the directChatMatrixId will be used. This is the same behaviour like in Element
and needs way less lines than before and also covers the avatar
calculation. For Synapse we seem to not need this but for Conduit it
might be helpful.
This commit is contained in:
Christian Pauly 2021-09-02 08:10:32 +02:00 committed by Krille Fear
parent fb62307730
commit 803c7598c6
1 changed files with 14 additions and 16 deletions

View File

@ -268,6 +268,12 @@ class Room {
.asUser
.avatarUrl;
}
if (isDirectChat) {
final user = directChatMatrixID;
if (user != null) {
return getUserByMXIDSync(user).avatarUrl;
}
}
if (membership == Membership.invite &&
getState(EventTypes.RoomMember, client.userID) != null) {
return getState(EventTypes.RoomMember, client.userID).sender.avatarUrl;
@ -404,26 +410,18 @@ class Room {
canonicalAlias.length > 3) {
return canonicalAlias.localpart;
}
var heroes = <String>[];
if (summary.mHeroes != null &&
summary.mHeroes.isNotEmpty &&
summary.mHeroes.any((h) => h.isNotEmpty)) {
heroes = summary.mHeroes;
} else {
if (states[EventTypes.RoomMember] is Map<String, dynamic>) {
for (final entry in states[EventTypes.RoomMember].entries) {
final state = entry.value;
if (state.type == EventTypes.RoomMember &&
state.stateKey != client?.userID) heroes.add(state.stateKey);
}
}
}
if (heroes.isNotEmpty) {
return heroes
if (summary.mHeroes != null && summary.mHeroes.isNotEmpty) {
return summary.mHeroes
.where((hero) => hero.isNotEmpty)
.map((hero) => getUserByMXIDSync(hero).calcDisplayname())
.join(', ');
}
if (isDirectChat) {
final user = directChatMatrixID;
if (user != null) {
return getUserByMXIDSync(user).displayName;
}
}
if (membership == Membership.invite &&
getState(EventTypes.RoomMember, client.userID) != null) {
return getState(EventTypes.RoomMember, client.userID)