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>.
35 (luna-define-class shimbun-mixi (shimbun) ())
37 (defcustom shimbun-mixi-group-alist '(("new-diaries" . mixi-get-new-diaries)
38 ("new-comments" . mixi-get-new-comments)
39 ("new-bbses" . mixi-get-new-bbses)
40 ("messages" . mixi-get-messages)
41 ("my-diaries" . "/home.pl"))
42 "*An alist of mixi shimbun group definition.
43 Each element looks like (NAME . URL) or (NAME . FUNCTION).
44 NAME is a shimbun group name.
45 URL is the URL for mixi access point of the group. When URL is friend's, get
46 his/her diaries as article. When community's, get its BBSes. When diary's
47 or BBS's, get its comments.
48 FUNCTION is the function for getting articles."
50 :type '(repeat (cons :fromat "%v"
51 (string :tag "Group name")
52 (radio (string :tag "URL")
53 (const :tag "New diaries" mixi-get-new-diaries)
54 (const :tag "New comments" mixi-get-new-comments)
55 (const :tag "New BBSes" mixi-get-new-bbses)
56 (const :tag "Messages" mixi-get-messages)
57 (function :tag "Other function")))))
59 ;; FIXME: Don't use this user option.
60 (defcustom shimbun-mixi-page-articles 10
61 "*How many articles are there in one page."
65 (defcustom shimbun-mixi-get-comment-p t
66 "*If non-nil, get diaries or BBSes together with its comments."
70 (defvar shimbun-mixi-x-face-alist
71 '(("default" . "X-Face: CY;j#FoBnpK^37`-IoJvN!J^u;GciiPmMQ@T)~RP1]t8iv?v)/bVI:I\"F!JfWJvhM5{zY!=
72 h.d+'g\I{D>Ocy?Rc4uYUyOZj2%2Kl>,x-!MCSsyi3!L}psrrC1jlF,O?Ui>qf)X;sBz`/}\066X%$
73 siG'|4K!2?==|oB&#E'5GGH\#z[muyQ")))
75 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
76 (mapcar 'car shimbun-mixi-group-alist))
78 (defun shimbun-mixi-make-subject (object)
79 (let ((class (mixi-object-class object)))
80 (cond ((eq class 'mixi-comment)
81 (concat "Re: " (shimbun-mixi-make-subject
82 (mixi-comment-parent object))))
83 (t (mixi-object-title object)))))
85 (defun shimbun-mixi-make-from (object)
86 (let ((owner (mixi-object-owner object)))
87 (mixi-friend-nick owner)))
89 (defun shimbun-mixi-make-date (object)
90 (let* ((time (mixi-object-time object))
91 (cts (current-time-string time))
92 (day-of-week (substring cts 0 3))
93 (month (substring cts 4 7)))
94 (concat day-of-week ", "
95 (format-time-string "%d" time) " "
97 (format-time-string "%Y %H:%M:%S %z" time))))
99 (defun shimbun-mixi-make-message-id (object)
100 (let ((class (mixi-object-class object)))
102 (format-time-string "%Y%m%d%H%M" (mixi-object-time object)) "."
103 (if (eq class 'mixi-comment)
104 (concat (mixi-friend-id (mixi-comment-owner object)) "@"
105 (mixi-object-id (mixi-comment-parent object)) "."
106 (mixi-friend-id (mixi-object-owner
107 (mixi-comment-parent object))) ".")
108 (concat (mixi-object-id object) "@"
109 (mixi-object-id (mixi-object-owner object)) "."))
110 (mixi-object-name object) ".mixi.jp"
113 (defun shimbun-mixi-make-xref (object)
114 (let ((class (mixi-object-class object)))
115 (cond ((eq class 'mixi-diary)
116 (mixi-expand-url (mixi-diary-page object)))
117 ((eq class 'mixi-topic)
118 (mixi-expand-url (mixi-topic-page object)))
119 ((eq class 'mixi-event)
120 (mixi-expand-url (mixi-event-page object)))
121 ((eq class 'mixi-comment)
122 (concat (shimbun-mixi-make-xref (mixi-comment-parent object))
124 ((eq class 'mixi-message)
125 (mixi-expand-url (mixi-message-page object))))))
127 (defun shimbun-mixi-make-body (object)
128 (mixi-object-content object))
130 (defun shimbun-mixi-get-headers (shimbun objects &optional range)
134 (mapc (lambda (object)
135 (when (mixi-object-p object)
136 (let ((class (mixi-object-class object))
137 (id (shimbun-mixi-make-message-id object)))
139 (shimbun-create-header
141 (shimbun-mixi-make-subject object)
142 (shimbun-mixi-make-from object)
143 (shimbun-mixi-make-date object)
145 (if (eq class 'mixi-comment)
146 (shimbun-mixi-make-message-id
147 (mixi-comment-parent object))
150 (shimbun-mixi-make-xref object))
152 (when (and shimbun-mixi-get-comment-p
153 (or (eq class 'mixi-diary)
154 (eq class 'mixi-topic)
155 (eq class 'mixi-event)))
156 (let ((comments (mixi-get-comments object range)))
157 (mapc (lambda (header)
158 (push header headers))
159 (shimbun-mixi-get-headers shimbun
164 (luna-define-method shimbun-get-headers ((shimbun shimbun-mixi)
166 (let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
167 shimbun-mixi-group-alist)))
168 (range (when (integerp range) (* range shimbun-mixi-page-articles)))
170 (if (stringp url-or-function)
171 (let* ((object (mixi-make-object-from-url url-or-function))
172 (class (mixi-object-class object)))
173 (cond ((eq class 'mixi-friend)
174 (setq objects (mixi-get-diaries object range)))
175 ((eq class 'mixi-community)
176 (setq objects (mixi-get-bbses object range)))
177 ((or (eq class 'mixi-diary)
178 (eq class 'mixi-topic)
179 (eq class 'mixi-event))
180 (setq objects (mixi-get-comments object range)))
181 (t (error (concat (symbol-name class)
182 " is not supported yet.")))))
183 (setq objects (funcall url-or-function range)))
184 (shimbun-sort-headers (shimbun-mixi-get-headers shimbun objects range))))
186 (defun shimbun-comment-article (url header)
187 (let ((parent (mixi-make-object-from-url url))
188 (date (shimbun-header-date header))
189 (message-id (shimbun-header-id header)))
191 (mapc (lambda (comment)
192 (let ((id (mixi-friend-id (mixi-comment-owner comment)))
193 (time (shimbun-mixi-make-date comment)))
194 (when (and (string= time date)
195 (string-match (concat "^<[0-9]+\\." id "@")
197 ;; FIXME: Concat parent's information?
198 (throw 'found (mixi-comment-content comment)))))
199 (mixi-get-comments parent)))))
201 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
202 header &optional outbuf)
203 (when (shimbun-current-group-internal shimbun)
204 (with-current-buffer (or outbuf (current-buffer))
206 (or (with-temp-buffer
207 (let* ((url (shimbun-article-url shimbun header))
208 (article (if (string-match "#comment$" url)
209 (shimbun-comment-article url header)
210 ;; FIXME: Concat community information?
211 (shimbun-mixi-make-body
212 (mixi-make-object-from-url url)))))
213 (when (stringp article)
215 (shimbun-message shimbun "shimbun: Make contents...")
216 (goto-char (point-min))
217 (prog1 (shimbun-make-contents shimbun header)
218 (shimbun-message shimbun "shimbun: Make contents...done")))
223 ;;; sb-mixi.el ends here