Skip to content

Commit

Permalink
feat(Poll): pop up new arrived polls for participants in the call
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Feb 9, 2024
1 parent d000089 commit 822d579
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:class="{
'system-message': isSystemMessage && !showJoinCallButton,
'deleted-message': isDeletedMessage,
'call-started': showJoinCallButton,
'message-highlighted': showJoinCallButton,
}">
<!-- Message content / text -->
<CancelIcon v-if="isDeletedMessage" :size="16" />
Expand All @@ -49,6 +49,7 @@
<!-- Normal message body content -->
<div v-else
class="message-main__text markdown-message"
:class="{'message-highlighted': isNewPollMessage }"
@mouseover="handleMarkdownMouseOver"
@mouseleave="handleMarkdownMouseLeave">
<!-- Replied parent message -->
Expand Down Expand Up @@ -284,6 +285,14 @@ export default {
return this.messageParameters?.file
},

isNewPollMessage() {
if (this.messageParameters?.object?.type !== 'talk-poll') {
return false
}

return !!this.$store.getters.getNewPolls[this.messageParameters.object.id]
},

hideDate() {
return this.isTemporary || this.isDeleting || !!this.sendingFailure
},
Expand Down Expand Up @@ -440,7 +449,7 @@ export default {
padding: 0 20px;
}

&.call-started {
&.message-highlighted {
color: var(--color-text-light);
background-color: var(--color-primary-element-light);
padding: 10px;
Expand Down
28 changes: 28 additions & 0 deletions src/components/PollViewer/PollViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ import NcProgressBar from '@nextcloud/vue/dist/Components/NcProgressBar.js'
import PollVotersDetails from './PollVotersDetails.vue'
import LoadingComponent from '../LoadingComponent.vue'

import { useIsInCall } from '../../composables/useIsInCall.js'
import { POLL } from '../../constants.js'
import { EventBus } from '../../services/EventBus.js'

export default {
name: 'PollViewer',
Expand All @@ -138,6 +140,12 @@ export default {
PollIcon,
},

setup() {
return {
isInCall: useIsInCall(),
}
},

data() {
return {
voteToSubmit: [],
Expand Down Expand Up @@ -238,6 +246,10 @@ export default {
}
},

id(value) {
this.$store.dispatch('hidePollToast', value)
},

poll: {
immediate: true,
handler(value) {
Expand All @@ -252,6 +264,14 @@ export default {
},
},

mounted() {
EventBus.$on('talk:poll-added', this.showPopup)
},

beforeDestroy() {
EventBus.$off('talk:poll-added', this.showPopup)
},

methods: {
getPollData() {
if (!this.poll) {
Expand All @@ -268,6 +288,14 @@ export default {
: []
},

showPopup({ token, message }) {
if (!this.isInCall) {
return
}

this.$store.dispatch('addPollToast', { token, message })
},

dismissModal() {
this.$store.dispatch('removeActivePoll')
this.voteToSubmit = []
Expand Down
3 changes: 3 additions & 0 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ const actions = {
if (message.messageParameters?.object || message.messageParameters?.file) {
// Handle voice messages, shares with single file, polls, deck cards, e.t.c
sharedItemsStore.addSharedItemFromMessage(token, message)
if (message.messageParameters?.object?.type === 'talk-poll') {
EventBus.$emit('talk:poll-added', { token, message })
}
} else if (Object.keys(message.messageParameters).some(key => key.startsWith('file'))) {
// Handle shares with multiple files
}
Expand Down
41 changes: 40 additions & 1 deletion src/store/pollStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import debounce from 'debounce'
import Vue from 'vue'

import { showError } from '@nextcloud/dialogs'
import { showError, showInfo, TOAST_PERMANENT_TIMEOUT } from '@nextcloud/dialogs'

import pollService from '../services/pollService.js'

const state = {
polls: {},
pollDebounceFunctions: {},
activePoll: null,
pollToastsQueue: {},
}

const getters = {
Expand All @@ -40,6 +41,10 @@ const getters = {
activePoll: (state) => {
return state.activePoll
},

getNewPolls: (state) => {
return state.pollToastsQueue
},
}

const mutations = {
Expand All @@ -60,6 +65,17 @@ const mutations = {
}
},

addPollToast(state, { pollId, toast }) {
Vue.set(state.pollToastsQueue, pollId, toast)
},

hidePollToast(state, id) {
if (state.pollToastsQueue[id]) {
state.pollToastsQueue[id].hideToast()
Vue.delete(state.pollToastsQueue, id)
}
},

// Add debounce function for getting the poll data
addDebounceGetPollDataFunction(state, { token, pollId, debounceGetPollDataFunction }) {
if (!state.pollDebounceFunctions[token]) {
Expand Down Expand Up @@ -147,6 +163,29 @@ const actions = {
removeActivePoll(context) {
context.commit('removeActivePoll')
},

addPollToast(context, { token, message }) {
const pollId = message.messageParameters.object.id
const name = message.messageParameters.object.name

const toast = showInfo(t('spreed', 'Poll "{name}" was created by {user}. Click to vote', {
name,
user: message.actorDisplayName,
}), {
onClick: () => {
if (!context.state.activePoll) {
context.dispatch('setActivePoll', { token, pollId, name })
}
},
timeout: TOAST_PERMANENT_TIMEOUT,
})

context.commit('addPollToast', { pollId, toast })
},

hidePollToast(context, id) {
context.commit('hidePollToast', id)
},
}

export default { state, mutations, getters, actions }

0 comments on commit 822d579

Please sign in to comment.