From 0585b9e6d56a721cf4eea34e2b12f735638195ba Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 7 Nov 2018 16:09:28 +0100 Subject: [PATCH] Fixed some things Signed-off-by: Thomas Citharel --- js/src/components/NavBar.vue | 15 +++++++-------- js/src/graphql/event.js | 14 +++++++++++--- js/src/graphql/search.js | 2 ++ lib/mobilizon/actors/actors.ex | 2 +- lib/mobilizon_web/resolvers/actor.ex | 10 +++++----- lib/mobilizon_web/resolvers/event.ex | 18 ++++++++++++++++-- lib/service/web_finger/web_finger.ex | 2 +- 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/js/src/components/NavBar.vue b/js/src/components/NavBar.vue index d64bbb02b..9b2741432 100644 --- a/js/src/components/NavBar.vue +++ b/js/src/components/NavBar.vue @@ -22,6 +22,7 @@ class="hidden-sm-and-down" :items="items" :search-input.sync="searchText" + @keyup.enter="enter" v-model="model" return-object > @@ -139,7 +140,7 @@ export default { return this.search.map(searchEntry => { switch (searchEntry.__typename) { case 'Actor': - searchEntry.label = searchEntry.preferredUsername; + searchEntry.label = searchEntry.preferredUsername + (searchEntry.domain === null ? '' : `@${searchEntry.domain}`); break; case 'Event': searchEntry.label = searchEntry.title; @@ -148,17 +149,15 @@ export default { return searchEntry; }); }, - displayed_name() { - console.log('displayed name', this.actor); - if (this.actor) { - return this.actor.display_name === null ? this.actor.username : this.actor.display_name; - } - }, }, methods: { username_with_domain(actor) { - return actor.preferredUsername + (actor.domain === undefined ? '' : `@${actor.domain}`); + return actor.preferredUsername + (actor.domain === null ? '' : `@${actor.domain}`); }, + enter() { + console.log('enter'); + this.$apollo.queries.search.refetch(); + } }, }; diff --git a/js/src/graphql/event.js b/js/src/graphql/event.js index d965da74c..689ce2e33 100644 --- a/js/src/graphql/event.js +++ b/js/src/graphql/event.js @@ -88,9 +88,17 @@ export const CREATE_EVENT = gql` $categoryId: Int!, $beginsOn: DateTime!, $addressType: AddressType!, - ) { - createEvent(title: $title, description: $description, beginsOn: $beginsOn, organizerActorId: $organizerActorId, categoryId: $categoryId, addressType: $addressType) { - uuid + ) { + createEvent( + title: $title, + description: $description, + beginsOn: $beginsOn, + organizerActorId: $organizerActorId, + categoryId: $categoryId, + addressType: $addressType) { + uuid, + title, + description, } } `; diff --git a/js/src/graphql/search.js b/js/src/graphql/search.js index 6d479b919..5182a98ca 100644 --- a/js/src/graphql/search.js +++ b/js/src/graphql/search.js @@ -9,6 +9,8 @@ query SearchEvents($searchText: String!) { __typename }, ...on Actor { + avatarUrl, + domain, preferredUsername, __typename } diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index e1c665643..bb70d770d 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -275,7 +275,7 @@ defmodule Mobilizon.Actors do actor = case String.split(name, "@") do [name] -> - Repo.get_by(Actor, preferred_username: name) + Repo.one(from(a in Actor, where: a.preferred_username == ^name and is_nil(a.domain))) [name, domain] -> Repo.get_by(Actor, preferred_username: name, domain: domain) diff --git a/lib/mobilizon_web/resolvers/actor.ex b/lib/mobilizon_web/resolvers/actor.ex index 5129e911b..6ddf7e7d8 100644 --- a/lib/mobilizon_web/resolvers/actor.ex +++ b/lib/mobilizon_web/resolvers/actor.ex @@ -2,14 +2,14 @@ defmodule MobilizonWeb.Resolvers.Actor do alias Mobilizon.Actors.Actor, as: ActorSchema alias Mobilizon.Actors.User alias Mobilizon.Actors + alias Mobilizon.Service.ActivityPub def find_actor(_parent, %{preferred_username: name}, _resolution) do - case Actors.get_actor_by_name_with_everything(name) do - nil -> - {:error, "Actor with name #{name} not found"} - - actor -> + case ActivityPub.find_or_make_actor_from_nickname(name) do + {:ok, actor} -> {:ok, actor} + _ -> + {:error, "Actor with name #{name} not found"} end end diff --git a/lib/mobilizon_web/resolvers/event.ex b/lib/mobilizon_web/resolvers/event.ex index 09b0e6565..323fcf673 100644 --- a/lib/mobilizon_web/resolvers/event.ex +++ b/lib/mobilizon_web/resolvers/event.ex @@ -1,4 +1,6 @@ defmodule MobilizonWeb.Resolvers.Event do + alias Mobilizon.Service.ActivityPub + def list_events(_parent, _args, _resolution) do {:ok, Mobilizon.Events.list_events()} end @@ -28,9 +30,21 @@ defmodule MobilizonWeb.Resolvers.Event do Search events and actors by title """ def search_events_and_actors(_parent, %{search: search, page: page, limit: limit}, _resolution) do + search = String.strip(search) found = - Mobilizon.Events.find_events_by_name(search, page, limit) ++ - Mobilizon.Actors.find_actors_by_username_or_name(search, page, limit) + case String.contains?(search, "@") do + true -> + with {:ok, actor} <- ActivityPub.find_or_make_actor_from_nickname(search) do + actor + else + {:error, _err} -> + nil + end + + _ -> + Mobilizon.Events.find_events_by_name(search, page, limit) ++ + Mobilizon.Actors.find_actors_by_username_or_name(search, page, limit) + end require Logger Logger.debug(inspect(found)) diff --git a/lib/service/web_finger/web_finger.ex b/lib/service/web_finger/web_finger.ex index 74a0e18b9..deec91813 100644 --- a/lib/service/web_finger/web_finger.ex +++ b/lib/service/web_finger/web_finger.ex @@ -49,7 +49,7 @@ defmodule Mobilizon.Service.WebFinger do def represent_user(user, "JSON") do %{ - "subject" => "acct:#{user.preferred_username}@#{MobilizonWeb.Endpoint.host() <> ":4001"}", + "subject" => "acct:#{user.preferred_username}@#{MobilizonWeb.Endpoint.host()}", "aliases" => [user.url], "links" => [ %{"rel" => "self", "type" => "application/activity+json", "href" => user.url}