Skip to content
Browse files

Why not commenting on diaspora.el instead using a web browser??? :P

Now you can comment posts using `diaspora-comment-message-new-buffer` in the entry-stream.
Once you finish write your comment, send it with `diaspora-send-comment-this-buffer`.

If somethings goes wrong, remember to set the `diaspora-auth-token` variable into nil.
  • Loading branch information...
1 parent 2faa47c commit 3c88e7f44c3978089b5ea6c4d301eb7e8950d7c5 @cnngimenez committed Feb 14, 2012
Showing with 102 additions and 39 deletions.
  1. +3 −1 README.md
  2. +70 −1 diaspora-comments.el
  3. +16 −33 diaspora-stream.el
  4. +13 −4 diaspora.el
View
4 README.md
@@ -1,6 +1,8 @@
## diaspora(dot)el --- Simple Emacs-based client for diaspora*
-You can find me: https://joindiaspora.com/u/tca
+You can find us:
+https://joindiaspora.com/u/tca
+https://joindiaspora.com/u/cnngimenez
*WARNING*
View
71 diaspora-comments.el
@@ -2,7 +2,7 @@
;;
;; Filename: diaspora-comments.el
;; Description:
-;; Author: Christian
+;; Author: Christian Giménez, Tiago Charters Azevedo
;; Maintainer:
;; Created: mar feb 14 13:15:51 2012 (-0300)
;; Version:
@@ -50,6 +50,73 @@
;;; Code:
+(defun diaspora-insert-comments-for-message (message-id &optional buffer)
+ "Get the comments for the given message, and insert it in the current
+buffer or in the buffer specified."
+ (let ((buff-http (diaspora-get-url-entry-stream
+ (diaspora-get-comment-url message-id)))
+ (buffer (if (null buffer)
+ (current-buffer)
+ buffer)))
+ (with-current-buffer buff-http
+ (diaspora-delete-http-header)
+ (let ((json-array-type 'list)
+ (json-object-type 'alist)
+ (lstparsed (json-read)))
+ ;; parse all comments one by one and insert it
+ (let ((le (length lstparsed))
+; (inhibit-read-only t)
+ )
+ (dotimes (i le)
+ (diaspora-insert-comment (aref lstparsed i) buffer)))))))
+
+(defun diaspora-insert-comment (comment buffer)
+ "Insert a JSON parsed (with `json-read') into a specific buffer."
+ (let ((name (cdr (assoc 'name (cdr (assoc 'author comment)))))
+ (text (cdr (assoc 'text comment)))
+ (created_at (cdr (assoc 'created_at comment))))
+ (with-current-buffer buffer
+ (insert (format "\n---\n%s at %s:\n" name created_at))
+ (insert text))))
+
+
+(defconst diaspora-comment-buffer-name "*diaspora comment*"
+ "This is the name of the comment buffer.")
+
+(defvar diaspora-comment-buffer nil
+ "This is the buffer (supposed to be only one or unique) for write a comment.")
+
+(defun diaspora-new-comment-buffer (post-id)
+ "Create a new buffer for write a comment for the post with id given by post-id."
+ (interactive)
+ (setq diaspora-next-comment-to-post post-id)
+ ;; create buffer
+ (setq diaspora-comment-buffer (get-buffer-create diaspora-comment-buffer-name))
+ (switch-to-buffer-other-window diaspora-comment-buffer)
+ ;; insert header and footer, modes... etc.
+ (diaspora-date)
+ (insert diaspora-footer-post)
+ (goto-char (point-min))
+ (insert diaspora-header-post)
+ (diaspora-mode)
+ (message "Use C-c C-c to comment to diaspora or use diaspora-send-comment-this-buffer."))
+
+(defvar diaspora-next-comment-to-post
+ nil
+ "This is the post id where to send the comment in the next `diaspora-send-comment-this-buffer' function call.")
+
+(defun diaspora-send-comment-this-buffer ()
+ "Send this buffer as a comment to the post determined by the id `diaspora-next-comment-to-post'."
+ (interactive)
+ (diaspora-ask)
+ (when (null diaspora-auth-token)
+ (message (concat "Getting authenticity token..."))
+ (diaspora-authenticity-token (diaspora-url diaspora-sign-in-url))
+ (message (concat "done: " diaspora-auth-token))
+ )
+ (diaspora-send-comment-post (buffer-string) diaspora-next-comment-to-post))
+
+
(defun diaspora-send-comment-post (comment post-id)
"Send a comment for the post given by the post-id.
Comment should be a String and post-id the id number of the post."
@@ -68,6 +135,8 @@ Comment should be a String and post-id the id number of the post."
"&")))
(url-retrieve-synchronously (diaspora-post-comment-url post-id))))
+;; Add keymap for `diaspora-mode':
+
(provide 'diaspora-comments)
View
49 diaspora-stream.el
@@ -30,6 +30,8 @@
;; Streaming
+(require 'diaspora-comments)
+
(defun diaspora-show-stream (status &optional new-buffer-name)
"Show what was recieved in a new buffer.
If new-buffer-name is given then, the new buffer will have that name,
@@ -169,6 +171,7 @@ Check if the temporal directory exists, if not create it."
(defvar diaspora-show-message-map
(let ((map (make-sparse-keymap)))
+ (define-key map [c] 'diaspora-comment-message-new-buffer)
(define-key map [return] 'diaspora-show-message-new-buffer)
(define-key map [mouse-2] 'diaspora-show-message-new-buffer)
map)
@@ -241,13 +244,22 @@ or a function like `diaspora-show-message-new-buffer'."
'help-echo "Click here to see this message in new buffer.")
)
+(defun diaspora-get-id-message-near-point ()
+ "Get the diaspora-id-message property value searching from point.
+Use it for getting the nearest id post number when selecting a message."
+ (get-text-property (+ 1 (previous-single-property-change (+ (point) 1) 'diaspora-id-message))
+ 'diaspora-id-message))
+
+
(defun diaspora-show-message-new-buffer (&rest r)
"Show this message in new buffer. Load the message, and all its comments, and show it!."
(interactive)
- (let ((id-message
- (get-text-property (+ 1 (previous-single-property-change (+ (point) 1) 'diaspora-id-message))
- 'diaspora-id-message)))
- (diaspora-get-single-message id-message)))
+ (diaspora-get-single-message (diaspora-get-id-message-near-point)))
+
+(defun diaspora-comment-message-new-buffer (&rest r)
+ "Create a new buffer for commenting the current message."
+ (interactive)
+ (diaspora-new-comment-buffer (diaspora-get-id-message-near-point)))
(defun diaspora-single-message-destroy ()
"Destroy the current diaspora single message buffer."
@@ -304,35 +316,6 @@ or a function like `diaspora-show-message-new-buffer'."
(dotimes (i le)
(diaspora-show-message (aref lstparsed i) buff)))))
-(defun diaspora-insert-comments-for-message (message-id &optional buffer)
- "Get the comments for the given message, and insert it in the current
-buffer or in the buffer specified."
- (let ((buff-http (diaspora-get-url-entry-stream
- (format "%s/%s/comments.json" (diaspora-url diaspora-single-message-url) message-id)))
- (buffer (if (null buffer)
- (current-buffer)
- buffer)))
- (with-current-buffer buff-http
- (diaspora-delete-http-header)
- (let ((json-array-type 'list)
- (json-object-type 'alist)
- (lstparsed (json-read)))
- ;; parse all comments one by one and insert it
- (let ((le (length lstparsed))
-; (inhibit-read-only t)
- )
- (dotimes (i le)
- (diaspora-insert-comment (aref lstparsed i) buffer)))))))
-
-(defun diaspora-insert-comment (comment buffer)
- "Insert a JSON parsed (with `json-read') into a specific buffer."
- (let ((name (cdr (assoc 'name (cdr (assoc 'author comment)))))
- (text (cdr (assoc 'text comment)))
- (created_at (cdr (assoc 'created_at comment))))
- (with-current-buffer buffer
- (insert (format "\n---\n%s at %s:\n" name created_at))
- (insert text))))
-
;; images: needs working
(defun diaspora-get-user-avatar (url &optional user-id)
View
17 diaspora.el
@@ -245,7 +245,7 @@ And the `diaspora-participate-stream-name' must be at value \"participate\"."
:type 'string
:group 'diaspora-streams)
-(defcustom diaspora-post-comment-name
+(defcustom diaspora-comment-name
"comments"
"This is the name of the comments for posting."
:type 'string
@@ -707,12 +707,21 @@ Note: this is not correct! Needs more thought to get all images right."
(defun diaspora-post-comment-url (post-id)
"Return the URL for posting a comment for the post with id post-id"
(diaspora-url
- (format "%s/%s"
+ (format "%s/%s/%s"
+ diaspora-single-message-url
(if (numberp post-id)
(number-to-string post-id)
post-id)
- diaspora-post-comment-name)))
-
+ diaspora-comment-name)))
+
+(defun diaspora-get-comment-url (post-id)
+ (diaspora-url
+ (format "%s/%s/%s.json" diaspora-single-message-url
+ (if (numberp post-id)
+ (number-to-string post-id)
+ post-id)
+ post-id
+ diaspora-comment-name)))
(provide 'diaspora)

0 comments on commit 3c88e7f

Please sign in to comment.
Something went wrong with that request. Please try again.