You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
6.6 KiB

;;; idec-online.el --- This file part of GNU Emacs client for IDEC network
;; Copyright (c) 2017 Denis Zheleztsov
;; Author: Denis Zheleztsov <>
;; Keywords: lisp,network,IDEC
;; Version: 0.1
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <>.
;;; Commentary:
;; In active developent.
;; Fetched node must be support modern IDEC extensions like /list.txt, /x/c, etc.
;;; Code:
;; (require 'idec-mode)
(require 'idec-answers)
(defun display-echo-messages (messages)
"Display downloaded MESSAGES from echo."
(message (concat "RECEIVED MESSAGES: " messages))
(let (msgs echo echo-msg-hash)
(setq echo-msg-hash (make-hash-table :test 'equal))
(setq echo (nth 0 (split-string messages "\n")))
(setq msgs (split-string messages "\n"))
(dolist (id msgs)
(when (not (or
(string-match "\\." id)
(string= "" id)))
(puthash id echo echo-msg-hash)))
(with-output-to-temp-buffer (get-buffer-create (concat "*IDEC: online browse " echo "*" ))
(switch-to-buffer (concat "*IDEC: online browse " echo "*"))
(maphash (lambda (id msg-hash)
(when (equal (get-message-field (gethash "content" msg-hash) "echo") echo)
(princ "__________________________________\n")
(princ (concat "ID: " id "\n"))
(princ (concat "From: " (get-message-field (gethash "content" msg-hash) "author") "("
(get-message-field (gethash "content" msg-hash) "address") ")" "\n"))
(princ (concat "To: " (get-message-field (gethash "content" msg-hash) "recipient") "\n"))
(princ (concat "Echo: " (get-message-field (gethash "content" msg-hash) "echo") "\n"))
(princ (concat "At: " (get-message-field (gethash "content" msg-hash) "time") "\n"))
(let (subj)
(setq subj (concat "Subject: " (get-message-field (gethash "content" msg-hash) "subj")))
(princ (concat subj "\n")))
(princ (concat "__________________________________\n\n"
(replace-in-string "\r" ""
(s-join "\n"
(gethash "content" msg-hash)
(princ "\n__________________________________\n")
(princ "[")
(insert-button "Answer"
'action (lambda (x) (edit-answer-without-quote (button-get x 'id) (button-get x 'msg-hash)))
'id id
'msg-hash msg-hash)
(princ "]")
(princ "\t [")
(insert-button "Answer with quote")
(princ "]\n\n")))
;; Plain messages hash proccesing
(get-messages-content echo-msg-hash))
;; (idec-mode)
(defun load-echo-messages (echo &optional online)
"Load messages from ECHO with ONLINE selector."
(when (not online)
(message (concat "Update counter of " echo))
(store-echo-counter echo))
(display-echo-messages (get-url-content (make-echo-url echo))))
(defun proccess-echo-message (msg echo)
"Download new message MSG in ECHO."
(with-output-to-temp-buffer (get-buffer-create "*IDEC: DEBUG*")
(switch-to-buffer "*IDEC: DEBUG*")
(princ msg)
(princ echo)))
(defun proccess-echo-list (raw-list)
"Parse RAW-LIST from HTTP response."
(with-output-to-temp-buffer (get-buffer-create "*IDEC: list.txt*")
(switch-to-buffer "*IDEC: list.txt*")
(let (len lst)
;; Calculate echo name
(setq lst (list))
(dolist (l (split-string (decode-coding-string raw-list 'utf-8) "\n"))
(add-to-list 'lst (nth 0 (split-string l ":")) t))
(setq len (get-longest-string lst))
(message (concat "Longest echo " (number-to-string len)))
(dolist (line (split-string (decode-coding-string raw-list 'utf-8) "\n"))
(when (not (equal line ""))
;; Define echo
(defvar current-echo nil)
(setq current-echo (nth 0 (split-string line ":")))
;; Create clickable button
(insert-text-button current-echo
'action (lambda (x) (load-echo-messages (button-get x 'echo) t))
'help-echo (concat "Go to echo " current-echo)
'echo current-echo)
(let (s e)
(setq e (point))
(setq s (point))
(add-text-properties s e '(comment t face '(:foreground "light green")))))
(princ (make-string (+ 3 (- len (length current-echo))) ? ))
(princ (format "%s\n"
(nth 2 (split-string line ":"))))
(let (s e)
(setq e (point))
(re-search-backward " ")
(setq s (point))
(add-text-properties s e '(comment t face '(:foreground "light blue")))))))))
(defun idec-fetch-echo-list (nodeurl)
"Fetch echoes list from remote NODEURL."
(proccess-echo-list (get-url-content nodeurl)))
(provide 'idec-online)
;;; idec-online.el ends here