More notification tweaks

This commit is contained in:
Thomas Sileo 2019-07-29 22:46:53 +02:00
parent bf954adaea
commit b00263c817
2 changed files with 23 additions and 6 deletions

View file

@ -1,3 +1,4 @@
from enum import unique
from enum import Enum from enum import Enum
from typing import Any from typing import Any
from typing import Dict from typing import Dict
@ -7,12 +8,14 @@ from little_boxes import activitypub as ap
_SubQuery = Dict[str, Any] _SubQuery = Dict[str, Any]
@unique
class Box(Enum): class Box(Enum):
INBOX = "inbox" INBOX = "inbox"
OUTBOX = "outbox" OUTBOX = "outbox"
REPLIES = "replies" REPLIES = "replies"
@unique
class MetaKey(Enum): class MetaKey(Enum):
NOTIFICATION = "notification" NOTIFICATION = "notification"
NOTIFICATION_UNREAD = "notification_unread" NOTIFICATION_UNREAD = "notification_unread"

View file

@ -26,7 +26,7 @@ def _is_from_outbox(activity: ap.BaseActivity) -> bool:
def _flag_as_notification(activity: ap.BaseActivity, new_meta: _NewMeta) -> None: def _flag_as_notification(activity: ap.BaseActivity, new_meta: _NewMeta) -> None:
new_meta.update( new_meta.update(
**{_meta(MetaKey.NOTIFICATION): True, _meta(MetaKey.NOTIFICATION_UNREAD): True} {_meta(MetaKey.NOTIFICATION): True, _meta(MetaKey.NOTIFICATION_UNREAD): True}
) )
return None 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 # This Accept will be a "You started following $actor" notification
_flag_as_notification(activity, new_meta) _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 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 # This Follow will be a "$actor started following you" notification
_flag_as_notification(activity, new_meta) _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 return None
@ -98,7 +98,7 @@ def _like_set_inbox_flags(activity: ap.Like, new_meta: _NewMeta) -> None:
Tasks.cache_object(activity.id) Tasks.cache_object(activity.id)
# Also set the "keep mark" for the GC (as we want to keep it forever) # 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 return None
@ -111,9 +111,23 @@ def _announce_set_inbox_flags(activity: ap.Announce, new_meta: _NewMeta) -> None
_flag_as_notification(activity, new_meta) _flag_as_notification(activity, new_meta)
# Also set the "keep mark" for the GC (as we want to keep it forever) # 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) Tasks.cache_object(activity.id)
return None 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