From 58cf9fb99709bb1979fca991b535646ecc4951a2 Mon Sep 17 00:00:00 2001 From: lgmarchi Date: Mon, 21 Oct 2024 18:26:45 -0300 Subject: [PATCH] Show all users in call, even if they are not friends --- src/lib/components/calling/CallScreen.svelte | 65 +++++++++---------- .../components/messaging/Conversation.svelte | 4 +- src/lib/wasm/MultipassStore.ts | 27 +++++++- 3 files changed, 61 insertions(+), 35 deletions(-) diff --git a/src/lib/components/calling/CallScreen.svelte b/src/lib/components/calling/CallScreen.svelte index 86094c1e0..c86f23c5c 100644 --- a/src/lib/components/calling/CallScreen.svelte +++ b/src/lib/components/calling/CallScreen.svelte @@ -16,23 +16,47 @@ import { callTimeout, TIME_TO_SHOW_CONNECTING, TIME_TO_SHOW_END_CALL_FEEDBACK, usersAcceptedTheCall, usersDeniedTheCall, VoiceRTCInstance } from "$lib/media/Voice" import { log } from "$lib/utils/Logger" import { playSound, SoundHandler, Sounds } from "../utils/SoundHandler" + import { MultipassStoreInstance } from "$lib/wasm/MultipassStore" export let expanded: boolean = false - function toggleExanded() { - expanded = !expanded - } + export let deafened: boolean = get(Store.state.devices.deafened) + export let chat: Chat let showVolumeMixer = false let showCallSettings = false - let muted: boolean = !VoiceRTCInstance.callOptions.audio.enabled let cameraEnabled: boolean = get(Store.state.devices.cameraEnabled) + let isFullScreen = false + let localVideoCurrentSrc: HTMLVideoElement - export let deafened: boolean = get(Store.state.devices.deafened) - export let chat: Chat + let showAnimation = true + let message = $_("settings.calling.connecting") + let timeout: NodeJS.Timeout | undefined + let callSound: SoundHandler | undefined = undefined + + $: if ($usersAcceptedTheCall.length > 0) { + callSound?.stop() + callSound = undefined + } + $: userCache = Store.getUsersLookup(chat.users) + $: userCallOptions = VoiceRTCInstance.callOptions + $: remoteStreams = Store.state.activeCallMeta + $: ownUserName = get(Store.state.user).name + + $: if ($usersDeniedTheCall.length === chat.users.length - 1) { + setTimeout(() => { + Store.endCall() + VoiceRTCInstance.leaveCall() + dispatch("endCall") + }, TIME_TO_SHOW_END_CALL_FEEDBACK) + } let dispatch = createEventDispatcher() + function toggleExanded() { + expanded = !expanded + } + function toggleFullscreen() { const elem = document.getElementById("call-screen") @@ -50,13 +74,6 @@ userCallOptions = userCallOptions } - let isFullScreen = false - - $: userCache = Store.getUsersLookup(chat.users) - $: userCallOptions = VoiceRTCInstance.callOptions - $: remoteStreams = Store.state.activeCallMeta - $: ownUserName = get(Store.state.user).name - let subscribeOne = Store.state.devices.muted.subscribe(state => { muted = state userCallOptions = VoiceRTCInstance.callOptions @@ -78,8 +95,6 @@ userCallOptions = VoiceRTCInstance.callOptions }) - let localVideoCurrentSrc: HTMLVideoElement - function handleClickOutside(event: MouseEvent) { const callSettingsElement = document.getElementById("call-settings") const showVolumeElement = document.getElementById("volume-mixer") @@ -118,25 +133,9 @@ } } - $: if ($usersDeniedTheCall.length === chat.users.length - 1) { - setTimeout(() => { - Store.endCall() - VoiceRTCInstance.leaveCall() - dispatch("endCall") - }, TIME_TO_SHOW_END_CALL_FEEDBACK) - } - - let showAnimation = true - let message = $_("settings.calling.connecting") - let timeout: NodeJS.Timeout | undefined - let callSound: SoundHandler | undefined = undefined - - $: if ($usersAcceptedTheCall.length > 0) { - callSound?.stop() - callSound = undefined - } - onMount(async () => { + await MultipassStoreInstance.listUsersForACall(chat.users) + userCache = Store.getUsersLookup(chat.users) usersDeniedTheCall.set([]) callTimeout.set(false) usersAcceptedTheCall.set([]) diff --git a/src/lib/components/messaging/Conversation.svelte b/src/lib/components/messaging/Conversation.svelte index e10d0465c..e07f1dd44 100644 --- a/src/lib/components/messaging/Conversation.svelte +++ b/src/lib/components/messaging/Conversation.svelte @@ -85,7 +85,9 @@ } onDestroy(() => { - if (scrollContainer.scrollHeight <= scrollContainer.clientHeight) markAsRead($chat.id) + if (scrollContainer && scrollContainer.scrollHeight) { + if (scrollContainer?.scrollHeight <= scrollContainer?.clientHeight) markAsRead($chat.id) + } }) diff --git a/src/lib/wasm/MultipassStore.ts b/src/lib/wasm/MultipassStore.ts index f1d5ff927..2ac4d19c0 100644 --- a/src/lib/wasm/MultipassStore.ts +++ b/src/lib/wasm/MultipassStore.ts @@ -391,6 +391,31 @@ class MultipassStore { } } + /** + * Lists users for a call. + * Update users cache if they are not already in cache. + * It avoids problem if there is some user in call that is not current user's friend. + */ + async listUsersForACall(callUsers: Array) { + const multipass = get(this.multipassWritable) + + if (multipass) { + try { + let usersInCall: Array = [] + for (let i = 0; i < callUsers.length; i++) { + let userInCall = await this.identity_from_did(callUsers[i]) + if (userInCall) { + usersInCall.push(userInCall.key) + // Add users in cache + Store.updateUser(userInCall) + } + } + } catch (error) { + log.error("Error getting users in a call: " + error) + } + } + } + /** * Removes a friend. * @param did - The DID of the friend to be removed. @@ -611,7 +636,7 @@ class MultipassStore { overlay: "", }, status: status, - status_message: identity === undefined ? "" : (identity.status_message ?? ""), + status_message: identity === undefined ? "" : identity.status_message ?? "", }, integrations: identity === undefined ? new Map() : identity.metadata, media: {