1
0
Fork 0
forked from mirrors/akkoma

Add activity_type to twitter api output.

This commit is contained in:
Roger Braun 2017-08-24 16:18:26 +02:00
parent d95b78c72f
commit 5dc278b1a6
2 changed files with 15 additions and 6 deletions

View file

@ -29,7 +29,8 @@ def to_map(%Activity{data: %{"type" => "Announce", "actor" => actor, "published"
"created_at" => created_at, "created_at" => created_at,
"retweeted_status" => retweeted_status, "retweeted_status" => retweeted_status,
"statusnet_conversation_id" => conversation_id(announced_activity), "statusnet_conversation_id" => conversation_id(announced_activity),
"external_url" => activity.data["id"] "external_url" => activity.data["id"],
"activity_type" => "repeat"
} }
end end
@ -49,7 +50,8 @@ def to_map(%Activity{data: %{"type" => "Like", "published" => created_at}} = act
"uri" => "tag:#{activity.data["id"]}:objectType=Favourite", "uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
"created_at" => created_at, "created_at" => created_at,
"in_reply_to_status_id" => liked_activity.id, "in_reply_to_status_id" => liked_activity.id,
"external_url" => activity.data["id"] "external_url" => activity.data["id"],
"activity_type" => "like"
} }
end end
@ -68,7 +70,8 @@ def to_map(%Activity{data: %{"type" => "Follow", "published" => created_at, "obj
"is_post_verb" => false, "is_post_verb" => false,
"created_at" => created_at, "created_at" => created_at,
"in_reply_to_status_id" => nil, "in_reply_to_status_id" => nil,
"external_url" => activity.data["id"] "external_url" => activity.data["id"],
"activity_type" => "follow"
} }
end end
@ -88,7 +91,8 @@ def to_map(%Activity{data: %{"type" => "Undo", "published" => created_at, "objec
"is_post_verb" => false, "is_post_verb" => false,
"created_at" => created_at, "created_at" => created_at,
"in_reply_to_status_id" => nil, "in_reply_to_status_id" => nil,
"external_url" => activity.data["id"] "external_url" => activity.data["id"],
"activity_type" => "undo"
} }
end end
@ -125,7 +129,8 @@ def to_map(%Activity{data: %{"object" => %{"content" => content} = object}} = ac
"favorited" => to_boolean(favorited), "favorited" => to_boolean(favorited),
"repeated" => to_boolean(repeated), "repeated" => to_boolean(repeated),
"external_url" => object["external_url"], "external_url" => object["external_url"],
"tags" => activity.data["object"]["tag"] || [] "tags" => activity.data["object"]["tag"] || [],
"activity_type" => "post"
} }
end end

View file

@ -27,6 +27,7 @@ test "an announce activity" do
assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"] assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
assert status["retweeted_status"] == retweeted_status assert status["retweeted_status"] == retweeted_status
assert status["activity_type"] == "repeat"
end end
test "a like activity" do test "a like activity" do
@ -44,6 +45,7 @@ test "a like activity" do
activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"]) activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user}) liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
assert liked_status["favorited"] == true assert liked_status["favorited"] == true
assert status["activity_type"] == "like"
end end
test "an activity" do test "an activity" do
@ -127,7 +129,8 @@ test "an activity" do
"favorited" => false, "favorited" => false,
"repeated" => false, "repeated" => false,
"external_url" => "some url", "external_url" => "some url",
"tags" => ["content", "mentioning", "nsfw"] "tags" => ["content", "mentioning", "nsfw"],
"activity_type" => "post"
} }
assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
@ -142,5 +145,6 @@ test "an undo for a follow" do
map = ActivityRepresenter.to_map(unfollow, %{user: follower}) map = ActivityRepresenter.to_map(unfollow, %{user: follower})
assert map["is_post_verb"] == false assert map["is_post_verb"] == false
assert map["activity_type"] == "undo"
end end
end end