Skip to content

Commit

Permalink
refactor(cleanup): use BBCParser Gen Server for parsing user signatur…
Browse files Browse the repository at this point in the history
…e, run format
  • Loading branch information
akinsey committed Nov 7, 2024
1 parent f618c32 commit 9bace91
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 47 deletions.
68 changes: 31 additions & 37 deletions lib/epochtalk_server_web/helpers/proxy_conversion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,36 +90,37 @@ defmodule EpochtalkServerWeb.Helpers.ProxyConversion do
limit: 1,
select: %{last_active: m.posterTime * 1000}

user = from(u in "smf_members", where: u.id_member == ^user_id)
|> join(:left, [u], a in "smf_attachments",
on: u.id_member == a.id_member and a.attachmentType == 1
)
|> select([u, a], %{
activity: u.activity,
created_at: u.dateRegistered * 1000,
dob: u.birthdate,
gender: u.gender,
id: u.id_member,
language: nil,
location: u.location,
merit: u.merit,
id_group: u.id_group,
id_post_group: u.id_post_group,
signature: u.signature,
post_count: u.posts,
name: u.realName,
username: u.realName,
title: u.usertitle,
website: u.websiteUrl,
avatar:
fragment(
"if(? <>'',concat('https://bitcointalk.org/avatars/',?),ifnull(concat('https://bitcointalk.org/useravatars/',?),''))",
u.avatar,
u.avatar,
a.filename
)
})
|> SmfRepo.one()
user =
from(u in "smf_members", where: u.id_member == ^user_id)
|> join(:left, [u], a in "smf_attachments",
on: u.id_member == a.id_member and a.attachmentType == 1
)
|> select([u, a], %{
activity: u.activity,
created_at: u.dateRegistered * 1000,
dob: u.birthdate,
gender: u.gender,
id: u.id_member,
language: nil,
location: u.location,
merit: u.merit,
id_group: u.id_group,
id_post_group: u.id_post_group,
signature: u.signature,
post_count: u.posts,
name: u.realName,
username: u.realName,
title: u.usertitle,
website: u.websiteUrl,
avatar:
fragment(
"if(? <>'',concat('https://bitcointalk.org/avatars/',?),ifnull(concat('https://bitcointalk.org/useravatars/',?),''))",
u.avatar,
u.avatar,
a.filename
)
})
|> SmfRepo.one()

if user.post_count > 0,
do: Map.merge(user, SmfRepo.one(last_active)),
Expand Down Expand Up @@ -525,13 +526,6 @@ defmodule EpochtalkServerWeb.Helpers.ProxyConversion do
}
})
|> ProxyPagination.page_simple(count_query, page, per_page: per_page, desc: desc)
|> case do
{:ok, [], _} ->
{:error, "Posts not found for user_id: #{id}"}

{:ok, posts, data} ->
return_tuple(posts, data)
end
end

def build_threads_by_user(id, page, per_page, desc) do
Expand Down
13 changes: 3 additions & 10 deletions lib/epochtalk_server_web/json/user_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@ defmodule EpochtalkServerWeb.Controllers.UserJSON do
"""
def find_proxy(%{user: user}) do
parsed_signature =
if user.signature do
%Porcelain.Result{out: parsed_sig, status: _status} =
Porcelain.shell(
"php -r \"require 'parsing.php'; ECHO parse_bbc('" <> user.signature <> "');\""
)

parsed_sig
else
nil
end
if user.signature,
do: EpochtalkServer.BBCParser.async_parse(user.signature),
else: nil

user |> Map.put(:signature, parsed_signature)
end
Expand Down

0 comments on commit 9bace91

Please sign in to comment.