11<script lang="ts">
2- import type { Room } from ' matrix-js-sdk'
32import type { ImgProps } from ' ~/components/img.vue'
43
54export type MatrixAvatarProps = Omit <ImgProps , ' src' | ' alt' > & {
65 square? : boolean
7- room? : Room | undefined
8- user: MaybeUserOrId | undefined | null
96 imageSize? : AvatarImageSize
10- }
7+ } & (
8+ | { room: MaybeRoomOrId | undefined | null , user? : never , src? : never }
9+ | { user: MaybeUserOrId | undefined | null , room? : never , src? : never }
10+ | { src: string | undefined | null , room? : never , user? : never }
11+ )
1112</script >
1213
1314< script setup lang = " ts" >
@@ -18,16 +19,32 @@ const props = withDefaults(
1819 },
1920)
2021
21- const userProfile = useUserProfile (() => typeof props .user === ' string' ? props .user : props .user ?.userId )
22- const resolvedAvatar = useResolveAvatarUrl (() => userProfile .value ?.avatar_url , { size: props .imageSize })
22+ const room = useRoom (() => props .room ?? undefined )
23+ const userProfile = useUserProfile (() => props .user ?? undefined )
24+
25+ const src = computed (() => {
26+ if (props .src ) return props .src
27+
28+ if (room .value )
29+ return room .value .getMxcAvatarUrl () ?? undefined
30+
31+ if (userProfile .value )
32+ return userProfile .value .avatar_url
33+
34+ return undefined
35+ })
36+
37+ const resolvedAvatar = useResolveAvatarUrl (src , { size: props .imageSize })
2338
2439const isError = ref (false )
40+
41+ const delegatedProps = reactiveOmit (props , ' room' , ' user' , ' src' , ' square' , ' imageSize' )
2542 </script >
2643
2744<template >
2845 <Img
2946 v-if =" resolvedAvatar"
30- v-bind =" props "
47+ v-bind =" delegatedProps "
3148 :key =" resolvedAvatar"
3249 data-slot =" avatar"
3350 :alt =" userProfile?.displayname ? `${userProfile?.displayname}'s avatar` : 'Avatar'"
0 commit comments