defmodule Mix.Tasks.Pleroma.Marker do
use Mix.Task
import Mix.Pleroma
-
import Ecto.Query
- alias Pleroma.Repo
+
alias Pleroma.Notification
+ alias Pleroma.Repo
def run(["update_markers"]) do
start_pleroma()
user_id: q.user_id,
unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
last_read_id:
- type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
+ type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
},
group_by: [q.user_id]
)
|> Ecto.Changeset.change()
|> Pleroma.Repo.insert(
returning: true,
- on_conflict: {:replace, [:last_read_id, :unread_count]},
- conflict_target: [:user_id, :timeline]
+ on_conflict: {:replace, [:last_read_id, :unread_count]},
+ conflict_target: [:user_id, :timeline]
)
end)
|> json_response(200)
assert response == %{
- "notifications" => %{
- "last_read_id" => "69420",
- "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
- "version" => 0,
- "pleroma" => %{ "unread_count" => 7 }
- }
- }
+ "notifications" => %{
+ "last_read_id" => "69420",
+ "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
+ "version" => 0,
+ "pleroma" => %{"unread_count" => 7}
+ }
+ }
end
test "gets markers with missed scopes", %{conn: conn} do
"last_read_id" => "69420",
"updated_at" => _,
"version" => 0,
- "pleroma" => %{ "unread_count" => 0 }
+ "pleroma" => %{"unread_count" => 0}
}
} = response
end
"last_read_id" => "69888",
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
"version" => 0,
- "pleroma" => %{ "unread_count" => 0 }
+ "pleroma" => %{"unread_count" => 0}
}
}
end