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

Add labs flag: Show only current profile on historical messages #7815

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 17 additions & 7 deletions src/components/views/avatars/MemberAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Copyright 2019 - 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -27,6 +27,8 @@ import { replaceableComponent } from "../../../utils/replaceableComponent";
import { mediaFromMxc } from "../../../customisations/Media";
import { CardContext } from '../right_panel/BaseCard';
import UserIdentifierCustomisations from '../../../customisations/UserIdentifier';
import SettingsStore from "../../../settings/SettingsStore";
import { MatrixClientPeg } from "../../../MatrixClientPeg";

interface IProps extends Omit<React.ComponentProps<typeof BaseAvatar>, "name" | "idName" | "url"> {
member: RoomMember;
Expand All @@ -41,6 +43,7 @@ interface IProps extends Omit<React.ComponentProps<typeof BaseAvatar>, "name" |
pushUserOnClick?: boolean;
title?: string;
style?: any;
forceHistorical?: boolean; // true to deny `feature_use_only_current_profiles` usage. Default false.
}

interface IState {
Expand All @@ -50,7 +53,7 @@ interface IState {
}

@replaceableComponent("views.avatars.MemberAvatar")
export default class MemberAvatar extends React.Component<IProps, IState> {
export default class MemberAvatar extends React.PureComponent<IProps, IState> {
public static defaultProps = {
width: 40,
height: 40,
Expand All @@ -69,20 +72,27 @@ export default class MemberAvatar extends React.Component<IProps, IState> {
}

private static getState(props: IProps): IState {
if (props.member?.name) {
let member = props.member;
if (member && !props.forceHistorical && SettingsStore.getValue("feature_use_only_current_profiles")) {
const room = MatrixClientPeg.get().getRoom(member.roomId);
if (room) {
member = room.getMember(member.userId);
}
}
if (member?.name) {
let imageUrl = null;
const userTitle = UserIdentifierCustomisations.getDisplayUserIdentifier(
props.member.userId, { roomId: props.member?.roomId },
member.userId, { roomId: member?.roomId },
);
if (props.member.getMxcAvatarUrl()) {
imageUrl = mediaFromMxc(props.member.getMxcAvatarUrl()).getThumbnailOfSourceHttp(
if (member.getMxcAvatarUrl()) {
imageUrl = mediaFromMxc(member.getMxcAvatarUrl()).getThumbnailOfSourceHttp(
props.width,
props.height,
props.resizeMethod,
);
}
return {
name: props.member.name,
name: member.name,
title: props.title || userTitle,
imageUrl: imageUrl,
};
Expand Down
16 changes: 13 additions & 3 deletions src/components/views/messages/SenderProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import UserIdentifier from '../../../customisations/UserIdentifier';
import { TileShape } from '../rooms/EventTile';
import SettingsStore from "../../../settings/SettingsStore";
import { MatrixClientPeg } from "../../../MatrixClientPeg";

interface IProps {
mxEvent: MatrixEvent;
Expand Down Expand Up @@ -107,9 +109,17 @@ export default class SenderProfile extends React.Component<IProps, IState> {
const colorClass = getUserNameColorClass(mxEvent.getSender());
const { msgtype } = mxEvent.getContent();

const disambiguate = mxEvent.sender?.disambiguate;
const displayName = mxEvent.sender?.rawDisplayName || mxEvent.getSender() || "";
const mxid = mxEvent.sender?.userId || mxEvent.getSender() || "";
let member = mxEvent.sender;
if (SettingsStore.getValue("feature_use_only_current_profiles")) {
const room = MatrixClientPeg.get().getRoom(mxEvent.getRoomId());
if (room) {
member = room.getMember(member.userId);
}
}

const disambiguate = member?.disambiguate || mxEvent.sender?.disambiguate;
const displayName = member?.rawDisplayName || mxEvent.getSender() || "";
const mxid = member?.userId || mxEvent.getSender() || "";

if (msgtype === MsgType.Emote && this.props.tileShape !== TileShape.ThreadPanel) {
return null; // emote message must include the name so don't duplicate it
Expand Down
1 change: 1 addition & 0 deletions src/components/views/rooms/EventTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ export default class EventTile extends React.Component<IProps, IState> {
width={avatarSize}
height={avatarSize}
viewUserOnClick={true}
forceHistorical={this.props.mxEvent.getType() === EventType.RoomMember}
/>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@
"Show message previews for reactions in all rooms": "Show message previews for reactions in all rooms",
"Offline encrypted messaging using dehydrated devices": "Offline encrypted messaging using dehydrated devices",
"Show extensible event representation of events": "Show extensible event representation of events",
"Show current avatar and name for users in message history": "Show current avatar and name for users in message history",
"Show info about bridges in room settings": "Show info about bridges in room settings",
"Use new room breadcrumbs": "Use new room breadcrumbs",
"New search experience": "New search experience",
Expand Down
7 changes: 7 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ export const SETTINGS: {[setting: string]: ISetting} = {
displayName: _td("Show extensible event representation of events"),
default: false,
},
"feature_use_only_current_profiles": {
isFeature: true,
labsGroup: LabGroup.Rooms,
supportedLevels: LEVELS_FEATURE,
displayName: _td("Show current avatar and name for users in message history"),
default: false,
},
"doNotDisturb": {
supportedLevels: [SettingLevel.DEVICE],
default: false,
Expand Down