Bootstrap EmojiReaction support
This commit is contained in:
@@ -26,8 +26,8 @@ def find_activities(q: _Q) -> Iterable[_D]:
|
||||
return DB[CollectionName.ACTIVITIES.value].find(q)
|
||||
|
||||
|
||||
def update_one_activity(q: _Q, update: _Q) -> None:
|
||||
DB[CollectionName.ACTIVITIES.value].update_one(q, update)
|
||||
def update_one_activity(q: _Q, update: _Q) -> bool:
|
||||
return DB[CollectionName.ACTIVITIES.value].update_one(q, update).matched_count == 1
|
||||
|
||||
|
||||
def update_many_activities(q: _Q, update: _Q) -> None:
|
||||
|
@@ -174,6 +174,23 @@ def _like_process_inbox(like: ap.Like, new_meta: _NewMeta) -> None:
|
||||
)
|
||||
|
||||
|
||||
@process_inbox.register
|
||||
def _emoji_reaction_process_inbox(emoji_reaction: ap.EmojiReaction, new_meta: _NewMeta) -> None:
|
||||
_logger.info(f"process_inbox activity={emoji_reaction!r}")
|
||||
obj = emoji_reaction.get_object()
|
||||
# Try to update an existing emoji reaction counter entry for the activity emoji
|
||||
if not update_one_activity(
|
||||
{**by_type(ap.ActivityType.CREATE), **by_object_id(obj.id),
|
||||
"meta.emoji_reactions.emoji": emoji_reaction.content},
|
||||
{"$inc": {"meta.emoji_reactions.$.count": 1}},
|
||||
):
|
||||
# Bootstrap the current emoji counter
|
||||
update_one_activity(
|
||||
{**by_type(ap.ActivityType.CREATE), **by_object_id(obj.id)},
|
||||
{"$push": {"meta.emoji_reactions": {"emoji": emoji_reaction.content, "count": 1}}},
|
||||
)
|
||||
|
||||
|
||||
@process_inbox.register
|
||||
def _follow_process_inbox(activity: ap.Follow, new_meta: _NewMeta) -> None:
|
||||
_logger.info(f"process_inbox activity={activity!r}")
|
||||
|
@@ -70,6 +70,8 @@ class MetaKey(Enum):
|
||||
COUNT_BOOST = "count_boost"
|
||||
COUNT_REPLY = "count_reply"
|
||||
|
||||
EMOJI_REACTIONS = "emoji_reactions"
|
||||
|
||||
|
||||
def _meta(mk: MetaKey) -> str:
|
||||
return f"meta.{mk.value}"
|
||||
|
Reference in New Issue
Block a user