2019-11-07 17:36:16 +01:00
|
|
|
/*
|
2024-09-09 15:57:16 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2019-11-07 17:36:16 +01:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 15:57:16 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-11-07 17:36:16 +01:00
|
|
|
*/
|
|
|
|
|
2023-05-23 17:24:12 +02:00
|
|
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import { _t } from "../languageHandler";
|
2019-11-07 17:36:16 +01:00
|
|
|
|
2023-05-23 17:24:12 +02:00
|
|
|
export function getNameForEventRoom(matrixClient: MatrixClient, userId: string, roomId: string): string {
|
|
|
|
const room = matrixClient.getRoom(roomId);
|
2020-01-24 14:20:48 +01:00
|
|
|
const member = room && room.getMember(userId);
|
2019-11-07 17:39:50 +01:00
|
|
|
return member ? member.name : userId;
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:24:12 +02:00
|
|
|
export function userLabelForEventRoom(matrixClient: MatrixClient, userId: string, roomId: string): string {
|
|
|
|
const name = getNameForEventRoom(matrixClient, userId, roomId);
|
2019-11-07 17:39:50 +01:00
|
|
|
if (name !== userId) {
|
2023-09-22 17:39:40 +02:00
|
|
|
return _t("name_and_id", { name, userId });
|
2019-11-07 17:39:50 +01:00
|
|
|
} else {
|
|
|
|
return userId;
|
|
|
|
}
|
|
|
|
}
|