parler_feed/state.py
2020-12-27 14:25:27 -05:00

39 lines
1.1 KiB
Python

import os
from hexlib.db import VolatileBooleanState, VolatileState
from items import ParlerItem
REDIS_HOST = os.environ.get("PAF_REDIS_HOST", "localhost")
REDIS_PORT = os.environ.get("PAF_REDIS_PORT", 6379)
class ParlerState:
def __init__(self):
self._visited = VolatileBooleanState("parler", host=REDIS_HOST, port=REDIS_PORT)
self._resume = VolatileState("parler", host=REDIS_HOST, port=REDIS_PORT)
def resume_key(self, endpoint, user_id):
return self._resume[endpoint][user_id]
def set_resume_key(self, endpoint, user_id, key):
if key is None:
del self._resume[endpoint][user_id]
else:
self._resume[endpoint][user_id] = key
def has_visited_post(self, post: ParlerItem):
if post.data["comments"] == "0":
return True
return self._visited["post"][post.item_id()]
def mark_visited_post(self, post_id):
self._visited["post"][post_id] = True
def has_visited_user(self, user_id):
return self._visited["user"][user_id]
def mark_visited_user(self, user_id):
self._visited["user"][user_id] = True