Add user status on user profile icon (#33653)
* Add user status on user profile icon Currently unstyled & no tests * Style the user status icon * Update snapshot for avatar wrapper * More snapshot updates * add if braces * Split out user status functions to avoid circular dep which has the weird effect of just breaking jest's mocking. * type imports * Update imports * Update snapshot * Tests * baseline image * Just snapshot the component itself --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
co-authored by
Michael Telatynski
parent
f65a53a174
commit
bb07f84e41
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
const MAX_STATUS_TEXT_BYTES = 256;
|
||||
|
||||
export interface UserStatus {
|
||||
emoji: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export function userStatusTextWithinMaxLength(text: string): boolean {
|
||||
const textEncoder = new TextEncoder();
|
||||
return textEncoder.encode(text).length <= MAX_STATUS_TEXT_BYTES;
|
||||
}
|
||||
|
||||
export function validateUserStatus(rawUserStatus: unknown): UserStatus | undefined {
|
||||
if (typeof rawUserStatus !== "object" || rawUserStatus === null) {
|
||||
return undefined;
|
||||
}
|
||||
if ("emoji" in rawUserStatus === false || typeof rawUserStatus.emoji !== "string" || !rawUserStatus.emoji) {
|
||||
return undefined;
|
||||
}
|
||||
if ("text" in rawUserStatus === false || typeof rawUserStatus.text !== "string" || !rawUserStatus.text) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
emoji: rawUserStatus.emoji,
|
||||
text: userStatusTextWithinMaxLength(rawUserStatus.text)
|
||||
? rawUserStatus.text
|
||||
: `${rawUserStatus.text.slice(0, MAX_STATUS_TEXT_BYTES)}…`,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user