Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(User): Show all users even if they are not friends #746

Merged
merged 8 commits into from
Oct 25, 2024
64 changes: 32 additions & 32 deletions src/lib/components/calling/CallScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,47 @@
import { callInProgress, callTimeout, TIME_TO_SHOW_CONNECTING, TIME_TO_SHOW_END_CALL_FEEDBACK, timeCallStarted, 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")

Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -118,33 +133,18 @@
}
}

$: if ($usersDeniedTheCall.length === chat.users.length - 1) {
setTimeout(() => {
Store.endCall()
VoiceRTCInstance.leaveCall()
dispatch("endCall")
}, TIME_TO_SHOW_END_CALL_FEEDBACK)
}

let showAnimation = true
let noResponseVisible = false
let message = $_("settings.calling.connecting")
let timeout: NodeJS.Timeout | undefined
let hideNoResponseUsersTimeout: NodeJS.Timeout | undefined
let callSound: SoundHandler | undefined = undefined

function hideNoResponseUsersAfterAPeriodOfTime() {
hideNoResponseUsersTimeout = setTimeout(() => {
noResponseVisible = false
}, 10000)
}

$: 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([])
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/messaging/Conversation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@
}

onDestroy(() => {
if (scrollContainer.scrollHeight <= scrollContainer.clientHeight) markAsRead($chat.id)
if (scrollContainer && scrollContainer.scrollHeight) {
if (scrollContainer?.scrollHeight <= scrollContainer?.clientHeight) markAsRead($chat.id)
}
})
</script>

Expand Down
27 changes: 26 additions & 1 deletion src/lib/wasm/MultipassStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>) {
const multipass = get(this.multipassWritable)

if (multipass) {
try {
let usersInCall: Array<string> = []
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.
Expand Down Expand Up @@ -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<string, string>() : identity.metadata,
media: {
Expand Down