diff --git a/components/compositions/conversations.ts b/components/compositions/conversations.ts index 0c9aa08926..128a5b3f22 100644 --- a/components/compositions/conversations.ts +++ b/components/compositions/conversations.ts @@ -1,4 +1,4 @@ -import { computed, ComputedRef } from 'vue' +import { computed, ComputedRef, reactive } from 'vue' import { Conversation } from '~/libraries/Iridium/chat/types' import iridium from '~/libraries/Iridium/IridiumManager' import { User } from '~/libraries/Iridium/users/types' @@ -7,12 +7,22 @@ import { TrackKind } from '~/libraries/WebRTC/types' export function conversationHooks() { // @ts-ignore const $nuxt = useNuxtApp() - const conversationId: ComputedRef = computed(() => { + + const managers = reactive({ + chat: iridium.chat, + users: iridium.users, + }) + + // todo - refactor so a conversationId param can be passed in rather than relying on route every time + const conversationId: ComputedRef = computed(() => { return $nuxt.$route.params.id }) const conversation: ComputedRef = computed(() => { - return iridium.chat.state.conversations[conversationId.value] + if (!conversationId.value) { + return + } + return managers.chat.state.conversations[conversationId.value] }) const isGroup: ComputedRef = computed(() => { @@ -27,26 +37,51 @@ export function conversationHooks() { ) }) + const otherParticipants: ComputedRef<(User | undefined)[]> = computed(() => { + return otherDids.value.map((did) => managers.users.getUser(did)) + }) + + const otherTypingParticipants: ComputedRef<(User | undefined)[]> = computed( + () => { + if (!conversationId.value) { + return [] + } + return ( + managers.chat.ephemeral.typing[conversationId.value]?.map((did) => + managers.users.getUser(did), + ) ?? [] + ) + }, + ) + + const allParticipantsAlphaSorted: ComputedRef<(User | undefined)[]> = + computed(() => { + if (!conversation.value) { + return [] + } + const arr = conversation.value.participants.map((p) => + managers.users.getUser(p), + ) as User[] + return arr.sort((a, b) => a.name.localeCompare(b.name)) + }) + const enableRTC: ComputedRef = computed(() => { return Boolean( otherDids.value?.filter( - (did) => iridium.users.ephemeral.status[did] === 'online', + (did) => managers.users.ephemeral.status[did] === 'online', ).length, ) }) - // for a DM - const userDetails: ComputedRef = computed(() => { - return iridium.users.state[otherDids.value[0]] - }) - return { conversation, conversationId, isGroup, otherDids, + otherParticipants, + otherTypingParticipants, + allParticipantsAlphaSorted, enableRTC, - userDetails, } } @@ -61,7 +96,7 @@ export async function call({ }) { // @ts-ignore const $nuxt = useNuxtApp() - const { enableRTC, otherDids } = conversationHooks() + const { enableRTC } = conversationHooks() if (!enableRTC.value) { return diff --git a/components/views/chat/UserList.vue b/components/views/chat/UserList.vue index 3ad5e33e93..831d6233c3 100644 --- a/components/views/chat/UserList.vue +++ b/components/views/chat/UserList.vue @@ -1,9 +1,15 @@ diff --git a/components/views/chat/chatbar/Chatbar.html b/components/views/chat/chatbar/Chatbar.html index 530a051c02..07552f737d 100644 --- a/components/views/chat/chatbar/Chatbar.html +++ b/components/views/chat/chatbar/Chatbar.html @@ -31,12 +31,12 @@ /> {{ $t('global.active_upload') }} - + diff --git a/components/views/navigation/mobile/toolbar/Toolbar.html b/components/views/navigation/mobile/toolbar/Toolbar.html index 485f76e6fa..cabbd98d6b 100644 --- a/components/views/navigation/mobile/toolbar/Toolbar.html +++ b/components/views/navigation/mobile/toolbar/Toolbar.html @@ -20,8 +20,8 @@ > -