From d8d89f04759373cee394ab0a2e869edaabbae05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Fri, 11 Oct 2024 08:08:53 +0200 Subject: [PATCH] [feat] create own function for showName --- src/index.ts | 1 + src/utils/index.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/utils/index.ts diff --git a/src/index.ts b/src/index.ts index 9bb7b23..f3f8945 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,3 +29,4 @@ const plugin: FG_Plugin.Plugin = { export default plugin; export { DisplayNameMode }; +export * from './utils'; diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 0000000..ba41dd8 --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,18 @@ +import { DisplayNameMode } from '../models'; +import { useUserStore } from '@flaschengeist/api'; + +export function showName(user: FG.User) { + const userStore = useUserStore(); + switch (userStore.userSettings.display_name) { + case DisplayNameMode.DISPLAYNAME: + return user.display_name; + case DisplayNameMode.FIRSTNAME: + return user.firstname; + case DisplayNameMode.LASTNAME: + return user.lastname; + case DisplayNameMode.FIRSTNAME_LASTNAME: + return `${user.firstname} ${user.lastname}`; + case DisplayNameMode.LASTNAME_FIRSTNAME: + return `${user.lastname}, ${user.firstname}`; + } +}