Roll back to using heroes for computing DM color

This commit is contained in:
Danila Fedorin 2021-06-30 15:07:27 -07:00
parent d0f70cbdf9
commit ee1f1500e9
7 changed files with 23 additions and 17 deletions

View file

@ -69,7 +69,7 @@ export class BaseTileViewModel extends ViewModel {
}
get avatarColorNumber() {
return getIdentifierColorNumber(this._avatarSource.id);
return getIdentifierColorNumber(this._avatarSource.avatarColorId);
}
avatarUrl(size) {

View file

@ -15,7 +15,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {getIdentifierColorNumber} from "../../avatar.js";
import {BaseTileViewModel} from "./BaseTileViewModel.js";
export class RoomTileViewModel extends BaseTileViewModel {
@ -76,10 +75,6 @@ export class RoomTileViewModel extends BaseTileViewModel {
return timeDiff;
}
get avatarColorNumber() {
return getIdentifierColorNumber(this._room.avatarColorId);
}
get isUnread() {
return this._room.isUnread;
}

View file

@ -341,8 +341,14 @@ export class BaseRoom extends EventEmitter {
return null;
}
/**
* Retrieve the identifier that should be used to color
* this room's avatar. By default this is the room's
* ID, but DM rooms should be the same color as their
* user's avatar.
*/
get avatarColorId() {
return this._summary.data.avatarColorId;
return this._roomId;
}
get lastMessageTimestamp() {

View file

@ -179,6 +179,7 @@ export class Invite extends EventEmitter {
_createData(inviteState, myInvite, inviter, summaryData, heroes) {
const name = heroes ? heroes.roomName : summaryData.name;
const avatarUrl = heroes ? heroes.roomAvatarUrl : summaryData.avatarUrl;
const avatarColorId = heroes ? heroes.roomAvatarColorId : this.id;
return {
roomId: this.id,
isEncrypted: !!summaryData.encryption,
@ -186,7 +187,7 @@ export class Invite extends EventEmitter {
// type:
name,
avatarUrl,
avatarColorId: summaryData.avatarColorId,
avatarColorId,
canonicalAlias: summaryData.canonicalAlias,
timestamp: this._platform.clock.now(),
joinRule: this._getJoinRule(inviteState),

View file

@ -328,6 +328,10 @@ export class Room extends BaseRoom {
});
}
get avatarColorId() {
return this._heroes?.roomAvatarColorId || this._roomId;
}
get isUnread() {
return this._summary.data.isUnread;
}

View file

@ -239,15 +239,6 @@ export class SummaryData {
return !this.name && !this.canonicalAlias && this.heroes && this.heroes.length > 0;
}
get avatarColorId() {
if (this.heroes && this.heroes.length === 1) {
for (const hero of this.heroes) {
return hero;
}
}
return this.roomId;
}
isNewJoin(oldData) {
return this.membership === "join" && oldData.membership !== "join";
}

View file

@ -97,4 +97,13 @@ export class Heroes {
}
return null;
}
get roomAvatarColorId() {
if (this._members.size === 1) {
for (const member of this._members.keys()) {
return member
}
}
return null;
}
}