Expose user avatar URL field in the UI (#27)

* wip

* some fixes

* update readme

* update readme

* Add option to change/erase any user's avatar

* Fix README

* Remove mutationMode from Edit

* remove log

* update readme
This commit is contained in:
Aine
2024-09-17 23:06:12 +03:00
committed by GitHub
parent d5113aad72
commit 24cf0a60bf
13 changed files with 138 additions and 78 deletions

View File

@@ -1,4 +1,4 @@
import { fetchUtils } from "react-admin";
import { Identifier, fetchUtils } from "react-admin";
import storage from "../storage";
@@ -77,17 +77,17 @@ export function generateRandomMxId(): string {
* @param input the input string
* @returns full MXID as string
*/
export function returnMXID(input: string): string {
export function returnMXID(input: string | Identifier): string {
const homeserver = storage.getItem("home_server");
// Check if the input already looks like a valid MXID (i.e., starts with "@" and contains ":")
const mxidPattern = /^@[^@:]+:[^@:]+$/;
if (mxidPattern.test(input)) {
if (typeof input === 'string' && mxidPattern.test(input)) {
return input; // Already a valid MXID
}
// If input is not a valid MXID, assume it's a localpart and construct the MXID
const localpart = input.startsWith('@') ? input.slice(1) : input;
const localpart = typeof input === 'string' && input.startsWith('@') ? input.slice(1) : input;
return `@${localpart}:${homeserver}`;
}