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

Debounce User Info start dm "Message" button #7357

Merged
merged 1 commit into from
Dec 14, 2021
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
32 changes: 24 additions & 8 deletions src/components/views/right_panel/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const getE2EStatus = (cli: MatrixClient, userId: string, devices: IDevice
return anyDeviceUnverified ? E2EStatus.Warning : E2EStatus.Verified;
};

async function openDMForUser(matrixClient: MatrixClient, userId: string) {
async function openDMForUser(matrixClient: MatrixClient, userId: string): Promise<void> {
const lastActiveRoom = findDMForUser(matrixClient, userId);

if (lastActiveRoom) {
Expand Down Expand Up @@ -149,7 +149,7 @@ async function openDMForUser(matrixClient: MatrixClient, userId: string) {
}
}

return createRoom(createRoomOptions);
await createRoom(createRoomOptions);
}

type SetUpdating = (updating: boolean) => void;
Expand Down Expand Up @@ -318,6 +318,26 @@ function DevicesSection({ devices, userId, loading }: {devices: IDevice[], userI
);
}

const MessageButton = ({ userId }: { userId: string }) => {
const cli = useContext(MatrixClientContext);
const [busy, setBusy] = useState(false);

return (
<AccessibleButton
onClick={async () => {
if (busy) return;
setBusy(true);
await openDMForUser(cli, userId);
setBusy(false);
}}
className="mx_UserInfo_field"
disabled={busy}
>
{ _t("Message") }
</AccessibleButton>
);
};

const UserOptionsSection: React.FC<{
member: RoomMember;
isIgnored: boolean;
Expand Down Expand Up @@ -432,13 +452,9 @@ const UserOptionsSection: React.FC<{
</AccessibleButton>
);

let directMessageButton;
let directMessageButton: JSX.Element;
if (!isMe) {
directMessageButton = (
<AccessibleButton onClick={() => { openDMForUser(cli, member.userId); }} className="mx_UserInfo_field">
{ _t("Message") }
</AccessibleButton>
);
directMessageButton = <MessageButton userId={member.userId} />;
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1927,10 +1927,10 @@
"%(count)s sessions|other": "%(count)s sessions",
"%(count)s sessions|one": "%(count)s session",
"Hide sessions": "Hide sessions",
"Message": "Message",
"Jump to read receipt": "Jump to read receipt",
"Mention": "Mention",
"Share Link to User": "Share Link to User",
"Message": "Message",
"Demote yourself?": "Demote yourself?",
"You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the space it will be impossible to regain privileges.": "You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the space it will be impossible to regain privileges.",
"You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the room it will be impossible to regain privileges.": "You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the room it will be impossible to regain privileges.",
Expand Down