Fixed some things

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-11-07 16:09:28 +01:00
parent 74bc21fa2c
commit 0585b9e6d5
7 changed files with 43 additions and 20 deletions

View file

@ -22,6 +22,7 @@
class="hidden-sm-and-down" class="hidden-sm-and-down"
:items="items" :items="items"
:search-input.sync="searchText" :search-input.sync="searchText"
@keyup.enter="enter"
v-model="model" v-model="model"
return-object return-object
> >
@ -139,7 +140,7 @@ export default {
return this.search.map(searchEntry => { return this.search.map(searchEntry => {
switch (searchEntry.__typename) { switch (searchEntry.__typename) {
case 'Actor': case 'Actor':
searchEntry.label = searchEntry.preferredUsername; searchEntry.label = searchEntry.preferredUsername + (searchEntry.domain === null ? '' : `@${searchEntry.domain}`);
break; break;
case 'Event': case 'Event':
searchEntry.label = searchEntry.title; searchEntry.label = searchEntry.title;
@ -148,17 +149,15 @@ export default {
return searchEntry; 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: { methods: {
username_with_domain(actor) { 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();
}
}, },
}; };
</script> </script>

View file

@ -88,9 +88,17 @@ export const CREATE_EVENT = gql`
$categoryId: Int!, $categoryId: Int!,
$beginsOn: DateTime!, $beginsOn: DateTime!,
$addressType: AddressType!, $addressType: AddressType!,
) { ) {
createEvent(title: $title, description: $description, beginsOn: $beginsOn, organizerActorId: $organizerActorId, categoryId: $categoryId, addressType: $addressType) { createEvent(
uuid title: $title,
description: $description,
beginsOn: $beginsOn,
organizerActorId: $organizerActorId,
categoryId: $categoryId,
addressType: $addressType) {
uuid,
title,
description,
} }
} }
`; `;

View file

@ -9,6 +9,8 @@ query SearchEvents($searchText: String!) {
__typename __typename
}, },
...on Actor { ...on Actor {
avatarUrl,
domain,
preferredUsername, preferredUsername,
__typename __typename
} }

View file

@ -275,7 +275,7 @@ defmodule Mobilizon.Actors do
actor = actor =
case String.split(name, "@") do case String.split(name, "@") do
[name] -> [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] -> [name, domain] ->
Repo.get_by(Actor, preferred_username: name, domain: domain) Repo.get_by(Actor, preferred_username: name, domain: domain)

View file

@ -2,14 +2,14 @@ defmodule MobilizonWeb.Resolvers.Actor do
alias Mobilizon.Actors.Actor, as: ActorSchema alias Mobilizon.Actors.Actor, as: ActorSchema
alias Mobilizon.Actors.User alias Mobilizon.Actors.User
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Service.ActivityPub
def find_actor(_parent, %{preferred_username: name}, _resolution) do def find_actor(_parent, %{preferred_username: name}, _resolution) do
case Actors.get_actor_by_name_with_everything(name) do case ActivityPub.find_or_make_actor_from_nickname(name) do
nil -> {:ok, actor} ->
{:error, "Actor with name #{name} not found"}
actor ->
{:ok, actor} {:ok, actor}
_ ->
{:error, "Actor with name #{name} not found"}
end end
end end

View file

@ -1,4 +1,6 @@
defmodule MobilizonWeb.Resolvers.Event do defmodule MobilizonWeb.Resolvers.Event do
alias Mobilizon.Service.ActivityPub
def list_events(_parent, _args, _resolution) do def list_events(_parent, _args, _resolution) do
{:ok, Mobilizon.Events.list_events()} {:ok, Mobilizon.Events.list_events()}
end end
@ -28,9 +30,21 @@ defmodule MobilizonWeb.Resolvers.Event do
Search events and actors by title Search events and actors by title
""" """
def search_events_and_actors(_parent, %{search: search, page: page, limit: limit}, _resolution) do def search_events_and_actors(_parent, %{search: search, page: page, limit: limit}, _resolution) do
search = String.strip(search)
found = found =
Mobilizon.Events.find_events_by_name(search, page, limit) ++ case String.contains?(search, "@") do
Mobilizon.Actors.find_actors_by_username_or_name(search, page, limit) 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 require Logger
Logger.debug(inspect(found)) Logger.debug(inspect(found))

View file

@ -49,7 +49,7 @@ defmodule Mobilizon.Service.WebFinger do
def represent_user(user, "JSON") 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], "aliases" => [user.url],
"links" => [ "links" => [
%{"rel" => "self", "type" => "application/activity+json", "href" => user.url} %{"rel" => "self", "type" => "application/activity+json", "href" => user.url}