Fix docs.
[elisp/mixi.git] / sb-mixi.el
index c50fb52..60b7bf7 100644 (file)
@@ -44,9 +44,9 @@
   "*An alist of mixi shimbun group definition.
 Each element looks like (NAME . URL) or (NAME . FUNCTION).
 NAME is a shimbun group name.
-URL is the URL for mixi access point of the group.  When URL is friend's, get
-his/her diaries as article.  When community's, get its BBSes.  When diary's
-or BBS's, get its comments.
+URL is the URL for mixi access point of the group.  If URL is friend's, get
+his/her diaries as article.  If community's, get its BBSes.  If diary's or
+BBS's, get its comments.
 FUNCTION is the function which has one `range' argument and returns the list
 of mixi object."
   :group 'shimbun
@@ -65,44 +65,46 @@ of mixi object."
   :group 'shimbun
   :type 'integer)
 
-(defcustom shimbun-mixi-get-comment-p t
-  "*If non-nil, get diaries or BBSes together with its comments."
-  :group 'shimbun
-  :type 'boolean)
-
-(defcustom shimbun-mixi-logout-p nil
-  "*If non-ni, Logout from mixi when shimbun server was closed."
-  :group 'shimbun
-  :type 'boolean)
-
 (defvar shimbun-mixi-x-face-alist
   '(("default" . "X-Face: CY;j#FoBnpK^37`-IoJvN!J^u;GciiPmMQ@T)~RP1]t8iv?v)/bVI:I\"F!JfWJvhM5{zY!=
  h.d+'g\\I{D>Ocy?Rc4uYUyOZj2%2Kl>,x-!MCSsyi3!L}psrrC1jlF,O?Ui>qf)X;sBz`/}\\066X%$
  siG'|4K!2?==|oB&#E'5GGH\\#z[muyQ")))
 
