Skip to content

Commit

Permalink
Fix #477: ended polls never disappear when archiving is disabled (and…
Browse files Browse the repository at this point in the history
… no more than 20 new messages).
  • Loading branch information
JohnXLivingston committed Jul 18, 2024
1 parent e8dc9a0 commit db1993f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 10.3.2

### Minor changes and fixes

* Fix #477: ended polls never disappear when archiving is disabled (and no more than 20 new messages).

## 10.3.1

### Minor changes and fixes
Expand Down
19 changes: 19 additions & 0 deletions conversejs/custom/plugins/poll/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import './components/poll-form-view.js'

const { sizzle } = converse.env

const delayedTimeout = 2 // for delayed poll message, how long must the be considered as valid.

converse.plugins.add('livechat-converse-poll', {
dependencies: ['converse-muc', 'converse-disco'],

Expand Down Expand Up @@ -97,6 +99,23 @@ converse.plugins.add('livechat-converse-poll', {
if (attrs.is_archived) {
return this.__super__.onMessage(attrs)
}
if (attrs.is_delayed) {
// When archiving is disabled, the "history" mechanism is still available:
// Last X (20 by default) messages will be kept, and sent to users.
// The only thing that differentiates such messages is that they are delayed.
// We can't just ignore all delayed messages, because if one day we enable SMACKS
// (to handle deconnections on poor network), there could be some legitimate delayed messages.
// So we will only ignore the poll if it was sent more than X minutes ago.
console.debug('Got a delayed poll message, checking if old or not')
const d = new Date()
d.setMinutes(d.getMinutes() - delayedTimeout)
if (attrs.time < d.toISOString()) {
console.debug(
`Poll message was delayed fore more than ${delayedTimeout} minutes (${attrs.time} < ${d.toISOString()}).`
)
return this.__super__.onMessage(attrs)
}
}

console.info('Got a poll message, setting it as the current_poll')
// this will be displayed by the livechat-converse-muc-poll custom element,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "peertube-plugin-livechat",
"description": "PeerTube plugin livechat: create chat rooms for your Peertube lives! Comes with many features: federation, moderation tools, chat bot, chat persistence, OBS integration, ...",
"version": "10.3.1",
"version": "10.3.2",
"license": "AGPL-3.0",
"author": {
"name": "John Livingston",
Expand Down

0 comments on commit db1993f

Please sign in to comment.