Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/915
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Apr 22, 2024
1 parent 3241f28 commit 1305453
Showing 1 changed file with 67 additions and 22 deletions.
89 changes: 67 additions & 22 deletions lib/social_api_graphql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ if Application.compile_env(:bonfire_api_graphql, :modularity) != :disabled and
defmodule Bonfire.Social.API.GraphQL do
use Absinthe.Schema.Notation
use Absinthe.Relay.Schema.Notation, :modern

use Bonfire.Common.Utils
import Bonfire.Social.Integration
import Untangle

alias Absinthe.Resolution.Helpers
alias Bonfire.API.GraphQL.Pagination

alias Bonfire.API.GraphQL
alias Bonfire.Common.Utils
alias Bonfire.Common.Types
alias Bonfire.Social.Activities

Expand All @@ -33,6 +32,7 @@ if Application.compile_env(:bonfire_api_graphql, :modularity) != :disabled and
%{verb: verb}, _, _ ->
{:ok,
verb
|> debug()
|> Activities.verb_maybe_modify()
|> Activities.verb_display()}
end)
Expand Down Expand Up @@ -71,7 +71,11 @@ if Application.compile_env(:bonfire_api_graphql, :modularity) != :disabled and
%{verb_id: verb}, _, _ ->
{:ok, %{verb: verb}}

_, _, _ ->
%{verb: %{verb: verb}}, _, _ ->
{:ok, %{verb: verb}}

other, _, _ ->
warn(other, "not verb detected")
{:ok, nil}
end)
end
Expand All @@ -91,15 +95,17 @@ if Application.compile_env(:bonfire_api_graphql, :modularity) != :disabled and
field(:object_post_content, :post_content) do
resolve(fn
%{object: %{post_content: %{id: _} = post_content}}, _, _ ->
{:ok, post_content}
{:ok, post_content |> debug("post_content detected")}

%{object: %Bonfire.Data.Social.Post{} = post}, _, _ ->
%{object: %{post_content: _} = object}, _, _ ->
{:ok,
post
object
|> repo().maybe_preload(:post_content)
|> Map.get(:post_content)}
|> e(:post_content, nil)
|> debug("post_content detected")}

_, _, _ ->
activity, _, _ ->
warn(activity, "no post_content detected")
{:ok, nil}
end)
end
Expand All @@ -113,6 +119,8 @@ if Application.compile_env(:bonfire_api_graphql, :modularity) != :disabled and
end
end

connection(node_type: :activity)

object :post_content do
field(:name, :string)
field(:summary, :string)
Expand Down Expand Up @@ -156,6 +164,7 @@ if Application.compile_env(:bonfire_api_graphql, :modularity) != :disabled and
end

input_object :feed_filters do
# TODO: other filters?
field(:feed_name, :string)
end

Expand Down Expand Up @@ -186,11 +195,13 @@ if Application.compile_env(:bonfire_api_graphql, :modularity) != :disabled and
end

@desc "Get activities in a feed"
field :feed, list_of(:activity) do
# field :feed, list_of(:activity) do
# arg(:filter, :feed_filters)
# arg(:paginate, :paginate)
# resolve(&feed/2)
# end
connection field :feed, node_type: :activity do
arg(:filter, :feed_filters)
# TODO
arg(:paginate, :paginate)

resolve(&feed/2)
end
end
Expand Down Expand Up @@ -267,21 +278,55 @@ if Application.compile_env(:bonfire_api_graphql, :modularity) != :disabled and
{:ok, Activities.object_from_activity(activity)}
end

defp feed(args, info) do
user = GraphQL.current_user(info)
debug(args)
# defp feed(args, info) do
# user = GraphQL.current_user(info)
# debug(args)

# Bonfire.Social.FeedActivities.feed(
# Types.maybe_to_atom(Utils.e(args, :filter, :feed_name, :local)),
# current_user: user,
# paginate: Utils.e(args, :paginate, nil)
# )
# |> feed()
# end
# defp feed(%{edges: feed}) when is_list(feed) do
# {:ok, Enum.map(feed, &Map.get(&1, :activity))}
# end

def feed(feed_name \\ nil, args, info) do
{pagination_args, filters} =
Pagination.pagination_args_filter(args)
|> debug()

Bonfire.Social.FeedActivities.feed(
Types.maybe_to_atom(Utils.e(args, :filter, :feed_name, :local)),
current_user: user,
paginate: Utils.e(args, :paginate, nil)
feed_name || Types.maybe_to_atom(Utils.e(filters, :filter, :feed_name, :local)),
current_user: GraphQL.current_user(info),
pagination: pagination_args
)
|> Pagination.connection_paginate(pagination_args,
item_prepare_fun: fn fp -> e(fp, :activity, nil) || fp end
)
|> feed()
end

defp feed(%{edges: feed}) when is_list(feed) do
{:ok, Enum.map(feed, &Map.get(&1, :activity))}
end
# defp my_feed(%{} = parent, _args, _info) do
# Bonfire.Social.FeedActivities.my_feed(parent)
# |> feed()
# end

# defp my_notifications(%User{} = user, _args, _info) do
# Bonfire.Social.FeedActivities.feed(:notifications, user)
# |> feed()
# end

# defp all_flags(%{} = user_or_account, _args, _info) do
# Bonfire.Social.Flags.list(user_or_account)
# |> feed()
# end

# defp feed(%{edges: feed}) when is_list(feed) do
# {:ok, Enum.map(feed, &Map.get(&1, :activity))}
# end
# defp feed(_), do: {:ok, nil}

defp create_post(args, info) do
user = GraphQL.current_user(info)
Expand Down

0 comments on commit 1305453

Please sign in to comment.