(mixi-news-content-regexp): Follow the change of mixi.
[elisp/mixi.git] / sb-mixi.el
index 22c9e4c..43d0d72 100644 (file)
@@ -1,6 +1,6 @@
 ;;; sb-mixi.el --- shimbun backend for mixi
 
 ;;; sb-mixi.el --- shimbun backend for mixi
 
-;; Copyright (C) 2006 OHASHI Akira
+;; Copyright (C) 2006, 2007, 2008 OHASHI Akira
 
 ;; Author: OHASHI Akira <bg66@koka-in.org>
 ;; Keywords: news
 
 ;; Author: OHASHI Akira <bg66@koka-in.org>
 ;; Keywords: news
@@ -18,9 +18,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; 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, you can either send email to this
-;; program's maintainer or write to: The Free Software Foundation,
-;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 
 ;;; Commentary:
 
 (require 'mixi-utils)
 (require 'shimbun)
 
 (require 'mixi-utils)
 (require 'shimbun)
 
+(defconst shimbun-mixi-revision "$Revision: 1.65 $")
+
 (eval-and-compile
 (eval-and-compile
-  (luna-define-class shimbun-mixi (shimbun) (comment-cache))
+  (luna-define-class shimbun-mixi (shimbun) (comment-cache release-cache))
   (luna-define-internal-accessors 'shimbun-mixi))
 
 (defconst shimbun-mixi-default-group-alist
   '(("new-diaries" . mixi-get-new-diaries)
   (luna-define-internal-accessors 'shimbun-mixi))
 
 (defconst shimbun-mixi-default-group-alist
   '(("new-diaries" . mixi-get-new-diaries)
+    ("new-echoes" . mixi-get-new-echoes)
     ("new-comments" . mixi-get-new-comments)
     ("new-bbses" . mixi-get-new-bbses)
     ("new-comments" . mixi-get-new-comments)
     ("new-bbses" . mixi-get-new-bbses)
+    ("new-bbs-comments" . mixi-get-new-bbs-comments)
     ("messages" . mixi-get-messages)
     ("messages.sent" .
      (lambda (range)
        (mixi-get-messages 'outbox range)))
     ("messages" . mixi-get-messages)
     ("messages.sent" .
      (lambda (range)
        (mixi-get-messages 'outbox range)))
+    ("messages.notice" .
+     (lambda (range)
+       (mixi-get-messages 'noticebox range)))
     ("logs" . mixi-get-logs)
     ("my-diaries" . "/home.pl")
     ("mixi-el" . "/view_community.pl?id=1596390")
     ("logs" . mixi-get-logs)
     ("my-diaries" . "/home.pl")
     ("mixi-el" . "/view_community.pl?id=1596390")
     ("news.newest.it" .
      (lambda (range)
        (mixi-get-news 'IT 'newest range)))
     ("news.newest.it" .
      (lambda (range)
        (mixi-get-news 'IT 'newest range)))
+    ("news.newest.game-anime" .
+     (lambda (range)
+       (mixi-get-news 'game-anime 'newest range)))
+    ("news.newest.column" .
+     (lambda (range)
+       (mixi-get-news 'column 'newest range)))
     ("news.pickup.domestic" .
      (lambda (range)
        (mixi-get-news 'domestic 'pickup range)))
     ("news.pickup.domestic" .
      (lambda (range)
        (mixi-get-news 'domestic 'pickup range)))
        (mixi-get-news 'entertainment 'pickup range)))
     ("news.pickup.it" .
      (lambda (range)
        (mixi-get-news 'entertainment 'pickup range)))
     ("news.pickup.it" .
      (lambda (range)
-       (mixi-get-news 'IT 'pickup range))))
+       (mixi-get-news 'IT 'pickup range)))
+    ("news.pickup.game-anime" .
+     (lambda (range)
+       (mixi-get-news 'game-anime 'pickup range)))
+    ("news.pickup.column" .
+     (lambda (range)
+       (mixi-get-news 'column 'pickup range)))
+    ("releases" . mixi-get-releases))
   "An alist of mixi shimbun group default definition.")
 
 (defcustom shimbun-mixi-group-alist nil
   "*An alist of mixi shimbun group definition.
 Each element looks like (NAME . URL) or (NAME . FUNCTION).
   "An alist of mixi shimbun group default definition.")
 
 (defcustom shimbun-mixi-group-alist nil
   "*An alist of mixi shimbun group definition.
 Each element looks like (NAME . URL) or (NAME . FUNCTION).
-NAME is a shimbun group name.
+NAME is a shimbun group name that you can name it as you like.
 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.
 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.
@@ -111,12 +131,17 @@ of mixi object."
   :type '(repeat (cons :fromat "%v"
                       (string :tag "Group name")
                       (radio (string :tag "URL")
   :type '(repeat (cons :fromat "%v"
                       (string :tag "Group name")
                       (radio (string :tag "URL")
-                             (const :tag "New diaries" mixi-get-new-diaries)
-                             (const :tag "New comments" mixi-get-new-comments)
-                             (const :tag "New BBSes" mixi-get-new-bbses)
-                             (const :tag "Messages" mixi-get-messages)
-                             (const :tag "Logs" mixi-get-logs)
-                             (function :tag "Other function")))))
+                             (function :tag "Function")))))
+
+(defcustom shimbun-mixi-get-profile-with-diary t
+  "*If non-nil, get his/her profile together with diaries."
+  :group 'shimbun
+  :type 'boolean)
+
+(defcustom shimbun-mixi-add-comment-count-to-author t
+  "*If non-nil, add comment count to author."
+  :group 'shimbun
+  :type 'boolean)
 
 ;; FIXME: Don't use this user option.
 (defcustom shimbun-mixi-page-articles 10
 
 ;; FIXME: Don't use this user option.
 (defcustom shimbun-mixi-page-articles 10
@@ -137,10 +162,13 @@ of mixi object."
                                                &rest init-args)
   (shimbun-mixi-set-comment-cache-internal shimbun
                                           (make-hash-table :test 'equal))
                                                &rest init-args)
   (shimbun-mixi-set-comment-cache-internal shimbun
                                           (make-hash-table :test 'equal))
+  (shimbun-mixi-set-release-cache-internal shimbun
+                                          (make-hash-table :test 'equal))
   shimbun)
 
 (luna-define-method shimbun-close :after ((shimbun shimbun-mixi))
   (shimbun-mixi-set-comment-cache-internal shimbun nil)
   shimbun)
 
 (luna-define-method shimbun-close :after ((shimbun shimbun-mixi))
   (shimbun-mixi-set-comment-cache-internal shimbun nil)
+  (shimbun-mixi-set-release-cache-internal shimbun nil)
   (mixi-logout))
 
 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
   (mixi-logout))
 
 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
@@ -154,6 +182,11 @@ of mixi object."
     (catch 'stop
       (while objects
        (let ((object (car objects)))
     (catch 'stop
       (while objects
        (let ((object (car objects)))
+         (when (and shimbun-mixi-get-profile-with-diary
+                    (mixi-diary-p object))
+           (let ((owner (mixi-diary-owner object)))
+             (unless (mixi-object-realized-p owner)
+               (mixi-realize-friend owner))))
          (when (mixi-parent-p object)
            (let* ((comments (mixi-get-comments object range))
                   (comment-headers (shimbun-mixi-get-headers shimbun
          (when (mixi-parent-p object)
            (let* ((comments (mixi-get-comments object range))
                   (comment-headers (shimbun-mixi-get-headers shimbun
@@ -173,7 +206,7 @@ of mixi object."
                                       "^new-"
                                       (shimbun-current-group-internal
                                        shimbun)))
                                       "^new-"
                                       (shimbun-current-group-internal
                                        shimbun)))
-             (mixi-make-author object)
+             (mixi-make-author object shimbun-mixi-add-comment-count-to-author)
              (mixi-make-date object)
              id
              (if (eq class 'mixi-comment)
              (mixi-make-date object)
              id
              (if (eq class 'mixi-comment)
@@ -192,7 +225,9 @@ of mixi object."
                                         &optional range)
   (let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
                                     (shimbun-mixi-group-alist))))
                                         &optional range)
   (let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
                                     (shimbun-mixi-group-alist))))
-       (range (when (integerp range) (* range shimbun-mixi-page-articles))))
+       (range (shimbun-header-index-pages range)))
+    (when (integerp range)
+      (setq range (* range shimbun-mixi-page-articles)))
     (shimbun-sort-headers
      (shimbun-mixi-get-headers shimbun
                               (mixi-make-objects url-or-function range)
     (shimbun-sort-headers
      (shimbun-mixi-get-headers shimbun
                               (mixi-make-objects url-or-function range)
@@ -214,6 +249,21 @@ of mixi object."
          (setq comments (cdr comments)))))
     article))
 
          (setq comments (cdr comments)))))
     article))
 
+(defun shimbun-mixi-release-article (shimbun header)
+  (let* ((message-id (shimbun-header-id header))
+        (cache (shimbun-mixi-release-cache-internal shimbun))
+        (article (gethash message-id cache)))
+    (unless (stringp article)
+      (let ((releases (mixi-get-releases)))
+       (while releases
+         (let ((id (mixi-make-message-id (car releases)))
+               (content (mixi-release-content (car releases))))
+           (puthash id content cache)
+           (when (string= id message-id)
+             (setq article content)))
+         (setq releases (cdr releases)))))
+    article))
+
 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
                                     header &optional outbuf)
   (when (shimbun-current-group-internal shimbun)
 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
                                     header &optional outbuf)
   (when (shimbun-current-group-internal shimbun)
@@ -222,10 +272,14 @@ of mixi object."
        (or (with-temp-buffer
             (let* ((url (shimbun-article-url shimbun header))
                    (object (mixi-make-object-from-url url))
        (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-mixi-comment-article
-                                 url shimbun header)
-                              (mixi-make-content object))))
+                   (article (cond ((string-match "#comment$" url)
+                                   (shimbun-mixi-comment-article
+                                    url shimbun header))
+                                  ((string-match "release_info.pl$" url)
+                                   (shimbun-mixi-release-article
+                                    shimbun header))
+                                  (t
+                                   (mixi-make-content object)))))
               (mixi-make-reply-to object)
               (when (stringp article)
                 (insert article)))
               (mixi-make-reply-to object)
               (when (stringp article)
                 (insert article)))
@@ -235,33 +289,6 @@ of mixi object."
               (shimbun-message shimbun "shimbun: Make contents...done")))
           "")))))
 
               (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
 (provide 'sb-mixi)
 
 ;;; sb-mixi.el ends here