Skip to content

Commit 2221938

Browse files
committed
iterate
1 parent f042f41 commit 2221938

File tree

12 files changed

+116
-8
lines changed

12 files changed

+116
-8
lines changed

apps/cf_graphql/lib/resolvers/comments.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,19 @@ defmodule CF.Graphql.Resolvers.Comments do
9999
end
100100
end
101101

102-
def flag(_root, %{comment_id: comment_id, reason: reason}, %{context: %{user: user}}) do
102+
def flag(_root, %{comment_id: comment_id_str, reason: reason}, %{context: %{user: user}}) do
103103
# Get comment and preload statement to access video_id
104-
comment = Repo.get!(Comment, comment_id) |> Repo.preload(:statement)
105-
video_id = comment.statement.video_id
106-
104+
comment_id = String.to_integer(comment_id_str)
105+
video_id =
106+
Comment
107+
|> join(:inner, [c], s in assoc(c, :statement))
108+
|> select([c, s], s.video_id)
109+
|> where([c, s], c.id == ^comment_id)
110+
|> Repo.one!()
111+
112+
IO.inspect(%{comment_id: comment_id, reason: reason, video_id: video_id})
107113
Flagger.flag!(user.id, video_id, comment_id, reason)
108-
{:ok, %{id: comment_id}}
114+
{:ok, %{id: comment_id, video_id: video_id}}
109115
end
110116

111117
# Helper function to calculate vote value diff (matches comments_channel.ex logic)

apps/cf_graphql/lib/resolvers/history.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ defmodule CF.Graphql.Resolvers.History do
1515
end
1616

1717

18+
19+
20+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule CF.Graphql.Resolvers.Moderation do
2+
@moduledoc """
3+
Resolvers for moderation-related queries
4+
"""
5+
6+
alias CF.Moderation
7+
8+
def random(_root, _args, %{context: %{user: user}}) do
9+
case Moderation.random!(user) do
10+
nil -> {:ok, nil}
11+
entry -> {:ok, entry}
12+
end
13+
end
14+
end

apps/cf_graphql/lib/resolvers/speakers.ex

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,23 @@ defmodule CF.Graphql.Resolvers.Speakers do
187187
|> Repo.update()
188188
|> case do
189189
{:ok, updated_speaker} ->
190-
Subscriptions.publish_speaker_updated(updated_speaker, nil)
191-
CF.Algolia.SpeakersIndex.save_object(updated_speaker)
190+
# Publish subscription updates asynchronously
191+
Task.start(fn ->
192+
speaker_video_ids =
193+
Repo.all(
194+
from(vs in VideoSpeaker, where: vs.speaker_id == ^speaker.id, select: vs.video_id)
195+
)
196+
197+
Enum.each(speaker_video_ids, fn video_id ->
198+
Subscriptions.publish_speaker_updated(updated_speaker, video_id)
199+
end)
200+
end)
201+
202+
# Update search index asynchronously
203+
Task.start(fn ->
204+
CF.Algolia.SpeakersIndex.save_object(updated_speaker)
205+
end)
206+
192207
{:ok, updated_speaker}
193208

194209
{:error, changeset} ->

apps/cf_graphql/lib/resolvers/users.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ defmodule CF.Graphql.Resolvers.Users do
8989
|> Result.ok()
9090
end
9191

92+
@spec videos_added(
93+
atom() | %{:id => any(), optional(any()) => any()},
94+
%{:limit => any(), :offset => any(), optional(any()) => any()},
95+
any()
96+
) :: {:ok, Scrivener.Page.t()}
9297
@doc """
9398
Get videos added by this user
9499
"""

apps/cf_graphql/lib/schema/schema.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ defmodule CF.Graphql.Schema do
88
import_types(CF.Graphql.Schema.Types.{
99
AppInfo,
1010
Comment,
11+
Flag,
1112
JSON,
13+
ModerationEntry,
1214
Notification,
1315
Paginated,
1416
Source,
@@ -129,6 +131,12 @@ defmodule CF.Graphql.Schema do
129131
arg(:url, non_null(:string))
130132
resolve(&Resolvers.Videos.search/3)
131133
end
134+
135+
@desc "Get a random action requiring moderation"
136+
field :random_moderation, :moderation_entry do
137+
middleware(Middleware.RequireAuthentication)
138+
resolve(&Resolvers.Moderation.random/3)
139+
end
132140
end
133141

134142
# Mutation API
@@ -291,7 +299,7 @@ defmodule CF.Graphql.Schema do
291299
middleware(Middleware.RequireAuthentication)
292300

293301
arg(:comment_id, non_null(:id))
294-
arg(:reason, non_null(:integer))
302+
arg(:reason, non_null(:flag_reason))
295303

296304
resolve(&Resolvers.Comments.flag/3)
297305
end

apps/cf_graphql/lib/schema/types/comment.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ defmodule CF.Graphql.Schema.Types.Comment do
99
import CF.Graphql.Schema.Utils
1010
alias CF.Graphql.Resolvers
1111

12+
@desc "Reason for flagging a comment"
13+
enum :flag_reason do
14+
value(:bad_language, description: "Personal attack or inappropriate language", as: 1)
15+
value(:spam, description: "Unwanted commercial content or spam", as: 2)
16+
value(:irrelevant, description: "Irrelevant", as: 3)
17+
value(:not_constructive, description: "Not constructive", as: 4)
18+
end
19+
1220
@desc "A user's comment. A comment will be considered being a fact if it has a source"
1321
object :comment do
1422
field(:id, non_null(:id))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule CF.Graphql.Schema.Types.Flag do
2+
@moduledoc """
3+
Representation of a `DB.Schema.Flag` for Absinthe
4+
"""
5+
6+
use Absinthe.Schema.Notation
7+
8+
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
9+
import CF.Graphql.Schema.Utils
10+
11+
@desc "A flag on an action"
12+
object :flag do
13+
@desc "User who created the flag"
14+
field :source_user, :user do
15+
resolve(dataloader(DB.Repo))
16+
complexity(join_complexity())
17+
end
18+
19+
@desc "Reason for the flag"
20+
field(:reason, :flag_reason)
21+
end
22+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule CF.Graphql.Schema.Types.ModerationEntry do
2+
@moduledoc """
3+
Representation of a `CF.Moderation.ModerationEntry` for Absinthe
4+
"""
5+
6+
use Absinthe.Schema.Notation
7+
8+
import CF.Graphql.Schema.Utils
9+
10+
@desc "A moderation entry containing an action and its flags"
11+
object :moderation_entry do
12+
@desc "The action that needs moderation"
13+
field(:action, non_null(:user_action))
14+
15+
@desc "Flags associated with this action"
16+
field(:flags, non_null(list_of(:flag)))
17+
end
18+
end

apps/cf_graphql/lib/subscriptions.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@ end
9797

9898

9999

100+
101+
102+

0 commit comments

Comments
 (0)