Clean up event parsing
This commit is contained in:
@@ -24,8 +24,7 @@ class Typing(ThreadEvent):
|
|||||||
return cls(author=author, thread=author, status=status)
|
return cls(author=author, thread=author, status=status)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse_thread_typing(cls, session, data):
|
||||||
# TODO: Rename this method
|
|
||||||
author = _threads.User(session=session, id=str(data["sender_fbid"]))
|
author = _threads.User(session=session, id=str(data["sender_fbid"]))
|
||||||
thread = _threads.Group(session=session, id=str(data["thread"]))
|
thread = _threads.Group(session=session, id=str(data["thread"]))
|
||||||
status = data["state"] == 1
|
status = data["state"] == 1
|
||||||
@@ -90,7 +89,7 @@ def parse_events(session, topic, data):
|
|||||||
) from e
|
) from e
|
||||||
|
|
||||||
elif topic == "/thread_typing":
|
elif topic == "/thread_typing":
|
||||||
yield Typing._parse(session, data)
|
yield Typing._parse_thread_typing(session, data)
|
||||||
|
|
||||||
elif topic == "/orca_typing_notifications":
|
elif topic == "/orca_typing_notifications":
|
||||||
yield Typing._parse_orca(session, data)
|
yield Typing._parse_orca(session, data)
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import attr
|
import attr
|
||||||
import abc
|
|
||||||
from .._common import kw_only
|
from .._common import kw_only
|
||||||
from .. import _exception, _util, _threads
|
from .. import _exception, _util, _threads
|
||||||
|
|
||||||
@@ -10,14 +9,9 @@ attrs_event = attr.s(slots=True, kw_only=kw_only, frozen=True)
|
|||||||
|
|
||||||
|
|
||||||
@attrs_event
|
@attrs_event
|
||||||
class Event(metaclass=abc.ABCMeta):
|
class Event:
|
||||||
"""Base class for all events."""
|
"""Base class for all events."""
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@abc.abstractmethod
|
|
||||||
def _parse(cls, session, data):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_thread(session, data):
|
def _get_thread(session, data):
|
||||||
# TODO: Handle pages? Is it even possible?
|
# TODO: Handle pages? Is it even possible?
|
||||||
@@ -60,3 +54,9 @@ class ThreadEvent(Event):
|
|||||||
thread = cls._get_thread(session, metadata)
|
thread = cls._get_thread(session, metadata)
|
||||||
at = _util.millis_to_datetime(int(metadata["timestamp"]))
|
at = _util.millis_to_datetime(int(metadata["timestamp"]))
|
||||||
return author, thread, at
|
return author, thread, at
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _parse_fetch(cls, session, data):
|
||||||
|
author = _threads.User(session=session, id=data["message_sender"]["id"])
|
||||||
|
at = _util.millis_to_datetime(int(data["timestamp_precise"]))
|
||||||
|
return author, at
|
||||||
|
Reference in New Issue
Block a user