Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/PollViewer/PollViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ export default {

id(value) {
this.pollsStore.hidePollToast(value)
if (this.pollsStore.scheduledPolls[this.token]?.[value]) {
this.pollsStore.getPollData({
token: this.token,
pollId: value,
})
}
Comment on lines +299 to +304
Copy link
Contributor

@DorraJaouad DorraJaouad Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are just flushing requests upon opening poll viewer, we will lose the responsive UI when the dialog remains open (which I think it is the case for the polls that are created in the beginning of the webinars like Have you heard about Nextcloud before?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For chat relay, it is a must we get these information when someone votes:

  • Actor who voted
  • The option
  • the poll Id

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For chat relay, it is a must we get these information when someone votes:

  • Actor who voted

Only possible when it's a public poll :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only possible when it's a public poll :/

Yes, we are not even receiving poll_voted for anonymous poll, so if we receive it, it is evident it is a public poll

},

isInCall(value) {
Expand Down
4 changes: 2 additions & 2 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ const actions = {
if (isHiddenSystemMessage(message)) {
if (message.systemMessage === MESSAGE.SYSTEM_TYPE.POLL_VOTED) {
const pollsStore = usePollsStore()
pollsStore.debounceGetPollData({
pollsStore.scheduleGetPollData({
token,
pollId: message.messageParameters.poll.id,
})
Expand Down Expand Up @@ -562,7 +562,7 @@ const actions = {

if (message.systemMessage === MESSAGE.SYSTEM_TYPE.POLL_CLOSED) {
const pollsStore = usePollsStore()
pollsStore.getPollData({
pollsStore.scheduleGetPollData({
token,
pollId: message.messageParameters.poll.id,
})
Expand Down
34 changes: 17 additions & 17 deletions src/stores/polls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ type submitVotePayload = { token: string, pollId: string } & Pick<votePollParams
type State = {
polls: Record<string, Record<string, Poll>>
drafts: Record<string, Record<string, PollDraft>>
debouncedFunctions: Record<string, Record<string, () => void>>
scheduledPolls: Record<string, Record<string, boolean>>
activePoll: { token: string, id: string, name: string } | null
pollToastsQueue: Record<string, ReturnType<typeof showInfo>>
}
export const usePollsStore = defineStore('polls', {
state: (): State => ({
polls: {},
drafts: {},
debouncedFunctions: {},
scheduledPolls: {},
activePoll: null,
pollToastsQueue: {},
}),
Expand Down Expand Up @@ -101,33 +101,33 @@ export const usePollsStore = defineStore('polls', {
try {
const response = await getPollData(token, pollId)
this.addPoll({ token, poll: response.data.ocs.data })

// Unmark the poll as scheduled for update
if (this.scheduledPolls[token]?.[pollId]) {
delete this.scheduledPolls[token][pollId]
}
} catch (error) {
console.error(error)
}
},

/**
* In order to limit the amount of requests, we cannot get the
* poll data every time someone votes, so we create a debounce
* function for each poll and store it in the pollStore
* poll data every time someone votes, so we schedule an update
* of poll information for the next time user opens a dialog
*
* @param payload The arguments passed to the action
* @param payload.token The token of the conversation
* @param payload.pollId The id of the poll
*/
debounceGetPollData({ token, pollId }: { token: string, pollId: string }) {
if (!this.debouncedFunctions[token]) {
this.debouncedFunctions[token] = {}
}
// Create the debounced function for getting poll data if not exist yet
if (!this.debouncedFunctions[token]?.[pollId]) {
const debouncedFunction = debounce(async () => {
await this.getPollData({ token, pollId })
}, 5000)
this.debouncedFunctions[token][pollId] = debouncedFunction
}
// Call the debounced function for getting the poll data
this.debouncedFunctions[token][pollId]()
scheduleGetPollData({ token, pollId }: { token: string, pollId: string }) {
if (!this.scheduledPolls[token]) {
this.scheduledPolls[token] = {}
}
// Mark the poll as scheduled for update
if (!this.scheduledPolls[token]?.[pollId]) {
this.scheduledPolls[token][pollId] = true
}
},

async createPoll({ token, form, threadId }: { token: string, form: createPollParams, threadId?: number }) {
Expand Down
Loading