-(defmacro shimbun-mixi-initialize-comment-cache (shimbun)
-  `(shimbun-mixi-set-comment-cache-internal ,shimbun
-                                           (make-hash-table :test 'equal)))
+(defvar shimbun-mixi-reply-to nil)
 
 (luna-define-method initialize-instance :after ((shimbun shimbun-mixi)
                                                &rest init-args)
-  (shimbun-mixi-initialize-comment-cache shimbun)
+  (shimbun-mixi-set-comment-cache-internal shimbun
+                                          (make-hash-table :test 'equal))
   shimbun)
 
 (luna-define-method shimbun-close :after ((shimbun shimbun-mixi))
-  (shimbun-mixi-initialize-comment-cache shimbun)
-  (when shimbun-mixi-logout-p
-    (mixi-logout)))
+  (shimbun-mixi-set-comment-cache-internal shimbun nil)
+  (mixi-logout))
 
 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
   (mapcar 'car shimbun-mixi-group-alist))
 
-(defun shimbun-mixi-make-subject (object)
+(luna-define-method shimbun-reply-to ((shimbun shimbun-mixi))
+  shimbun-mixi-reply-to)
+
+(defun shimbun-mixi-make-subject (shimbun object)
   (let ((class (mixi-object-class object)))
-    (cond ((eq class 'mixi-comment)
-          (concat "Re: " (shimbun-mixi-make-subject
-                          (mixi-comment-parent object))))
-         (t (mixi-object-title object)))))
+    (if (eq class 'mixi-comment)
+        (concat "Re: " (shimbun-mixi-make-subject
+                       shimbun (mixi-comment-parent object)))
+      (let ((prefix (when (eq class 'mixi-event) "[¥¤¥Ù¥ó¥È]"))
+           (subject (mixi-object-title object))
+           (suffix (when (string-match
+                          "^new-" (shimbun-current-group-internal shimbun))
+                     (concat " ("
+                             (if (eq class 'mixi-diary)
+                                 (mixi-friend-nick
+                                  (mixi-diary-owner object))
+                               (mixi-community-name
+                                (mixi-bbs-community object)))
+                             ")"))))
+       (concat prefix subject suffix)))))
 
 (defun shimbun-mixi-make-from (object)
   (let ((owner (mixi-object-owner object)))
@@ -147,7 +149,49 @@ of mixi object."
           (mixi-expand-url (mixi-message-page object))))))
 
 (defun shimbun-mixi-make-body (object)
-  (mixi-object-content object))
+  (let ((class (mixi-object-class object)))
+    (cond ((eq class 'mixi-event)
+          (let ((limit (mixi-event-limit object)))
+            (setq limit (if limit
+                            (format-time-string "%Yǯ%m·î%dÆü" limit)
+                          "»ØÄê¤Ê¤·"))
+            (concat "<dl><dt>³«ºÅÆü»þ¡§</dt>"
+                    "<dd>" (mixi-event-date object) "</dd>"
+                    "<dt>³«ºÅ¾ì½ê¡§</dt>"
+                    "<dd>" (mixi-event-place object) "</dd>"
+                    "<dt>¾ÜºÙ¡§</dt>"
+                    "<dd>" (mixi-event-detail object) "</dd>"
+                    "<dt>Ê罸´ü¸Â¡§</dt>"
+                    "<dd>" limit "</dd>"
+                    "<dt>»²²Ã¼Ô¡§</dt>"
+                    "<dd>" (mixi-event-members object) "</dd></dl>")))
+         (t (mixi-object-content object)))))
+
+(defun shimbun-mixi-make-reply-to (object)
+  (setq shimbun-mixi-reply-to "mixi;")
+  (let ((class (mixi-object-class object)))
+    (setq shimbun-mixi-reply-to
+         (concat
+          (cond ((eq class 'mixi-diary)
+                 (concat shimbun-mixi-reply-to "comment;diary;"
+                         (mixi-friend-id (mixi-diary-owner object)) ";"
+                         (mixi-diary-id object)))
+                ((mixi-bbs-p object)
+                 (concat shimbun-mixi-reply-to "comment;"
+                         (mixi-object-name object) ";"
+                         (mixi-community-id (mixi-bbs-community object)) ";"
+                         (mixi-bbs-id object)))
+                ((eq class 'mixi-community)
+                 (concat shimbun-mixi-reply-to "topic;"
+                         (mixi-community-id object)))
+                ((eq object (mixi-make-me))
+                 (concat shimbun-mixi-reply-to "diary"))
+                ((eq class 'mixi-message)
+                 (concat shimbun-mixi-reply-to "message;"
+                         (mixi-friend-id (mixi-message-owner object))))
+                ((or (eq class 'mixi-friend) (eq class 'mixi-log))
+                 (concat shimbun-mixi-reply-to "message;"
+                         (mixi-friend-id object))))))))
 
 (defun shimbun-mixi-get-headers (shimbun objects &optional range)
   (when objects
@@ -160,7 +204,7 @@ of mixi object."
                    (push
                     (shimbun-create-header
                      0
-                     (shimbun-mixi-make-subject object)
+                     (shimbun-mixi-make-subject shimbun object)
                      (shimbun-mixi-make-from object)
                      (shimbun-mixi-make-date object)
                      id
@@ -171,10 +215,8 @@ of mixi object."
                      0 0
                      (shimbun-mixi-make-xref object))
                     headers)
-                   (when (and shimbun-mixi-get-comment-p
-                              (or (eq class 'mixi-diary)
-                                  (eq class 'mixi-topic)
-                                  (eq class 'mixi-event)))
+                   (when (or (eq class 'mixi-diary)
+                             (mixi-bbs-p object))
                      (let ((comments (mixi-get-comments object range)))
                        (mapc (lambda (header)
                                (push header headers))
@@ -201,15 +243,14 @@ of mixi object."
                ((eq class 'mixi-community)
                 (setq objects (mixi-get-bbses object range)))
                ((or (eq class 'mixi-diary)
-                    (eq class 'mixi-topic)
-                    (eq class 'mixi-event))
+                    (mixi-bbs-p object))
                 (setq objects (mixi-get-comments object range)))
                (t (error (concat (symbol-name class)
                                  " is not supported yet.")))))
       (setq objects (funcall url-or-function range)))
     (shimbun-sort-headers (shimbun-mixi-get-headers shimbun objects range))))
 
-(defun shimbun-comment-article (url shimbun header)
+(defun shimbun-mixi-comment-article (url shimbun header)
   (let* ((message-id (shimbun-header-id header))
         (cache (shimbun-mixi-comment-cache-internal shimbun))
         (article (gethash message-id cache)))
@@ -217,7 +258,6 @@ of mixi object."
       (let ((parent (mixi-make-object-from-url url)))
        (mapc (lambda (comment)
                (let ((id (shimbun-mixi-make-message-id comment))
-                     ;; FIXME: Concat parent's information?
                      (content (mixi-comment-content comment)))
                  (puthash id content cache)
                  (when (string= id message-id)
@@ -232,11 +272,12 @@ of mixi object."
       (w3m-insert-string
        (or (with-temp-buffer
             (let* ((url (shimbun-article-url shimbun header))
+                   (object (mixi-make-object-from-url url))
                    (article (if (string-match "#comment$" url)
-                                (shimbun-comment-article url shimbun header)
-                              ;; FIXME: Concat community information?
-                              (shimbun-mixi-make-body
-                               (mixi-make-object-from-url url)))))
+                                (shimbun-mixi-comment-article
+                                 url shimbun header)
+                              (shimbun-mixi-make-body object))))
+              (shimbun-mixi-make-reply-to object)
               (when (stringp article)
                 (insert article)))
             (shimbun-message shimbun "shimbun: Make contents...")
@@ -245,6 +286,33 @@ of mixi object."
               (shimbun-message shimbun "shimbun: Make contents...done")))
           "")))))
 
+(defconst shimbun-mixi-to-regexp
+  "^mixi;\\([a-z]+\\);?\\([a-z0-9]+\\)?;?\\([0-9]+\\)?;?\\([0-9]+\\)?")
+
+(defun shimbun-mixi-send-mail (to title content)
+  (when (string-match shimbun-mixi-to-regexp to)
+    (let ((method (match-string 1 to)))
+      (cond ((string= method "comment")
+            (let ((parent (match-string 2 to))
+                  (owner-id (match-string 3 to))
+                  (id (match-string 4 to)))
+              (if (string= parent "diary")
+                  (mixi-post-comment
+                   (mixi-make-diary (mixi-make-friend owner-id) id) content)
+                (let ((func (intern
+                             (concat mixi-object-prefix "make-" parent))))
+                  (mixi-post-comment
+                   (funcall func (mixi-make-community owner-id) id)
+                   content)))))
+           ((string= method "topic")
+            (mixi-post-topic (mixi-make-community (match-string 2 to))
+                             title content))
+           ((string= method "diary")
+            (mixi-post-diary title content))
+           ((string= method "message")
+            (mixi-post-message (mixi-make-friend (match-string 2 to))
+                               title content))))))
+
 (provide 'sb-mixi)
 
 ;;; sb-mixi.el ends here