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

Commit

Permalink
De-flair new sender profile
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Mar 22, 2022
1 parent a17c894 commit 30c3816
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 74 deletions.
4 changes: 1 addition & 3 deletions src/components/views/messages/DisambiguatedProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ import UserIdentifier from "../../../customisations/UserIdentifier";
interface IProps {
member?: RoomMember;
fallbackName: string;
flair?: JSX.Element;
onClick?(): void;
colored?: boolean;
emphasizeDisplayName?: boolean;
}

export default class DisambiguatedProfile extends React.Component<IProps> {
render() {
const { fallbackName, member, flair, colored, emphasizeDisplayName, onClick } = this.props;
const { fallbackName, member, colored, emphasizeDisplayName, onClick } = this.props;
const rawDisplayName = member?.rawDisplayName || fallbackName;
const mxid = member?.userId;

Expand Down Expand Up @@ -64,7 +63,6 @@ export default class DisambiguatedProfile extends React.Component<IProps> {
{ rawDisplayName }
</span>
{ mxidElement }
{ flair }
</div>
);
}
Expand Down
71 changes: 0 additions & 71 deletions src/components/views/messages/SenderProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import React from 'react';
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MsgType } from "matrix-js-sdk/src/@types/event";

import Flair from '../elements/Flair';
import FlairStore from '../../../stores/FlairStore';
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import DisambiguatedProfile from "./DisambiguatedProfile";
Expand All @@ -37,65 +35,6 @@ export default class SenderProfile extends React.PureComponent<IProps> {
public static contextType = MatrixClientContext;
public context!: React.ContextType<typeof MatrixClientContext>;

constructor(props: IProps) {
super(props);
const senderId = this.props.mxEvent.getSender();

this.state = {
userGroups: FlairStore.cachedPublicisedGroups(senderId) || [],
relatedGroups: [],
};
}

componentDidMount() {
this.updateRelatedGroups();

if (this.state.userGroups.length === 0) {
this.getPublicisedGroups();
}

this.context.on(RoomStateEvent.Events, this.onRoomStateEvents);
}

componentWillUnmount() {
this.unmounted = true;
this.context.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
}

private async getPublicisedGroups() {
const userGroups = await FlairStore.getPublicisedGroupsCached(this.context, this.props.mxEvent.getSender());
if (this.unmounted) return;
this.setState({ userGroups });
}

private onRoomStateEvents = (event: MatrixEvent) => {
if (event.getType() === 'm.room.related_groups' && event.getRoomId() === this.props.mxEvent.getRoomId()) {
this.updateRelatedGroups();
}
};

private updateRelatedGroups() {
const room = this.context.getRoom(this.props.mxEvent.getRoomId());
if (!room) return;

const relatedGroupsEvent = room.currentState.getStateEvents('m.room.related_groups', '');
this.setState({
relatedGroups: relatedGroupsEvent?.getContent().groups || [],
});
}

private getDisplayedGroups(userGroups?: string[], relatedGroups?: string[]) {
let displayedGroups = userGroups || [];
if (relatedGroups && relatedGroups.length > 0) {
displayedGroups = relatedGroups.filter((groupId) => {
return displayedGroups.includes(groupId);
});
} else {
displayedGroups = [];
}
return displayedGroups;
}

render() {
const { mxEvent, onClick } = this.props;
const msgtype = mxEvent.getContent().msgtype;
Expand All @@ -116,19 +55,9 @@ export default class SenderProfile extends React.PureComponent<IProps> {
return null; // emote message must include the name so don't duplicate it
}

let flair;
if (this.props.enableFlair) {
const displayedGroups = this.getDisplayedGroups(
this.state.userGroups, this.state.relatedGroups,
);

flair = <Flair key='flair' userId={mxEvent.getSender()} groups={displayedGroups} />;
}

return (
<DisambiguatedProfile
fallbackName={mxEvent.getSender() || ""}
flair={flair}
onClick={onClick}
member={member}
colored={true}
Expand Down

0 comments on commit 30c3816

Please sign in to comment.