Skip to content

Commit

Permalink
prevent the creation of duplicate history entries
Browse files Browse the repository at this point in the history
  • Loading branch information
ticaki committed Aug 24, 2023
1 parent 23b0007 commit 476713f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ This adapter would not have been possible without the great work of @Zefau (http
-->
### **WORK IN PROGRESS**
- (ticaki) Fixed: Don't add empty notifications to history [#183](https://github.com/iobroker-community-adapters/ioBroker.plex/issues/183)
- (ticaki) Fixed: prevent the creation of duplicate history entries in most cases

### 1.0.2 (2023-08-23)
- (ticaki) Added: a play/pause switch for mediaplayer
Expand Down
2 changes: 1 addition & 1 deletion _NODES.js

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

26 changes: 20 additions & 6 deletions plex.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,26 @@ function setEvent(data, source, prefix)
'caption': replacePlaceholders(message.caption, eventData),
'source': data.source
}

// add event to history
history.push(notification);

data = Object.assign({}, notification); // copy object
data.history = JSON.stringify(history.slice(-1000));
// dont add events with same media, account, and event (within 1 sec)
let addNotification = true
for (let i = history.length-1; i>=0;i--) {
let lastItem = history[i]
if (lastItem.source != notification.source
&& lastItem.media == notification.media
&& lastItem.account == notification.account)
{
addNotification = lastItem.media != notification.media || lastItem.timestamp+1000 <= notification.timestamp
break
}
}

if (addNotification) {
// add event to history
history.push(notification);

data = Object.assign({}, notification); // copy object
data.history = JSON.stringify(history.slice(-1000));
}
} else {
adapter.log.debug('No message defined for ' + data.media + ' ' + event)
}
Expand Down

0 comments on commit 476713f

Please sign in to comment.