1 ;;; sb-mixi.el --- shimbun backend for mixi
3 ;; Copyright (C) 2006, 2007 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 (defconst shimbun-mixi-revision "$Revision: 1.57 $")
39 (luna-define-class shimbun-mixi (shimbun) (comment-cache))
40 (luna-define-internal-accessors 'shimbun-mixi))
42 (defconst shimbun-mixi-default-group-alist
43 '(("new-diaries" . mixi-get-new-diaries)
44 ("new-comments" . mixi-get-new-comments)
45 ("new-bbses" . mixi-get-new-bbses)
46 ("messages" . mixi-get-messages)
49 (mixi-get-messages 'outbox range)))
50 ("logs" . mixi-get-logs)
51 ("my-diaries" . "/home.pl")
52 ("mixi-el" . "/view_community.pl?id=1596390")
53 ("news.newest.domestic" .
55 (mixi-get-news 'domestic 'newest range)))
56 ("news.newest.politics" .
58 (mixi-get-news 'politics 'newest range)))
59 ("news.newest.economy" .
61 (mixi-get-news 'economy 'newest range)))
64 (mixi-get-news 'area 'newest range)))
65 ("news.newest.abroad" .
67 (mixi-get-news 'abroad 'newest range)))
68 ("news.newest.sports" .
70 (mixi-get-news 'sports 'newest range)))
71 ("news.newest.entertainment" .
73 (mixi-get-news 'entertainment 'newest range)))
76 (mixi-get-news 'IT 'newest range)))
77 ("news.pickup.domestic" .
79 (mixi-get-news 'domestic 'pickup range)))
80 ("news.pickup.politics" .
82 (mixi-get-news 'politics 'pickup range)))
83 ("news.pickup.economy" .
85 (mixi-get-news 'economy 'pickup range)))
88 (mixi-get-news 'area 'pickup range)))
89 ("news.pickup.abroad" .
91 (mixi-get-news 'abroad 'pickup range)))
92 ("news.pickup.sports" .
94 (mixi-get-news 'sports 'pickup range)))
95 ("news.pickup.entertainment" .
97 (mixi-get-news 'entertainment 'pickup range)))
100 (mixi-get-news 'IT 'pickup range))))
101 "An alist of mixi shimbun group default definition.")
103 (defcustom shimbun-mixi-group-alist nil
104 "*An alist of mixi shimbun group definition.
105 Each element looks like (NAME . URL) or (NAME . FUNCTION).
106 NAME is a shimbun group name that you can name it as you like.
107 URL is the URL for mixi access point of the group. If URL is friend's, get
108 his/her diaries as article. If community's, get its BBSes. If diary's or
109 BBS's, get its comments.
110 FUNCTION is the function which has one `range' argument and returns the list
113 :type '(repeat (cons :fromat "%v"
114 (string :tag "Group name")
115 (radio (string :tag "URL")
116 (const :tag "New diaries" mixi-get-new-diaries)
117 (const :tag "New comments" mixi-get-new-comments)
118 (const :tag "New BBSes" mixi-get-new-bbses)
119 (const :tag "Messages" mixi-get-messages)
120 (const :tag "Logs" mixi-get-logs)
121 (function :tag "Other function")))))
123 (defcustom shimbun-mixi-get-profile-with-diary t
124 "*If non-nil, get his/her profile together with diaries."
128 ;; FIXME: Don't use this user option.
129 (defcustom shimbun-mixi-page-articles 10
130 "*How many articles are there in one page."
134 (defvar shimbun-mixi-x-face-alist
135 '(("default" . "X-Face: CY;j#FoBnpK^37`-IoJvN!J^u;GciiPmMQ@T)~RP1]t8iv?v)/bVI:I\"F!JfWJvhM5{zY!=
136 h.d+'g\\I{D>Ocy?Rc4uYUyOZj2%2Kl>,x-!MCSsyi3!L}psrrC1jlF,O?Ui>qf)X;sBz`/}\\066X%$
137 siG'|4K!2?==|oB&#E'5GGH\\#z[muyQ")))
139 (defun shimbun-mixi-group-alist ()
140 (append shimbun-mixi-default-group-alist
141 shimbun-mixi-group-alist))
143 (luna-define-method initialize-instance :after ((shimbun shimbun-mixi)
145 (shimbun-mixi-set-comment-cache-internal shimbun
146 (make-hash-table :test 'equal))
149 (luna-define-method shimbun-close :after ((shimbun shimbun-mixi))
150 (shimbun-mixi-set-comment-cache-internal shimbun nil)
153 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
154 (mapcar 'car (shimbun-mixi-group-alist)))
156 (luna-define-method shimbun-reply-to ((shimbun shimbun-mixi))
159 (defun shimbun-mixi-get-headers (shimbun objects &optional range)
163 (let ((object (car objects)))
164 (when (and shimbun-mixi-get-profile-with-diary
165 (mixi-diary-p object))
166 (let ((owner (mixi-diary-owner object)))
167 (unless (mixi-object-realized-p owner)
168 (mixi-realize-friend owner))))
169 (when (mixi-parent-p object)
170 (let* ((comments (mixi-get-comments object range))
171 (comment-headers (shimbun-mixi-get-headers shimbun
173 (while comment-headers
174 (push (car comment-headers) headers)
175 (setq comment-headers (cdr comment-headers)))))
176 (let ((class (mixi-object-class object))
177 (id (mixi-make-message-id object)))
178 (when (and (eq class 'mixi-comment)
179 (shimbun-search-id shimbun id))
182 (shimbun-create-header
184 (mixi-make-title object (string-match
186 (shimbun-current-group-internal
188 (mixi-make-author object)
189 (mixi-make-date object)
191 (if (eq class 'mixi-comment)
192 (mixi-make-message-id (mixi-comment-parent object))
195 (mixi-make-url object))
197 (when (eq class 'mixi-comment)
198 (puthash id (mixi-comment-content object)
199 (shimbun-mixi-comment-cache-internal shimbun)))))
200 (setq objects (cdr objects))))
203 (luna-define-method shimbun-get-headers ((shimbun shimbun-mixi)
205 (let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
206 (shimbun-mixi-group-alist))))
207 (range (shimbun-header-index-pages range)))
208 (when (integerp range)
209 (setq range (* range shimbun-mixi-page-articles)))
210 (shimbun-sort-headers
211 (shimbun-mixi-get-headers shimbun
212 (mixi-make-objects url-or-function range)
215 (defun shimbun-mixi-comment-article (url shimbun header)
216 (let* ((message-id (shimbun-header-id header))
217 (cache (shimbun-mixi-comment-cache-internal shimbun))
218 (article (gethash message-id cache)))
219 (unless (stringp article)
220 (let* ((parent (mixi-make-object-from-url url))
221 (comments (mixi-get-comments parent)))
223 (let ((id (mixi-make-message-id (car comments)))
224 (content (mixi-comment-content (car comments))))
225 (puthash id content cache)
226 (when (string= id message-id)
227 (setq article content)))
228 (setq comments (cdr comments)))))
231 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
232 header &optional outbuf)
233 (when (shimbun-current-group-internal shimbun)
234 (with-current-buffer (or outbuf (current-buffer))
236 (or (with-temp-buffer
237 (let* ((url (shimbun-article-url shimbun header))
238 (object (mixi-make-object-from-url url))
239 (article (if (string-match "#comment$" url)
240 (shimbun-mixi-comment-article
242 (mixi-make-content object))))
243 (mixi-make-reply-to object)
244 (when (stringp article)
246 (shimbun-message shimbun "shimbun: Make contents...")
247 (goto-char (point-min))
248 (prog1 (shimbun-make-contents shimbun header)
249 (shimbun-message shimbun "shimbun: Make contents...done")))
254 ;;; sb-mixi.el ends here