Rename Thread.last_message_timestamp to .last_active, and use datetimes
This commit is contained in:
@@ -319,9 +319,7 @@ class Client:
|
|||||||
else: # End of threads
|
else: # End of threads
|
||||||
break
|
break
|
||||||
|
|
||||||
last_thread_dt = _util.millis_to_datetime(
|
last_thread_dt = threads[-1].last_active
|
||||||
threads[-1].last_message_timestamp
|
|
||||||
)
|
|
||||||
|
|
||||||
# FB returns a sorted list of threads
|
# FB returns a sorted list of threads
|
||||||
if (before is not None and last_thread_dt > before) or (
|
if (before is not None and last_thread_dt > before) or (
|
||||||
@@ -332,9 +330,8 @@ class Client:
|
|||||||
# Return only threads between before and after (if set)
|
# Return only threads between before and after (if set)
|
||||||
if before is not None or after is not None:
|
if before is not None or after is not None:
|
||||||
for t in threads:
|
for t in threads:
|
||||||
last_message_dt = _util.millis_to_datetime(t.last_message_timestamp)
|
if (before is not None and t.last_active > before) or (
|
||||||
if (before is not None and last_message_dt > before) or (
|
after is not None and t.last_active < after
|
||||||
after is not None and last_message_dt < after
|
|
||||||
):
|
):
|
||||||
threads.remove(t)
|
threads.remove(t)
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import attr
|
import attr
|
||||||
from . import _plan
|
from . import _util, _plan
|
||||||
from ._thread import ThreadType, Thread
|
from ._thread import ThreadType, Thread
|
||||||
|
|
||||||
|
|
||||||
@@ -63,11 +63,11 @@ class Group(Thread):
|
|||||||
if data.get("image") is None:
|
if data.get("image") is None:
|
||||||
data["image"] = {}
|
data["image"] = {}
|
||||||
c_info = cls._parse_customization_info(data)
|
c_info = cls._parse_customization_info(data)
|
||||||
last_message_timestamp = None
|
last_active = None
|
||||||
if "last_message" in data:
|
if "last_message" in data:
|
||||||
last_message_timestamp = data["last_message"]["nodes"][0][
|
last_active = _util.millis_to_datetime(
|
||||||
"timestamp_precise"
|
int(data["last_message"]["nodes"][0]["timestamp_precise"])
|
||||||
]
|
)
|
||||||
plan = None
|
plan = None
|
||||||
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
||||||
plan = _plan.Plan._from_graphql(data["event_reminders"]["nodes"][0])
|
plan = _plan.Plan._from_graphql(data["event_reminders"]["nodes"][0])
|
||||||
@@ -97,7 +97,7 @@ class Group(Thread):
|
|||||||
photo=data["image"].get("uri"),
|
photo=data["image"].get("uri"),
|
||||||
name=data.get("name"),
|
name=data.get("name"),
|
||||||
message_count=data.get("messages_count"),
|
message_count=data.get("messages_count"),
|
||||||
last_message_timestamp=last_message_timestamp,
|
last_active=last_active,
|
||||||
plan=plan,
|
plan=plan,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -81,8 +81,8 @@ class Thread:
|
|||||||
photo = attr.ib(None)
|
photo = attr.ib(None)
|
||||||
#: The name of the thread
|
#: The name of the thread
|
||||||
name = attr.ib(None)
|
name = attr.ib(None)
|
||||||
#: Timestamp of last message
|
#: Datetime when the thread was last active / when the last message was sent
|
||||||
last_message_timestamp = attr.ib(None)
|
last_active = attr.ib(None)
|
||||||
#: Number of messages in the thread
|
#: Number of messages in the thread
|
||||||
message_count = attr.ib(None)
|
message_count = attr.ib(None)
|
||||||
#: Set :class:`Plan`
|
#: Set :class:`Plan`
|
||||||
@@ -94,7 +94,7 @@ class Thread:
|
|||||||
uid,
|
uid,
|
||||||
photo=None,
|
photo=None,
|
||||||
name=None,
|
name=None,
|
||||||
last_message_timestamp=None,
|
last_active=None,
|
||||||
message_count=None,
|
message_count=None,
|
||||||
plan=None,
|
plan=None,
|
||||||
):
|
):
|
||||||
@@ -102,7 +102,7 @@ class Thread:
|
|||||||
self.type = _type
|
self.type = _type
|
||||||
self.photo = photo
|
self.photo = photo
|
||||||
self.name = name
|
self.name = name
|
||||||
self.last_message_timestamp = last_message_timestamp
|
self.last_active = last_active
|
||||||
self.message_count = message_count
|
self.message_count = message_count
|
||||||
self.plan = plan
|
self.plan = plan
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._core import Enum
|
from ._core import Enum
|
||||||
from . import _plan
|
from . import _util, _plan
|
||||||
from ._thread import ThreadType, Thread
|
from ._thread import ThreadType, Thread
|
||||||
|
|
||||||
|
|
||||||
@@ -131,11 +131,11 @@ class User(Thread):
|
|||||||
user = next(
|
user = next(
|
||||||
p for p in participants if p["id"] == data["thread_key"]["other_user_id"]
|
p for p in participants if p["id"] == data["thread_key"]["other_user_id"]
|
||||||
)
|
)
|
||||||
last_message_timestamp = None
|
last_active = None
|
||||||
if "last_message" in data:
|
if "last_message" in data:
|
||||||
last_message_timestamp = data["last_message"]["nodes"][0][
|
last_active = _util.millis_to_datetime(
|
||||||
"timestamp_precise"
|
int(data["last_message"]["nodes"][0]["timestamp_precise"])
|
||||||
]
|
)
|
||||||
|
|
||||||
first_name = user.get("short_name")
|
first_name = user.get("short_name")
|
||||||
if first_name is None:
|
if first_name is None:
|
||||||
@@ -162,7 +162,7 @@ class User(Thread):
|
|||||||
own_nickname=c_info.get("own_nickname"),
|
own_nickname=c_info.get("own_nickname"),
|
||||||
photo=user["big_image_src"].get("uri"),
|
photo=user["big_image_src"].get("uri"),
|
||||||
message_count=data.get("messages_count"),
|
message_count=data.get("messages_count"),
|
||||||
last_message_timestamp=last_message_timestamp,
|
last_active=last_active,
|
||||||
plan=plan,
|
plan=plan,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user