diff options
-rwxr-xr-x | telem.lua | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -290,6 +290,17 @@ function do_messages() save_scan_times() end +function create_post() + -- This is used by both do_new and do_reply + -- Launch editor to save post in temporary file + local filename = os.tmpname() + os.execute(_EDITOR .. " " .. filename) + -- Check that file exists and is not empty + if not path.exists(filename) then return nil end + if lfs.attributes(filename).size == 0 then return nil end + return filename +end + function do_new() if not check_at_board() then return end -- Get subject for new thread @@ -303,8 +314,11 @@ function do_new() return end -- Save body of post to temp file - local filename = os.tmpname() - os.execute(_EDITOR .. " " .. filename) + local filename = create_post() + if not filename then + print("Post cancelled.") + return + end -- TODO: show and confirm -- Make thread dir local timestamp = tostring(os.time()) @@ -374,8 +388,13 @@ function do_type_prev() end function do_type_reply() - local filename = os.tmpname() - os.execute(_EDITOR .. " " .. filename) + -- Read reply body into temp file + local filename = create_post() + if not filename then + print("Empty file, reply cancelled.") + return + end + -- Move temp file to correct location and set permissions local timestamp = tostring(os.time()) local newfilename = timestamp .. "-" .. username local newpath = path.join(current_thread.directory, newfilename) @@ -384,6 +403,7 @@ function do_type_reply() print(str) end os.execute("chmod og+r " .. newpath) + -- Update state and show reply current_thread_posts = get_posts(current_thread) current_post_index = #current_thread_posts do_type_show_post() |