mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-14 18:54:27 +00:00
More notification tweaks
This commit is contained in:
parent
bf954adaea
commit
b00263c817
2 changed files with 23 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
|||
from enum import unique
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
|
@ -7,12 +8,14 @@ from little_boxes import activitypub as ap
|
|||
_SubQuery = Dict[str, Any]
|
||||
|
||||
|
||||
@unique
|
||||
class Box(Enum):
|
||||
INBOX = "inbox"
|
||||
OUTBOX = "outbox"
|
||||
REPLIES = "replies"
|
||||
|
||||
|
||||
@unique
|
||||
class MetaKey(Enum):
|
||||
NOTIFICATION = "notification"
|
||||
NOTIFICATION_UNREAD = "notification_unread"
|
||||
|
|
|
@ -26,7 +26,7 @@ def _is_from_outbox(activity: ap.BaseActivity) -> bool:
|
|||
|
||||
def _flag_as_notification(activity: ap.BaseActivity, new_meta: _NewMeta) -> None:
|
||||
new_meta.update(
|
||||
**{_meta(MetaKey.NOTIFICATION): True, _meta(MetaKey.NOTIFICATION_UNREAD): True}
|
||||
{_meta(MetaKey.NOTIFICATION): True, _meta(MetaKey.NOTIFICATION_UNREAD): True}
|
||||
)
|
||||
return None
|
||||
|
||||
|
@ -58,7 +58,7 @@ def _accept_set_inbox_flags(activity: ap.Accept, new_meta: _NewMeta) -> None:
|
|||
|
||||
# This Accept will be a "You started following $actor" notification
|
||||
_flag_as_notification(activity, new_meta)
|
||||
new_meta.update(**{_meta(MetaKey.NOTIFICATION_FOLLOWS_BACK): follows_back})
|
||||
new_meta.update({_meta(MetaKey.NOTIFICATION_FOLLOWS_BACK): follows_back})
|
||||
return None
|
||||
|
||||
|
||||
|
@ -83,7 +83,7 @@ def _follow_set_inbox_flags(activity: ap.Follow, new_meta: _NewMeta) -> None:
|
|||
|
||||
# This Follow will be a "$actor started following you" notification
|
||||
_flag_as_notification(activity, new_meta)
|
||||
new_meta.update(**{_meta(MetaKey.NOTIFICATION_FOLLOWS_BACK): follows_back})
|
||||
new_meta.update({_meta(MetaKey.NOTIFICATION_FOLLOWS_BACK): follows_back})
|
||||
return None
|
||||
|
||||
|
||||
|
@ -98,7 +98,7 @@ def _like_set_inbox_flags(activity: ap.Like, new_meta: _NewMeta) -> None:
|
|||
Tasks.cache_object(activity.id)
|
||||
|
||||
# Also set the "keep mark" for the GC (as we want to keep it forever)
|
||||
new_meta.update(**{_meta(MetaKey.GC_KEEP): True})
|
||||
new_meta.update({_meta(MetaKey.GC_KEEP): True})
|
||||
|
||||
return None
|
||||
|
||||
|
@ -111,9 +111,23 @@ def _announce_set_inbox_flags(activity: ap.Announce, new_meta: _NewMeta) -> None
|
|||
_flag_as_notification(activity, new_meta)
|
||||
|
||||
# Also set the "keep mark" for the GC (as we want to keep it forever)
|
||||
new_meta.update(**{_meta(MetaKey.GC_KEEP): True})
|
||||
new_meta.update({_meta(MetaKey.GC_KEEP): True})
|
||||
|
||||
# Cache the object in all case (for display on the notifcation page)
|
||||
# Cache the object in all case (for display on the notifcation page **and** the stream page)
|
||||
Tasks.cache_object(activity.id)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@set_inbox_flags.register
|
||||
def _undo_set_inbox_flags(activity: ap.Undo, new_meta: _NewMeta) -> None:
|
||||
obj = activity.get_object()
|
||||
|
||||
if obj.has_type(ap.ActivityType.FOLLOW):
|
||||
# Flag it as a noticiation (for the "$actor unfollowed you"
|
||||
_flag_as_notification(activity, new_meta)
|
||||
|
||||
# Also set the "keep mark" for the GC (as we want to keep it forever)
|
||||
new_meta.update({_meta(MetaKey.GC_KEEP): True})
|
||||
|
||||
return None
|
||||
|
|
Loading…
Reference in a new issue