|
|
@ -9,13 +9,14 @@ defmodule TirInnaNoc.Perenelle do |
|
|
|
def init(state) do |
|
|
|
def init(state) do |
|
|
|
IO.puts("watching thread "<>inspect(state)) |
|
|
|
IO.puts("watching thread "<>inspect(state)) |
|
|
|
send(String.to_atom(state.board<>"Meldh"), {:checkin, state.no, self()}) |
|
|
|
send(String.to_atom(state.board<>"Meldh"), {:checkin, state.no, self()}) |
|
|
|
send(self(), {:update, state.on_page, state.reply_number}) |
|
|
|
send(self(), {:update, state.on_page, state.reply_number, true}) |
|
|
|
{:ok, state} |
|
|
|
{:ok, state} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
@impl true |
|
|
|
def handle_info({:addpost, post, sage_status}, state) do |
|
|
|
def handle_info({:addpost, post, sage_status}, state) do |
|
|
|
state = %TirInnaNoc.Imageboard.Thread{state | posts: [%TirInnaNoc.Imageboard.Post{post: post, sage: sage_status}]++state.posts} |
|
|
|
state = %TirInnaNoc.Imageboard.Thread{state | posts: [%TirInnaNoc.Imageboard.Post{post: post, sage: sage_status}]++state.posts} |
|
|
|
|
|
|
|
TirInnaNoc.Imageboard.Post.save(%TirInnaNoc.Imageboard.Post{post: post, sage: sage_status}, state.board) |
|
|
|
{:noreply, state} |
|
|
|
{:noreply, state} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -26,14 +27,16 @@ defmodule TirInnaNoc.Perenelle do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
@impl true |
|
|
|
def handle_info({:update, new_page, new_replynum}, state) do |
|
|
|
def handle_info({:update, new_page, new_replynum, first_run}, state) do |
|
|
|
{:ok, res} = TirInnaNoc.Imageboard.thread(state.board, state.no) |
|
|
|
if (new_replynum > state.reply_number) or first_run do |
|
|
|
if res.status == 200 do |
|
|
|
{:ok, res} = TirInnaNoc.Imageboard.thread(state.board, state.no) |
|
|
|
res.body["posts"] |
|
|
|
if res.status == 200 do |
|
|
|
|> Enum.each(fn post -> |
|
|
|
res.body["posts"] |
|
|
|
sage_status = if (new_page>state.on_page and new_replynum == state.reply_number+1), do: "y", else: "n" |
|
|
|
|> Enum.each(fn post -> |
|
|
|
send(self(), {:addpost, post, sage_status}) |
|
|
|
sage_status = if (new_page>state.on_page and new_replynum == state.reply_number+1), do: "y", else: "n" |
|
|
|
end) |
|
|
|
send(self(), {:addpost, post, sage_status}) |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
state = %TirInnaNoc.Imageboard.Thread{state | on_page: new_page, reply_number: new_replynum} |
|
|
|
state = %TirInnaNoc.Imageboard.Thread{state | on_page: new_page, reply_number: new_replynum} |
|
|
|
send(self(), :save) |
|
|
|
send(self(), :save) |
|
|
|