X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=sb-mixi.el;h=a346df2823a1dd7add49711a51911125defa1aa7;hb=dc9d1f707c9eef0154a63ff4107fbd1f21aa3e9a;hp=cf775b1ceb2941f27eb89247659829440d26c0ed;hpb=911863744d5e6f107b5eb484faa5dcf01e9f114c;p=elisp%2Fmixi.git diff --git a/sb-mixi.el b/sb-mixi.el index cf775b1..a346df2 100644 --- a/sb-mixi.el +++ b/sb-mixi.el @@ -24,52 +24,154 @@ ;;; Commentary: +;; If you have bug reports and/or suggestions for improvement, please +;; send them via . + ;;; Code: (require 'mixi) (require 'shimbun) -(luna-define-class shimbun-mixi (shimbun) ()) +(eval-and-compile + (luna-define-class shimbun-mixi (shimbun) (comment-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")) +(defcustom shimbun-mixi-group-alist + '(("new-diaries" . mixi-get-new-diaries) + ("new-comments" . mixi-get-new-comments) + ("new-bbses" . mixi-get-new-bbses) + ("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.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)))) "*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." +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 "New BBSes" mixi-get-new-bbses) (const :tag "Messages" mixi-get-messages) (function :tag "Other function"))))) +;; 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"))) + +(defvar shimbun-mixi-reply-to nil) + +(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) + +(luna-define-method shimbun-close :after ((shimbun shimbun-mixi)) + (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))) - (if (eq class 'mixi-comment) - (concat "Re: " (mixi-object-title (mixi-comment-parent object))) - (mixi-object-title object)))) + (cond ((eq class 'mixi-comment) + (concat "Re: " (shimbun-mixi-make-subject + shimbun (mixi-comment-parent object)))) + ((eq class 'mixi-log) + (mixi-friend-nick (mixi-log-friend object))) + (t + (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))) - (mixi-friend-nick owner))) + (let ((class (mixi-object-class object))) + (if (eq class 'mixi-news) + (mixi-news-media object) + (let ((owner (if (eq class 'mixi-log) + (mixi-log-friend object) + (mixi-object-owner object)))) + (mixi-friend-nick owner))))) (defun shimbun-mixi-make-date (object) (let* ((time (mixi-object-time object)) @@ -83,17 +185,21 @@ FUNCTION is the function for getting articles." (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" - ">"))) + (concat + (format-time-string "<%Y%m%d%H%M" (mixi-object-time object)) "." + (cond ((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))) ".")) + ((eq class 'mixi-log) + (concat (mixi-friend-id (mixi-log-friend object)) "@")) + (t + (concat (mixi-object-id object) "@" + (if (eq class 'mixi-news) + (mixi-news-media-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))) @@ -101,11 +207,105 @@ FUNCTION is the function for getting articles." (mixi-expand-url (mixi-diary-page object))) ((eq class 'mixi-topic) (mixi-expand-url (mixi-topic-page object))) + ((eq class 'mixi-event) + (mixi-expand-url (mixi-event-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)))))) + (mixi-expand-url (mixi-message-page object))) + ((eq class 'mixi-news) + (mixi-news-page object)) + ((eq class 'mixi-log) + (mixi-expand-url (mixi-friend-page (mixi-log-friend object)))) + ((eq class 'mixi-friend) + (mixi-expand-url (mixi-friend-page object)))))) + +(defun shimbun-mixi-make-body (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 "
" + "
³«ºÅÆü»þ¡§
" + "
" (mixi-event-date object) "
\n" + "
³«ºÅ¾ì½ê¡§
" + "
" (mixi-event-place object) "
\n" + "
¾ÜºÙ¡§
" + "
" (mixi-event-detail object) "
\n" + "
Ê罸´ü¸Â¡§
" + "
" limit "
\n" + "
»²²Ã¼Ô¡§
" + "
" (mixi-event-members object) "
\n" + "
"))) + ((eq class 'mixi-friend) + (if (mixi-object-realized-p object) + (let ((sex (if (eq (mixi-friend-sex object) 'male) "ÃË" "½÷")) + (age (number-to-string (mixi-friend-age object))) + (birthday + (concat (mapconcat (lambda (number) + (number-to-string number)) + (mixi-friend-birthday object) "·î") + "Æü")) + (blood-type (symbol-name + (mixi-friend-blood-type object))) + (hobby (mapconcat 'identity + (mixi-friend-hobby object) ", "))) + (concat "
" + "
̾Á°¡§
" + "
" (mixi-friend-name object) "
\n" + "
À­ÊÌ¡§
" + "
" sex "À­
\n" + "
¸½½»½ê¡§
" + "
" (mixi-friend-address object) "
\n" + "
ǯÎð¡§
" + "
" age "ºÐ
\n" + "
ÃÂÀ¸Æü¡§
" + "
" birthday "
\n" + "
·ì±Õ·¿¡§
" + "
" blood-type "·¿
\n" + "
½Ð¿ÈÃÏ¡§
" + "
" (mixi-friend-birthplace object) "
\n" + "
¼ñÌ£¡§
" + "
" hobby "
\n" + "
¿¦¶È¡§
" + "
" (mixi-friend-job object) "
\n" + "
½ê°¡§
" + "
" (mixi-friend-organization object) "
\n" + "
¼«¸Ê¾Ò²ð¡§
" + "
" (mixi-friend-profile object) "
\n" + "
")) + (concat "¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë"))) + (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))) + ((or (eq class 'mixi-news) (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 @@ -113,32 +313,35 @@ FUNCTION is the function for getting articles." (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 ((class (mixi-object-class object))) + (when (mixi-parent-p object) (let ((comments (mixi-get-comments object range))) (mapc (lambda (header) (push header headers)) (shimbun-mixi-get-headers shimbun - comments))))))) + comments)))) + (let ((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 shimbun 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 (eq class 'mixi-comment) + (puthash id (mixi-comment-content object) + (shimbun-mixi-comment-cache-internal + shimbun))))))) objects)) headers))) @@ -154,35 +357,28 @@ FUNCTION is the function for getting articles." (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-bbses object range))) + ((mixi-parent-p object) (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)))) + (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))))) +(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 (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) @@ -191,11 +387,12 @@ FUNCTION is the function for getting articles." (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 header) - ;; FIXME: Concat community information? - (mixi-object-content - (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...") @@ -204,6 +401,33 @@ FUNCTION is the function for getting articles." (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