Fix issue where we may receive duplicate watched notifications when using websockets.

This commit is contained in:
Tim Van 2016-01-31 13:43:12 +02:00
commit 447caa9e9e
2 changed files with 15 additions and 8 deletions

View file

@ -378,8 +378,8 @@ from plexpy import common
var pms_ip = $("#pms_ip").val().trim(); var pms_ip = $("#pms_ip").val().trim();
var pms_port = $("#pms_port").val().trim(); var pms_port = $("#pms_port").val().trim();
var pms_identifier = $("#pms_identifier").val(); var pms_identifier = $("#pms_identifier").val();
var pms_ssl = $("#pms_ssl").val(); var pms_ssl = $("#pms_ssl").is(':checked') ? 1 : 0;
var pms_is_remote = $("#pms_is_remote").val(); var pms_is_remote = $("#pms_is_remote").is(':checked') ? 1 : 0;
if ((pms_ip !== '') || (pms_port !== '')) { if ((pms_ip !== '') || (pms_port !== '')) {
$("#pms-verify-status").html('<i class="fa fa-refresh fa-spin"></i> Validating server...'); $("#pms-verify-status").html('<i class="fa fa-refresh fa-spin"></i> Validating server...');
$('#pms-verify-status').fadeIn('fast'); $('#pms-verify-status').fadeIn('fast');

View file

@ -16,7 +16,7 @@
import time import time
import plexpy import plexpy
from plexpy import logger, pmsconnect, activity_processor, threading, notification_handler, helpers from plexpy import logger, pmsconnect, activity_processor, threading, notification_handler, helpers, notifiers
class ActivityHandler(object): class ActivityHandler(object):
@ -201,11 +201,18 @@ class ActivityHandler(object):
self.on_start() self.on_start()
# Monitor if the stream has reached the watch percentage for notifications # Monitor if the stream has reached the watch percentage for notifications
# The only purpose of this is for notifications # The only purpose of this is for notifications. Only process if any agents have on_watched toggled.
if any(d['on_watched'] == 1 for d in notifiers.available_notification_agents()):
progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration']) progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration'])
if progress_percent >= plexpy.CONFIG.NOTIFY_WATCHED_PERCENT and this_state != 'buffering': if progress_percent >= plexpy.CONFIG.NOTIFY_WATCHED_PERCENT and this_state != 'buffering':
threading.Thread(target=notification_handler.notify, # This is cheaper than having to send the request to notify each time.
kwargs=dict(stream_data=db_session, notify_action='watched')).start() notify_states = notification_handler.get_notify_state(db_session)
# This is a bit hacky but we're unaware of agents here so just check if any watched
# notifications are pending and allow it.
if any(d['on_watched'] is None for d in notify_states):
# Rather not put this on it's own thread so we know it completes before our next event.
notification_handler.notify(stream_data=db_session, notify_action='watched')
else: else:
# We don't have this session in our table yet, start a new one. # We don't have this session in our table yet, start a new one.