Skip to content

Commit

Permalink
Show zephyr signatures :)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrc52 committed Aug 20, 2024
1 parent 523bc00 commit 9b280a8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/components/views/messages/DisambiguatedProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ interface IProps {
colored?: boolean;
emphasizeDisplayName?: boolean;
withTooltip?: boolean;

// These name overrides are used for Zephyr (if set, will use that name instead)
overrideName?: string | undefined;
overrideDisambiguation?: string | undefined;
}

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

Expand All @@ -52,8 +56,8 @@ export default class DisambiguatedProfile extends React.Component<IProps> {
withDisplayName: true,
roomId: member.roomId,
}) ?? mxid;
if (member?.disambiguate) {
mxidElement = <span className="mx_DisambiguatedProfile_mxid">{identifier}</span>;
if (overrideDisambiguation || member?.disambiguate) {
mxidElement = <span className="mx_DisambiguatedProfile_mxid">{overrideDisambiguation ?? identifier}</span>;
}
title = _t("timeline|disambiguated_profile", {
displayName: rawDisplayName,
Expand All @@ -68,7 +72,7 @@ export default class DisambiguatedProfile extends React.Component<IProps> {
return (
<div className="mx_DisambiguatedProfile" title={withTooltip ? title : undefined} onClick={onClick}>
<span className={displayNameClasses} dir="auto">
{rawDisplayName}
{overrideName ?? rawDisplayName}
</span>
{mxidElement}
</div>
Expand Down
29 changes: 28 additions & 1 deletion src/components/views/messages/SenderProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,37 @@ interface IProps {
withTooltip?: boolean;
}

export default function SenderProfile({ mxEvent, onClick, withTooltip }: IProps): JSX.Element {
export default function SenderProfile({ mxEvent, onClick, withTooltip }: IProps): JSX.Element {
const member = useRoomMemberProfile({
userId: mxEvent.getSender(),
member: mxEvent.sender,
});

// Zephyr specific stuff!

let overrideName: string | undefined;
let overrideDisambiguation: string | undefined;

const signature = mxEvent.getContent()['im.zephyr.signature'];
// const isAuthentic = mxEvent.getContent()['im.zephyr.authentic'];
if (signature) {
// This is a Zephyr message
// Not extracting it to a variable to avoid merge conflicts in the future
const senderId = mxEvent.getSender();
if (senderId) {
// Example: "@_zephyr_rgabriel:matrix.mit.edu"
const kerb = senderId.split(":")[0].substring(9);

// This doesn't look that good, commenting out for now...
// if (isAuthentic === true) {
// overrideName = kerb + " ✅";
// } else {
overrideName = kerb;
// }
overrideDisambiguation = signature;
}
}

return mxEvent.getContent().msgtype !== MsgType.Emote ? (
<DisambiguatedProfile
fallbackName={mxEvent.getSender() ?? ""}
Expand All @@ -41,6 +66,8 @@ export default function SenderProfile({ mxEvent, onClick, withTooltip }: IProps)
colored={true}
emphasizeDisplayName={true}
withTooltip={withTooltip}
overrideName={overrideName}
overrideDisambiguation={overrideDisambiguation}
/>
) : (
<></>
Expand Down

0 comments on commit 9b280a8

Please sign in to comment.