diff --git a/changedetectionio/api/api_v1.py b/changedetectionio/api/api_v1.py index 783827ca..052bc94e 100644 --- a/changedetectionio/api/api_v1.py +++ b/changedetectionio/api/api_v1.py @@ -76,7 +76,7 @@ class Watch(Resource): # Properties are not returned as a JSON, so add the required props manually watch['history_n'] = watch.history_n watch['last_changed'] = watch.last_changed - + watch['viewed'] = watch.viewed return watch @auth.check_token @@ -280,11 +280,14 @@ class CreateWatch(Resource): if tag_limit and not any(v.get('title').lower() == tag_limit for k, v in tags.items()): continue - list[uuid] = {'url': watch['url'], - 'title': watch['title'], - 'last_checked': watch['last_checked'], - 'last_changed': watch.last_changed, - 'last_error': watch['last_error']} + list[uuid] = { + 'last_changed': watch.last_changed, + 'last_checked': watch['last_checked'], + 'last_error': watch['last_error'], + 'title': watch['title'], + 'url': watch['url'], + 'viewed': watch.viewed + } if request.args.get('recheck_all'): for uuid in self.datastore.data['watching'].keys(): diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index 50cbb6b3..a4774efc 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -113,7 +113,8 @@ class model(dict): @property def viewed(self): - if int(self['last_viewed']) >= int(self.newest_history_key) : + # Don't return viewed when last_viewed is 0 and newest_key is 0 + if int(self['last_viewed']) and int(self['last_viewed']) >= int(self.newest_history_key) : return True return False diff --git a/changedetectionio/tests/test_api.py b/changedetectionio/tests/test_api.py index 23051454..8f0eb949 100644 --- a/changedetectionio/tests/test_api.py +++ b/changedetectionio/tests/test_api.py @@ -96,7 +96,9 @@ def test_api_simple(client, live_server): ) assert watch_uuid in res.json.keys() before_recheck_info = res.json[watch_uuid] + assert before_recheck_info['last_checked'] != 0 + #705 `last_changed` should be zero on the first check assert before_recheck_info['last_changed'] == 0 assert before_recheck_info['title'] == 'My test URL' @@ -157,6 +159,18 @@ def test_api_simple(client, live_server): # @todo how to handle None/default global values? assert watch['history_n'] == 2, "Found replacement history section, which is in its own API" + assert watch.get('viewed') == False + # Loading the most recent snapshot should force viewed to become true + client.get(url_for("diff_history_page", uuid="first"), follow_redirects=True) + + # Fetch the whole watch again, viewed should be true + res = client.get( + url_for("watch", uuid=watch_uuid), + headers={'x-api-key': api_key} + ) + watch = res.json + assert watch.get('viewed') == True + # basic systeminfo check res = client.get( url_for("systeminfo"),