Skip to content
Permalink
Browse files

Bootstrap EmojiReaction support

  • Loading branch information
tsileo committed Jan 26, 2020
1 parent c0c1a55 commit f2f541c15c40165ce2b6511aaacd57d75ab39a3b
Showing with 21 additions and 2 deletions.
  1. +2 −2 core/db.py
  2. +17 −0 core/inbox.py
  3. +2 −0 core/meta.py
@@ -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}"

0 comments on commit f2f541c

Please sign in to comment.
You can’t perform that action at this time.