|
|
@ -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,7 +27,8 @@ 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 |
|
|
|
|
|
|
|
if (new_replynum > state.reply_number) or first_run do |
|
|
|
{:ok, res} = TirInnaNoc.Imageboard.thread(state.board, state.no) |
|
|
|
{:ok, res} = TirInnaNoc.Imageboard.thread(state.board, state.no) |
|
|
|
if res.status == 200 do |
|
|
|
if res.status == 200 do |
|
|
|
res.body["posts"] |
|
|
|
res.body["posts"] |
|
|
@ -35,6 +37,7 @@ defmodule TirInnaNoc.Perenelle do |
|
|
|
send(self(), {:addpost, post, sage_status}) |
|
|
|
send(self(), {:addpost, post, sage_status}) |
|
|
|
end) |
|
|
|
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) |
|
|
|
{:noreply, state} |
|
|
|
{:noreply, state} |
|
|
|