{:ok, Repo.all(q)}
end
+ def increase_note_count(%User{} = user) do
+ note_count = (user.info["note_count"] || 0) + 1
+ new_info = Map.put(user.info, "note_count", note_count)
+
+ cs = info_changeset(user, %{info: new_info})
+
+ Repo.update(cs)
+ end
+
def update_note_count(%User{} = user) do
note_count_query = from a in Object,
where: fragment("?->>'actor' = ? and ?->>'type' = 'Note'", a.data, ^user.ap_id, a.data),
context <- make_context(inReplyTo),
object <- make_note_data(user.ap_id, to, context, content_html, attachments, inReplyTo, tags) do
res = ActivityPub.create(to, user, context, object)
- User.update_note_count(user)
+ User.increase_note_count(user)
res
end
end
note <- (if inReplyTo && !inReplyToActivity, do: note |> Map.put("inReplyTo", inReplyTo), else: note)
do
res = ActivityPub.create(to, actor, context, note, %{}, date, false)
- User.update_note_count(actor)
+ User.increase_note_count(actor)
res
else
%Activity{} = activity -> {:ok, activity}
assert user.info["note_count"] == 1
end
+ test "it increases the info->note_count property" do
+ note = insert(:note)
+ user = User.get_by_ap_id(note.data["actor"])
+
+ assert user.info["note_count"] == nil
+
+ {:ok, user} = User.increase_note_count(user)
+
+ assert user.info["note_count"] == 1
+
+ {:ok, user} = User.increase_note_count(user)
+
+ assert user.info["note_count"] == 2
+ end
+
test "it sets the info->follower_count property" do
user = insert(:user)
follower = insert(:user)