Assorted fixes.

This commit is contained in:
lain 2018-11-30 17:08:02 +01:00
parent d407f662af
commit 48b95a9b95
5 changed files with 19 additions and 15 deletions

View File

@ -20,6 +20,8 @@ defmodule Pleroma.User.Info do
field(:settings, :map, default: nil) field(:settings, :map, default: nil)
field(:magic_key, :string, default: nil) field(:magic_key, :string, default: nil)
field(:uri, :string, default: nil) field(:uri, :string, default: nil)
field(:topic, :string, default: nil)
field(:hub, :string, default: nil)
# topic, subject, salmon, subscribe_address, uri # topic, subject, salmon, subscribe_address, uri
end end
@ -99,7 +101,9 @@ def remote_user_creation(info, params) do
:banner, :banner,
:locked, :locked,
:magic_key, :magic_key,
:uri :uri,
:hub,
:topic
]) ])
end end

View File

@ -146,7 +146,7 @@ defp valid_topic(%{"hub.topic" => topic}, user) do
end end
def subscribe(subscriber, subscribed, requester \\ &request_subscription/1) do def subscribe(subscriber, subscribed, requester \\ &request_subscription/1) do
topic = subscribed.info["topic"] topic = subscribed.info.topic
# FIXME: Race condition, use transactions # FIXME: Race condition, use transactions
{:ok, subscription} = {:ok, subscription} =
with subscription when not is_nil(subscription) <- with subscription when not is_nil(subscription) <-
@ -158,7 +158,7 @@ def subscribe(subscriber, subscribed, requester \\ &request_subscription/1) do
_e -> _e ->
subscription = %WebsubClientSubscription{ subscription = %WebsubClientSubscription{
topic: topic, topic: topic,
hub: subscribed.info["hub"], hub: subscribed.info.hub,
subscribers: [subscriber.ap_id], subscribers: [subscriber.ap_id],
state: "requested", state: "requested",
secret: :crypto.strong_rand_bytes(8) |> Base.url_encode64(), secret: :crypto.strong_rand_bytes(8) |> Base.url_encode64(),

View File

@ -447,7 +447,7 @@ test "it works for atom notes, too" do
end end
end end
test "it doesn't add nil in the do field" do test "it doesn't add nil in the to field" do
incoming = File.read!("test/fixtures/nil_mention_entry.xml") incoming = File.read!("test/fixtures/nil_mention_entry.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming) {:ok, [activity]} = OStatus.handle_incoming(incoming)

View File

@ -31,10 +31,10 @@ test "A user with emoji in username", %{user: user} do
expected = expected =
"<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man" "<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
user = %{ user =
user insert(:user, %{
| info: %{ info: %{
"source_data" => %{ source_data: %{
"tag" => [ "tag" => [
%{ %{
"type" => "Emoji", "type" => "Emoji",
@ -43,10 +43,10 @@ test "A user with emoji in username", %{user: user} do
} }
] ]
} }
} },
} name: ":karjalanpiirakka: man"
})
user = %{user | name: ":karjalanpiirakka: man"}
represented = UserView.render("show.json", %{user: user}) represented = UserView.render("show.json", %{user: user})
assert represented["name_html"] == expected assert represented["name_html"] == expected
end end
@ -103,7 +103,7 @@ test "A user" do
end end
test "A user for a given other follower", %{user: user} do test "A user for a given other follower", %{user: user} do
{:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]}) follower = insert(:user, %{following: [User.ap_followers(user)]})
{:ok, user} = User.update_follower_count(user) {:ok, user} = User.update_follower_count(user)
image = "http://localhost:4001/images/avi.png" image = "http://localhost:4001/images/avi.png"
banner = "http://localhost:4001/images/banner.png" banner = "http://localhost:4001/images/banner.png"
@ -186,7 +186,7 @@ test "A user that follows you", %{user: user} do
end end
test "a user that is a moderator" do test "a user that is a moderator" do
user = insert(:user, %{info: %{"is_moderator" => true}}) user = insert(:user, %{info: %{is_moderator: true}})
represented = UserView.render("show.json", %{user: user, for: user}) represented = UserView.render("show.json", %{user: user, for: user})
assert represented["rights"]["delete_others_notice"] assert represented["rights"]["delete_others_notice"]
@ -250,7 +250,7 @@ test "a user with mastodon fields" do
user = user =
insert(:user, %{ insert(:user, %{
info: %{ info: %{
"source_data" => %{ source_data: %{
"attachment" => "attachment" =>
Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end) Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end)
} }

View File

@ -99,7 +99,7 @@ def accepting_verifier(subscription) do
test "initiate a subscription for a given user and topic" do test "initiate a subscription for a given user and topic" do
subscriber = insert(:user) subscriber = insert(:user)
user = insert(:user, %{info: %{"topic" => "some_topic", "hub" => "some_hub"}}) user = insert(:user, %{info: %Pleroma.User.Info{topic: "some_topic", hub: "some_hub"}})
{:ok, websub} = Websub.subscribe(subscriber, user, &accepting_verifier/1) {:ok, websub} = Websub.subscribe(subscriber, user, &accepting_verifier/1)
assert websub.subscribers == [subscriber.ap_id] assert websub.subscribers == [subscriber.ap_id]