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 GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; 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.59 $")
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 ("new-bbs-comments" . mixi-get-new-bbs-comments)
47 ("messages" . mixi-get-messages)
50 (mixi-get-messages 'outbox range)))
51 ("logs" . mixi-get-logs)
52 ("my-diaries" . "/home.pl")
53 ("mixi-el" . "/view_community.pl?id=1596390")
54 ("news.newest.domestic" .
56 (mixi-get-news 'domestic 'newest range)))
57 ("news.newest.politics" .
59 (mixi-get-news 'politics 'newest range)))
60 ("news.newest.economy" .
62 (mixi-get-news 'economy 'newest range)))
65 (mixi-get-news 'area 'newest range)))
66 ("news.newest.abroad" .
68 (mixi-get-news 'abroad 'newest range)))
69 ("news.newest.sports" .
71 (mixi-get-news 'sports 'newest range)))
72 ("news.newest.entertainment" .
74 (mixi-get-news 'entertainment 'newest range)))
77 (mixi-get-news 'IT 'newest range)))
78 ("news.pickup.domestic" .
80 (mixi-get-news 'domestic 'pickup range)))
81 ("news.pickup.politics" .
83 (mixi-get-news 'politics 'pickup range)))
84 ("news.pickup.economy" .
86 (mixi-get-news 'economy 'pickup range)))
89 (mixi-get-news 'area 'pickup range)))
90 ("news.pickup.abroad" .
92 (mixi-get-news 'abroad 'pickup range)))
93 ("news.pickup.sports" .
95 (mixi-get-news 'sports 'pickup range)))
96 ("news.pickup.entertainment" .
98 (mixi-get-news 'entertainment 'pickup range)))
101 (mixi-get-news 'IT 'pickup range))))
102 "An alist of mixi shimbun group default definition.")
104 (defcustom shimbun-mixi-group-alist nil
105 "*An alist of mixi shimbun group definition.
106 Each element looks like (NAME . URL) or (NAME . FUNCTION).
107 NAME is a shimbun group name that you can name it as you like.
108 URL is the URL for mixi access point of the group. If URL is friend's, get
109 his/her diaries as article. If community's, get its BBSes. If diary's or
110 BBS's, get its comments.
111 FUNCTION is the function which has one `range' argument and returns the list
114 :type '(repeat (cons :fromat "%v"
115 (string :tag "Group name")
116 (radio (string :tag "URL")
117 (function :tag "Function")))))
119 (defcustom shimbun-mixi-get-profile-with-diary t
120 "*If non-nil, get his/her profile together with diaries."
124 ;; FIXME: Don't use this user option.
125 (defcustom shimbun-mixi-page-articles 10
126 "*How many articles are there in one page."
130 (defvar shimbun-mixi-x-face-alist
131 '(("default" . "X-Face: CY;j#FoBnpK^37`-IoJvN!J^u;GciiPmMQ@T)~RP1]t8iv?v)/bVI:I\"F!JfWJvhM5{zY!=
132 h.d+'g\\I{D>Ocy?Rc4uYUyOZj2%2Kl>,x-!MCSsyi3!L}psrrC1jlF,O?Ui>qf)X;sBz`/}\\066X%$
133 siG'|4K!2?==|oB&#E'5GGH\\#z[muyQ")))
135 (defun shimbun-mixi-group-alist ()
136 (append shimbun-mixi-default-group-alist
137 shimbun-mixi-group-alist))
139 (luna-define-method initialize-instance :after ((shimbun shimbun-mixi)
141 (shimbun-mixi-set-comment-cache-internal shimbun
142 (make-hash-table :test 'equal))
145 (luna-define-method shimbun-close :after ((shimbun shimbun-mixi))
146 (shimbun-mixi-set-comment-cache-internal shimbun nil)
149 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
150 (mapcar 'car (shimbun-mixi-group-alist)))
152 (luna-define-method shimbun-reply-to ((shimbun shimbun-mixi))
155 (defun shimbun-mixi-get-headers (shimbun objects &optional range)
159 (let ((object (car objects)))
160 (when (and shimbun-mixi-get-profile-with-diary
161 (mixi-diary-p object))
162 (let ((owner (mixi-diary-owner object)))
163 (unless (mixi-object-realized-p owner)
164 (mixi-realize-friend owner))))
165 (when (mixi-parent-p object)
166 (let* ((comments (mixi-get-comments object range))
167 (comment-headers (shimbun-mixi-get-headers shimbun
169 (while comment-headers
170 (push (car comment-headers) headers)
171 (setq comment-headers (cdr comment-headers)))))
172 (let ((class (mixi-object-class object))
173 (id (mixi-make-message-id object)))
174 (when (and (eq class 'mixi-comment)
175 (shimbun-search-id shimbun id))
178 (shimbun-create-header
180 (mixi-make-title object (string-match
182 (shimbun-current-group-internal
184 (mixi-make-author object)
185 (mixi-make-date object)
187 (if (eq class 'mixi-comment)
188 (mixi-make-message-id (mixi-comment-parent object))
191 (mixi-make-url object))
193 (when (eq class 'mixi-comment)
194 (puthash id (mixi-comment-content object)
195 (shimbun-mixi-comment-cache-internal shimbun)))))
196 (setq objects (cdr objects))))
199 (luna-define-method shimbun-get-headers ((shimbun shimbun-mixi)
201 (let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
202 (shimbun-mixi-group-alist))))
203 (range (shimbun-header-index-pages range)))
204 (when (integerp range)
205 (setq range (* range shimbun-mixi-page-articles)))
206 (shimbun-sort-headers
207 (shimbun-mixi-get-headers shimbun
208 (mixi-make-objects url-or-function range)
211 (defun shimbun-mixi-comment-article (url shimbun header)
212 (let* ((message-id (shimbun-header-id header))
213 (cache (shimbun-mixi-comment-cache-internal shimbun))
214 (article (gethash message-id cache)))
215 (unless (stringp article)
216 (let* ((parent (mixi-make-object-from-url url))
217 (comments (mixi-get-comments parent)))
219 (let ((id (mixi-make-message-id (car comments)))
220 (content (mixi-comment-content (car comments))))
221 (puthash id content cache)
222 (when (string= id message-id)
223 (setq article content)))
224 (setq comments (cdr comments)))))
227 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
228 header &optional outbuf)
229 (when (shimbun-current-group-internal shimbun)
230 (with-current-buffer (or outbuf (current-buffer))
232 (or (with-temp-buffer
233 (let* ((url (shimbun-article-url shimbun header))
234 (object (mixi-make-object-from-url url))
235 (article (if (string-match "#comment$" url)
236 (shimbun-mixi-comment-article
238 (mixi-make-content object))))
239 (mixi-make-reply-to object)
240 (when (stringp article)
242 (shimbun-message shimbun "shimbun: Make contents...")
243 (goto-char (point-min))
244 (prog1 (shimbun-make-contents shimbun header)
245 (shimbun-message shimbun "shimbun: Make contents...done")))
250 ;;; sb-mixi.el ends here