X-Git-Url: http://git.chise.org/gitweb/?p=elisp%2Fmixi.git;a=blobdiff_plain;f=sb-mixi.el;h=259a31fc21f004742dba78539c2a2f7fd20e552c;hp=d6709c834cc16fc3a6ee55a2ea0cd2a534593218;hb=024ab7527bb1ed840213038225cd4ae4f03285bd;hpb=2e16e94875c737bd83bac80bb95d215bd8b6aa2d diff --git a/sb-mixi.el b/sb-mixi.el index d6709c8..259a31f 100644 --- a/sb-mixi.el +++ b/sb-mixi.el @@ -1,6 +1,6 @@ ;;; sb-mixi.el --- shimbun backend for mixi -;; Copyright (C) 2006 OHASHI Akira +;; Copyright (C) 2006, 2007, 2008 OHASHI Akira ;; Author: OHASHI Akira ;; Keywords: news @@ -18,171 +18,247 @@ ;; 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: +;; If you have bug reports and/or suggestions for improvement, please +;; send them via . + ;;; Code: (require 'mixi) +(require 'mixi-utils) (require 'shimbun) -(luna-define-class shimbun-mixi (shimbun) ()) +(defconst shimbun-mixi-revision "$Revision: 1.63 $") + +(eval-and-compile + (luna-define-class shimbun-mixi (shimbun) (comment-cache release-cache)) + (luna-define-internal-accessors 'shimbun-mixi)) -(defcustom shimbun-mixi-group-alist '(("new-diaries" . mixi-get-new-diaries) - ("new-comments" . mixi-get-new-comments) -; ("new-topics" . mixi-get-new-topics) - ("messages" . mixi-get-messages) - ("my-diaries" . "/home.pl")) +(defconst shimbun-mixi-default-group-alist + '(("new-diaries" . mixi-get-new-diaries) + ("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))) + ("logs" . mixi-get-logs) + ("my-diaries" . "/home.pl") + ("mixi-el" . "/view_community.pl?id=1596390") + ("news.newest.domestic" . + (lambda (range) + (mixi-get-news 'domestic 'newest range))) + ("news.newest.politics" . + (lambda (range) + (mixi-get-news 'politics 'newest range))) + ("news.newest.economy" . + (lambda (range) + (mixi-get-news 'economy 'newest range))) + ("news.newest.area" . + (lambda (range) + (mixi-get-news 'area 'newest range))) + ("news.newest.abroad" . + (lambda (range) + (mixi-get-news 'abroad 'newest range))) + ("news.newest.sports" . + (lambda (range) + (mixi-get-news 'sports 'newest range))) + ("news.newest.entertainment" . + (lambda (range) + (mixi-get-news 'entertainment '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.politics" . + (lambda (range) + (mixi-get-news 'politics 'pickup range))) + ("news.pickup.economy" . + (lambda (range) + (mixi-get-news 'economy 'pickup range))) + ("news.pickup.area" . + (lambda (range) + (mixi-get-news 'area 'pickup range))) + ("news.pickup.abroad" . + (lambda (range) + (mixi-get-news 'abroad 'pickup range))) + ("news.pickup.sports" . + (lambda (range) + (mixi-get-news 'sports 'pickup range))) + ("news.pickup.entertainment" . + (lambda (range) + (mixi-get-news 'entertainment 'pickup range))) + ("news.pickup.it" . + (lambda (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). -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 topics. When diary's -or topic's, get its comments. -FUNCTION is the function for getting articles." +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. +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") (radio (string :tag "URL") - (const :tag "New diaries" mixi-get-new-diaries) - (const :tag "New comments" mixi-get-new-comments) - (const :tag "New topics" mixi-get-new-topics) - (const :tag "Messages" mixi-get-messages) - (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 "*How many articles are there in one page." :group 'shimbun :type 'integer) +(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"))) + +(defun shimbun-mixi-group-alist () + (append shimbun-mixi-default-group-alist + shimbun-mixi-group-alist)) + +(luna-define-method initialize-instance :after ((shimbun shimbun-mixi) + &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-mixi-set-release-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) - (let ((class (mixi-object-class object))) - (if (eq class 'mixi-comment) - (concat "Re: " (mixi-object-title (mixi-comment-parent object))) - (mixi-object-title object)))) - -(defun shimbun-mixi-make-from (object) - (let ((owner (mixi-object-owner object))) - (mixi-friend-nick owner))) - -(defun shimbun-mixi-make-date (object) - (let* ((time (mixi-object-time object)) - (cts (current-time-string time)) - (day-of-week (substring cts 0 3)) - (month (substring cts 4 7))) - (concat day-of-week ", " - (format-time-string "%d" time) " " - month " " - (format-time-string "%Y %H:%M:%S %z" time)))) - -(defun shimbun-mixi-make-message-id (object) - (let ((class (mixi-object-class object))) - (concat "<" - (format-time-string "%Y%m%d%H%M" (mixi-object-time object)) "." - (if (eq class 'mixi-comment) - (concat (mixi-friend-id (mixi-comment-owner object)) "@" - (mixi-object-id (mixi-comment-parent object)) "." - (mixi-friend-id (mixi-object-owner - (mixi-comment-parent object))) ".") - (concat (mixi-object-id object) "@" - (mixi-object-id (mixi-object-owner object)) ".")) - (mixi-object-name object) ".mixi.jp" - ">"))) - -(defun shimbun-mixi-make-xref (object) - (let ((class (mixi-object-class object))) - (cond ((eq class 'mixi-diary) - (mixi-expand-url (mixi-diary-page object))) - ((eq class 'mixi-topic) - (mixi-expand-url (mixi-topic-page object))) - ((eq class 'mixi-comment) - (concat (shimbun-mixi-make-xref (mixi-comment-parent object)) - "#comment")) - ((eq class 'mixi-message) - (mixi-expand-url (mixi-message-page object)))))) + (mapcar 'car (shimbun-mixi-group-alist))) + +(luna-define-method shimbun-reply-to ((shimbun shimbun-mixi)) + mixi-reply-to) (defun shimbun-mixi-get-headers (shimbun objects &optional range) - (when objects - (let (headers) - (catch 'stop - (mapc (lambda (object) - (when (mixi-object-p object) - (let ((class (mixi-object-class object)) - (id (shimbun-mixi-make-message-id object))) - (when (and (eq class 'mixi-comment) - (shimbun-search-id shimbun id)) - (throw 'stop nil)) - (push - (shimbun-create-header - 0 - (shimbun-mixi-make-subject object) - (shimbun-mixi-make-from object) - (shimbun-mixi-make-date object) - id - (if (eq class 'mixi-comment) - (shimbun-mixi-make-message-id - (mixi-comment-parent object)) - "") - 0 0 - (shimbun-mixi-make-xref object)) - headers) - (when (or (eq class 'mixi-diary) - (eq class 'mixi-topic)) - (let ((comments (mixi-get-comments object range))) - (mapc (lambda (header) - (push header headers)) - (shimbun-mixi-get-headers shimbun - comments))))))) - objects)) - headers))) + (let (headers) + (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 + comments))) + (while comment-headers + (push (car comment-headers) headers) + (setq comment-headers (cdr comment-headers))))) + (let ((class (mixi-object-class object)) + (id (mixi-make-message-id object))) + (when (and (eq class 'mixi-comment) + (shimbun-search-id shimbun id)) + (throw 'stop nil)) + (push + (shimbun-create-header + 0 + (mixi-make-title object (string-match + "^new-" + (shimbun-current-group-internal + shimbun))) + (mixi-make-author object shimbun-mixi-add-comment-count-to-author) + (mixi-make-date object) + id + (if (eq class 'mixi-comment) + (mixi-make-message-id (mixi-comment-parent object)) + "") + 0 0 + (mixi-make-url object)) + headers) + (when (eq class 'mixi-comment) + (puthash id (mixi-comment-content object) + (shimbun-mixi-comment-cache-internal shimbun))))) + (setq objects (cdr objects)))) + headers)) (luna-define-method shimbun-get-headers ((shimbun shimbun-mixi) &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))) - objects) - (if (stringp url-or-function) - (let* ((object (mixi-make-object-from-url url-or-function)) - (class (mixi-object-class object))) - (cond ((eq class 'mixi-friend) - (setq objects (mixi-get-diaries object range))) - ((eq class 'mixi-community) - (setq objects (mixi-get-topics object range))) - ((or (eq class 'mixi-diary) (eq class 'mixi-topic)) - (setq objects (mixi-get-comments object range))) - (t (error (concat (symbol-name class) - " is not supported yet."))))) - (when (fboundp url-or-function) - (setq objects (funcall url-or-function range)))) - (shimbun-sort-headers (shimbun-mixi-get-headers shimbun objects range)))) - -(defun shimbun-comment-article (url header) - (let ((parent (mixi-make-object-from-url url)) - (date (shimbun-header-date header)) - (from (shimbun-header-from header))) - (catch 'found - (mapc (lambda (comment) - (let ((nick (mixi-friend-nick (mixi-comment-owner comment))) - (time (shimbun-mixi-make-date comment)) - nick2) - ;; FIXME: How tricky it is. - (when (string-match "\\(.+\\)¤µ¤ó$" nick) - (setq nick2 (match-string 1 nick))) - (when (and - (or (string= (shimbun-mime-encode-string nick) from) - (string= (shimbun-mime-encode-string nick2) from)) - (string= time date)) - ;; FIXME: Concat parent's information? - (throw 'found (mixi-comment-content comment))))) - ;; FIXME: Limit range? - (mixi-get-comments parent))))) + (shimbun-mixi-group-alist)))) + (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) + range)))) + +(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)) + (comments (mixi-get-comments parent))) + (while comments + (let ((id (mixi-make-message-id (car comments))) + (content (mixi-comment-content (car comments)))) + (puthash id content cache) + (when (string= id message-id) + (setq article content))) + (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) @@ -191,11 +267,16 @@ FUNCTION is the function for getting articles." (w3m-insert-string (or (with-temp-buffer (let* ((url (shimbun-article-url shimbun header)) - (article (if (string-match "#comment$" url) - (shimbun-comment-article url header) - ;; FIXME: Concat community information? - (mixi-object-content - (mixi-make-object-from-url url))))) + (object (mixi-make-object-from-url url)) + (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))) (shimbun-message shimbun "shimbun: Make contents...")