Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6393 from robintown/match-avatar-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Jul 17, 2021
2 parents 88aa218 + eefadf6 commit f7767bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/views/avatars/RoomAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ImageView from '../elements/ImageView';
import { MatrixClientPeg } from '../../../MatrixClientPeg';
import Modal from '../../../Modal';
import * as Avatar from '../../../Avatar';
import DMRoomMap from "../../../utils/DMRoomMap";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import { mediaFromMxc } from "../../../customisations/Media";
import { IOOBData } from '../../../stores/ThreepidInviteStore';
Expand Down Expand Up @@ -131,11 +132,14 @@ export default class RoomAvatar extends React.Component<IProps, IState> {
const { room, oobData, viewAvatarOnClick, onClick, ...otherProps } = this.props;

const roomName = room ? room.name : oobData.name;
// If the room is a DM, we use the other user's ID for the color hash
// in order to match the room avatar with their avatar
const idName = room ? (DMRoomMap.shared().getUserIdForRoomId(room.roomId) ?? room.roomId) : null;

return (
<BaseAvatar {...otherProps}
name={roomName}
idName={room ? room.roomId : null}
idName={idName}
urls={this.state.urls}
onClick={viewAvatarOnClick && this.state.urls[0] ? this.onRoomAvatarClick : onClick}
/>
Expand Down
6 changes: 6 additions & 0 deletions test/components/views/messages/TextualBody-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { mkEvent, mkStubRoom } from "../../../test-utils";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import * as languageHandler from "../../../../src/languageHandler";
import * as TestUtils from "../../../test-utils";
import DMRoomMap from "../../../../src/utils/DMRoomMap";

const _TextualBody = sdk.getComponent("views.messages.TextualBody");
const TextualBody = TestUtils.wrapInMatrixClientContext(_TextualBody);
Expand All @@ -41,6 +42,7 @@ describe("<TextualBody />", () => {
isGuest: () => false,
mxcUrlToHttp: (s) => s,
};
DMRoomMap.makeShared();

const ev = mkEvent({
type: "m.room.message",
Expand All @@ -66,6 +68,7 @@ describe("<TextualBody />", () => {
isGuest: () => false,
mxcUrlToHttp: (s) => s,
};
DMRoomMap.makeShared();

const ev = mkEvent({
type: "m.room.message",
Expand All @@ -92,6 +95,7 @@ describe("<TextualBody />", () => {
isGuest: () => false,
mxcUrlToHttp: (s) => s,
};
DMRoomMap.makeShared();
});

it("simple message renders as expected", () => {
Expand Down Expand Up @@ -146,6 +150,7 @@ describe("<TextualBody />", () => {
isGuest: () => false,
mxcUrlToHttp: (s) => s,
};
DMRoomMap.makeShared();
});

it("italics, bold, underline and strikethrough render as expected", () => {
Expand Down Expand Up @@ -292,6 +297,7 @@ describe("<TextualBody />", () => {
isGuest: () => false,
mxcUrlToHttp: (s) => s,
};
DMRoomMap.makeShared();

const ev = mkEvent({
type: "m.room.message",
Expand Down

0 comments on commit f7767bf

Please sign in to comment.