Skip to content

Commit

Permalink
fix(call): add possibility to call user via context menu (#3484)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexZakablukov authored and JustZacca committed Jun 10, 2022
1 parent 90327b0 commit 6b96035
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion components/views/media/Media.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default Vue.extend({
isActiveCall() {
return (
this.webrtc.activeCall &&
this.webrtc.activeCall.callId === this.conversation.id
this.webrtc.activeCall.peerId === this.conversation.id
)
},
computedUsers() {
Expand Down
27 changes: 22 additions & 5 deletions components/views/user/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MessagingTypesEnum } from '~/libraries/Enums/enums'
import { RootState } from '~/types/store/store'
import { toHTML } from '~/libraries/ui/Markdown'
import { ContextMenuItem } from '~/store/ui/types'
import { TrackKind } from '~/libraries/WebRTC/types'
export default Vue.extend({
components: {
Expand Down Expand Up @@ -51,15 +52,16 @@ export default Vue.extend({
textilePubkey: (state) =>
(state as RootState).accounts?.details?.textilePubkey ?? '',
conversations: (state) => (state as RootState).textile?.conversations,
activeCall: (state) => (state as RootState).webrtc.activeCall,
}),
...mapGetters('textile', ['getConversation']),
...mapGetters('settings', ['getTimestamp']),
contextMenuValues(): ContextMenuItem[] {
return this.user.state === 'online'
return this.enableRTC
? [
{ text: this.$t('context.send'), func: this.navigateToUser },
{ text: this.$t('context.voice'), func: this.testFunc },
{ text: this.$t('context.video'), func: this.testFunc },
{ text: this.$t('context.voice'), func: this.handleCall },
// { text: this.$t('context.video'), func: this.testFunc },
// hide profile modal depend on this task AP-1717 (https://satellite-im.atlassian.net/browse/AP-1717)
// { text: this.$t('context.profile'), func: this.handleShowProfile },
{ text: this.$t('context.remove'), func: this.removeUser },
Expand Down Expand Up @@ -101,6 +103,9 @@ export default Vue.extend({
time: this.conversations[this.user.address]?.lastUpdate,
})
},
enableRTC(): boolean {
return this.user.state === 'online'
},
},
mounted() {
Array.from(
Expand All @@ -120,8 +125,20 @@ export default Vue.extend({
this.$store.commit('ui/toggleContextMenu', false)
},
methods: {
testFunc() {
this.$Logger.log('User Context', 'Test func')
async call(kinds: TrackKind[]) {
if (!this.enableRTC) {
return
}
await this.$store.dispatch('webrtc/call', {
kinds,
})
},
handleCall() {
if (!this.enableRTC || this.activeCall) {
return
}
this.navigateToUser()
this.call(['audio'])
},
async removeUser() {
this.isLoading = true
Expand Down
15 changes: 9 additions & 6 deletions store/conversation/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const actions = {
* @example
* store.dispatch('conversation/initialize');
*/
initialize(state: ActionsArguments<ConversationState>) {
state.commit('setConversation', {
initialize({ commit }: ActionsArguments<ConversationState>) {
commit('setConversation', {
id: '',
type: 'friend',
calling: false,
Expand All @@ -26,24 +26,27 @@ const actions = {
* store.dispatch('conversation/setConversation', conversation);
*/
setConversation(
state: ActionsArguments<ConversationState>,
{ commit }: ActionsArguments<ConversationState>,
payload: {
id: string
type: 'friend' | 'group'
calling?: boolean
participants: Array<ConversationParticipant>
},
) {
state.commit('setConversation', payload)
commit('setConversation', payload)
},
/**
* @method setCalling
* @description Set the calling state of the conversation
* @example
* store.dispatch('conversation/setCalling', true);
*/
setCalling(state: ActionsArguments<ConversationState>, calling: boolean) {
state.commit('setCalling', calling)
setCalling(
{ commit }: ActionsArguments<ConversationState>,
calling: boolean,
) {
commit('setCalling', calling)
},
/**
* @method addParticipant
Expand Down
4 changes: 2 additions & 2 deletions store/conversation/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConversationParticipant, ConversationState } from './types'

const actions = {
const mutations = {
setConversation(
state: ConversationState,
payload: {
Expand Down Expand Up @@ -60,4 +60,4 @@ const actions = {
})
},
}
export default actions
export default mutations

0 comments on commit 6b96035

Please sign in to comment.