1 ;;; sb-mixi.el --- shimbun backend for mixi
3 ;; Copyright (C) 2006 OHASHI Akira
5 ;; Author: OHASHI Akira <bg66@koka-in.org>
8 ;; This file is *NOT* a part of shimbun.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; if not, you can either send email to this
22 ;; program's maintainer or write to: The Free Software Foundation,
23 ;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 ;; If you have bug reports and/or suggestions for improvement, please
28 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
36 (luna-define-class shimbun-mixi (shimbun) (comment-cache))
37 (luna-define-internal-accessors 'shimbun-mixi))
39 (defcustom shimbun-mixi-group-alist '(("new-diaries" . mixi-get-new-diaries)
40 ("new-comments" . mixi-get-new-comments)
41 ("new-bbses" . mixi-get-new-bbses)
42 ("messages" . mixi-get-messages)
43 ("my-diaries" . "/home.pl"))
44 "*An alist of mixi shimbun group definition.
45 Each element looks like (NAME . URL) or (NAME . FUNCTION).
46 NAME is a shimbun group name.
47 URL is the URL for mixi access point of the group. When URL is friend's, get
48 his/her diaries as article. When community's, get its BBSes. When diary's
49 or BBS's, get its comments.
50 FUNCTION is the function which has one `range' argument and returns the list
53 :type '(repeat (cons :fromat "%v"
54 (string :tag "Group name")
55 (radio (string :tag "URL")
56 (const :tag "New diaries" mixi-get-new-diaries)
57 (const :tag "New comments" mixi-get-new-comments)
58 (const :tag "New BBSes" mixi-get-new-bbses)
59 (const :tag "Messages" mixi-get-messages)
60 (function :tag "Other function")))))
62 ;; FIXME: Don't use this user option.
63 (defcustom shimbun-mixi-page-articles 10
64 "*How many articles are there in one page."
68 (defcustom shimbun-mixi-get-comment-p t
69 "*If non-nil, get diaries or BBSes together with its comments."
73 (defcustom shimbun-mixi-logout-p nil
74 "*If non-ni, Logout from mixi when shimbun server was closed."
78 (defvar shimbun-mixi-x-face-alist
79 '(("default" . "X-Face: CY;j#FoBnpK^37`-IoJvN!J^u;GciiPmMQ@T)~RP1]t8iv?v)/bVI:I\"F!JfWJvhM5{zY!=
80 h.d+'g\\I{D>Ocy?Rc4uYUyOZj2%2Kl>,x-!MCSsyi3!L}psrrC1jlF,O?Ui>qf)X;sBz`/}\\066X%$
81 siG'|4K!2?==|oB&#E'5GGH\\#z[muyQ")))
83 (luna-define-method initialize-instance :after ((shimbun shimbun-mixi)
85 (shimbun-mixi-set-comment-cache-internal shimbun
86 (make-hash-table :test 'equal))
89 (luna-define-method shimbun-close :after ((shimbun shimbun-mixi))
90 (shimbun-mixi-set-comment-cache-internal shimbun nil)
91 (when shimbun-mixi-logout-p
94 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
95 (mapcar 'car shimbun-mixi-group-alist))
97 (defun shimbun-mixi-make-subject (object)
98 (let ((class (mixi-object-class object)))
99 (cond ((eq class 'mixi-comment)
100 (concat "Re: " (shimbun-mixi-make-subject
101 (mixi-comment-parent object))))
102 (t (mixi-object-title object)))))
104 (defun shimbun-mixi-make-from (object)
105 (let ((owner (mixi-object-owner object)))
106 (mixi-friend-nick owner)))
108 (defun shimbun-mixi-make-date (object)
109 (let* ((time (mixi-object-time object))
110 (cts (current-time-string time))
111 (day-of-week (substring cts 0 3))
112 (month (substring cts 4 7)))
113 (concat day-of-week ", "
114 (format-time-string "%d" time) " "
116 (format-time-string "%Y %H:%M:%S %z" time))))
118 (defun shimbun-mixi-make-message-id (object)
119 (let ((class (mixi-object-class object)))
121 (format-time-string "%Y%m%d%H%M" (mixi-object-time object)) "."
122 (if (eq class 'mixi-comment)
123 (concat (mixi-friend-id (mixi-comment-owner object)) "@"
124 (mixi-object-id (mixi-comment-parent object)) "."
125 (mixi-friend-id (mixi-object-owner
126 (mixi-comment-parent object))) ".")
127 (concat (mixi-object-id object) "@"
128 (mixi-object-id (mixi-object-owner object)) "."))
129 (mixi-object-name object) ".mixi.jp"
132 (defun shimbun-mixi-make-xref (object)
133 (let ((class (mixi-object-class object)))
134 (cond ((eq class 'mixi-diary)
135 (mixi-expand-url (mixi-diary-page object)))
136 ((eq class 'mixi-topic)
137 (mixi-expand-url (mixi-topic-page object)))
138 ((eq class 'mixi-event)
139 (mixi-expand-url (mixi-event-page object)))
140 ((eq class 'mixi-comment)
141 (concat (shimbun-mixi-make-xref (mixi-comment-parent object))
143 ((eq class 'mixi-message)
144 (mixi-expand-url (mixi-message-page object))))))
146 (defun shimbun-mixi-make-body (object)
147 (mixi-object-content object))
149 (defun shimbun-mixi-get-headers (shimbun objects &optional range)
153 (mapc (lambda (object)
154 (when (mixi-object-p object)
155 (let ((class (mixi-object-class object))
156 (id (shimbun-mixi-make-message-id object)))
158 (shimbun-create-header
160 (shimbun-mixi-make-subject object)
161 (shimbun-mixi-make-from object)
162 (shimbun-mixi-make-date object)
164 (if (eq class 'mixi-comment)
165 (shimbun-mixi-make-message-id
166 (mixi-comment-parent object))
169 (shimbun-mixi-make-xref object))
171 (when (and shimbun-mixi-get-comment-p
172 (or (eq class 'mixi-diary)
173 (eq class 'mixi-topic)
174 (eq class 'mixi-event)))
175 (let ((comments (mixi-get-comments object range)))
176 (mapc (lambda (header)
177 (push header headers))
178 (shimbun-mixi-get-headers shimbun
180 (when (eq class 'mixi-comment)
181 (puthash id (mixi-comment-content object)
182 (shimbun-mixi-comment-cache-internal
187 (luna-define-method shimbun-get-headers ((shimbun shimbun-mixi)
189 (let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
190 shimbun-mixi-group-alist)))
191 (range (when (integerp range) (* range shimbun-mixi-page-articles)))
193 (if (stringp url-or-function)
194 (let* ((object (mixi-make-object-from-url url-or-function))
195 (class (mixi-object-class object)))
196 (cond ((eq class 'mixi-friend)
197 (setq objects (mixi-get-diaries object range)))
198 ((eq class 'mixi-community)
199 (setq objects (mixi-get-bbses object range)))
200 ((or (eq class 'mixi-diary)
201 (eq class 'mixi-topic)
202 (eq class 'mixi-event))
203 (setq objects (mixi-get-comments object range)))
204 (t (error (concat (symbol-name class)
205 " is not supported yet.")))))
206 (setq objects (funcall url-or-function range)))
207 (shimbun-sort-headers (shimbun-mixi-get-headers shimbun objects range))))
209 (defun shimbun-comment-article (url shimbun header)
210 (let* ((message-id (shimbun-header-id header))
211 (cache (shimbun-mixi-comment-cache-internal shimbun))
212 (article (gethash message-id cache)))
213 (unless (stringp article)
214 (let ((parent (mixi-make-object-from-url url)))
215 (mapc (lambda (comment)
216 (let ((id (shimbun-mixi-make-message-id comment))
217 ;; FIXME: Concat parent's information?
218 (content (mixi-comment-content comment)))
219 (puthash id content cache)
220 (when (string= id message-id)
221 (setq article content))))
222 (mixi-get-comments parent))))
225 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
226 header &optional outbuf)
227 (when (shimbun-current-group-internal shimbun)
228 (with-current-buffer (or outbuf (current-buffer))
230 (or (with-temp-buffer
231 (let* ((url (shimbun-article-url shimbun header))
232 (article (if (string-match "#comment$" url)
233 (shimbun-comment-article url shimbun header)
234 ;; FIXME: Concat community information?
235 (shimbun-mixi-make-body
236 (mixi-make-object-from-url url)))))
237 (when (stringp article)
239 (shimbun-message shimbun "shimbun: Make contents...")
240 (goto-char (point-min))
241 (prog1 (shimbun-make-contents shimbun header)
242 (shimbun-message shimbun "shimbun: Make contents...done")))
247 ;;; sb-mixi.el ends here