* sb-mixi.el (shimbun-get-headers): Use `mixi-bbs-p'.
[elisp/mixi.git] / sb-mixi.el
index 5b16ba8..2c56b98 100644 (file)
@@ -47,7 +47,8 @@ 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.
-FUNCTION is the function for getting articles."
+FUNCTION is the function which has one `range' argument and returns the list
+of mixi object."
   :group 'shimbun
   :type '(repeat (cons :fromat "%v"
                       (string :tag "Group name")
@@ -64,8 +65,8 @@ FUNCTION is the function for getting articles."
   :group 'shimbun
   :type 'integer)
 
-(defcustom shimbun-mixi-get-comment-p t
-  "*If non-nil, get diaries or BBSes together with its comments."
+(defcustom shimbun-mixi-logout-p nil
+  "*If non-ni, logout from mixi when shimbun server was closed."
   :group 'shimbun
   :type 'boolean)
 
@@ -80,15 +81,31 @@ FUNCTION is the function for getting articles."
                                           (make-hash-table :test 'equal))
   shimbun)
 
+(luna-define-method shimbun-close :after ((shimbun shimbun-mixi))
+  (shimbun-mixi-set-comment-cache-internal shimbun nil)
+  (when shimbun-mixi-logout-p
+    (mixi-logout)))
+
 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
   (mapcar 'car shimbun-mixi-group-alist))
 
-(defun shimbun-mixi-make-subject (object)
+(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)))
@@ -133,7 +150,23 @@ FUNCTION is the function for getting articles."
           (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-get-headers (shimbun objects &optional range)
   (when objects
@@ -146,7 +179,7 @@ FUNCTION is the function for getting articles."
                    (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
@@ -157,10 +190,8 @@ FUNCTION is the function for getting articles."
                      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))
@@ -187,35 +218,27 @@ FUNCTION is the function for getting articles."
                ((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)
-  (let* ((parent (mixi-make-object-from-url url))
-        (date (shimbun-header-date header))
-        (message-id (shimbun-header-id header))
-        (cache (gethash message-id
-                        (shimbun-mixi-comment-cache-internal shimbun))))
-    (if (stringp cache)
-       cache
-      (catch 'found
+(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)))
+    (unless (stringp article)
+      (let ((parent (mixi-make-object-from-url url)))
        (mapc (lambda (comment)
-               (let ((id (mixi-friend-id (mixi-comment-owner comment)))
-                     (time (shimbun-mixi-make-date comment)))
-                 (when (and (string= time date)
-                            (string-match (concat "^<[0-9]+\\." id "@")
-                                          message-id))
-                   ;; FIXME: Concat parent's information?
-                   (let ((content (mixi-comment-content comment)))
-                     (puthash message-id content
-                              (shimbun-mixi-comment-cache-internal shimbun))
-                     (throw 'found content)))))
-             (mixi-get-comments parent))))))
+               (let ((id (shimbun-mixi-make-message-id comment))
+                     (content (mixi-comment-content comment)))
+                 (puthash id content cache)
+                 (when (string= id message-id)
+                   (setq article content))))
+             (mixi-get-comments parent))))
+    article))
 
 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
                                     header &optional outbuf)
@@ -225,8 +248,8 @@ FUNCTION is the function for getting articles."
        (or (with-temp-buffer
             (let* ((url (shimbun-article-url shimbun header))
                    (article (if (string-match "#comment$" url)
-                                (shimbun-comment-article url shimbun header)
-                              ;; FIXME: Concat community information?
+                                (shimbun-mixi-comment-article
+                                 url shimbun header)
                               (shimbun-mixi-make-body
                                (mixi-make-object-from-url url)))))
               (when (stringp article)