mirror of
https://github.com/simon987/poal_feed.git
synced 2025-04-04 08:23:03 +00:00
28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
from hexlib.db import VolatileState, VolatileBooleanState
|
|
|
|
|
|
class PoalState:
|
|
def __init__(self, prefix, host, port):
|
|
self._posts = VolatileState(prefix, host=host, port=port)
|
|
self._comments = VolatileBooleanState(prefix, host=host, port=port)
|
|
self._users = VolatileBooleanState(prefix, host=host, port=port)
|
|
|
|
def has_visited(self, item_id):
|
|
return self._comments["comments"][item_id]
|
|
|
|
def mark_visited(self, item_id):
|
|
self._comments["comments"][item_id] = True
|
|
|
|
def mark_post_as_visited(self, post, helper):
|
|
self._posts["posts"][helper.item_unique_id(post)] = post["comments"]
|
|
|
|
def has_new_comments(self, post, helper):
|
|
comment_count = self._posts["posts"][helper.item_unique_id(post)]
|
|
return comment_count is None or post["comments"] > comment_count
|
|
|
|
def has_visited_user(self, uid):
|
|
return self._users["users"][uid.replace("-", "")]
|
|
|
|
def mark_user_as_visited(self, uid):
|
|
self._users["users"][uid.replace("-", "")] = True
|