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>.
37 (luna-define-class shimbun-mixi (shimbun) (comment-cache))
38 (luna-define-internal-accessors 'shimbun-mixi))
40 (defcustom shimbun-mixi-group-alist
41 '(("new-diaries" . mixi-get-new-diaries)
42 ("new-comments" . mixi-get-new-comments)
43 ("new-bbses" . mixi-get-new-bbses)
44 ("messages" . mixi-get-messages)
47 (mixi-get-messages 'outbox range)))
48 ("logs" . mixi-get-logs)
49 ("my-diaries" . "/home.pl")
50 ("mixi-el" . "/view_community.pl?id=1596390")
51 ("news.newest.domestic" .
53 (mixi-get-news 'domestic 'newest range)))
54 ("news.newest.politics" .
56 (mixi-get-news 'politics 'newest range)))
57 ("news.newest.economy" .
59 (mixi-get-news 'economy 'newest range)))
62 (mixi-get-news 'area 'newest range)))
63 ("news.newest.abroad" .
65 (mixi-get-news 'abroad 'newest range)))
66 ("news.newest.sports" .
68 (mixi-get-news 'sports 'newest range)))
69 ("news.newest.entertainment" .
71 (mixi-get-news 'entertainment 'newest range)))
74 (mixi-get-news 'IT 'newest range)))
75 ("news.pickup.domestic" .
77 (mixi-get-news 'domestic 'pickup range)))
78 ("news.pickup.politics" .
80 (mixi-get-news 'politics 'pickup range)))
81 ("news.pickup.economy" .
83 (mixi-get-news 'economy 'pickup range)))
86 (mixi-get-news 'area 'pickup range)))
87 ("news.pickup.abroad" .
89 (mixi-get-news 'abroad 'pickup range)))
90 ("news.pickup.sports" .
92 (mixi-get-news 'sports 'pickup range)))
93 ("news.pickup.entertainment" .
95 (mixi-get-news 'entertainment 'pickup range)))
98 (mixi-get-news 'IT 'pickup range))))
99 "*An alist of mixi shimbun group definition.
100 Each element looks like (NAME . URL) or (NAME . FUNCTION).
101 NAME is a shimbun group name.
102 URL is the URL for mixi access point of the group. If URL is friend's, get
103 his/her diaries as article. If community's, get its BBSes. If diary's or
104 BBS's, get its comments.
105 FUNCTION is the function which has one `range' argument and returns the list
108 :type '(repeat (cons :fromat "%v"
109 (string :tag "Group name")
110 (radio (string :tag "URL")
111 (const :tag "New diaries" mixi-get-new-diaries)
112 (const :tag "New comments" mixi-get-new-comments)
113 (const :tag "New BBSes" mixi-get-new-bbses)
114 (const :tag "Messages" mixi-get-messages)
115 (const :tag "Logs" mixi-get-logs)
116 (function :tag "Other function")))))
118 ;; FIXME: Don't use this user option.
119 (defcustom shimbun-mixi-page-articles 10
120 "*How many articles are there in one page."
124 (defvar shimbun-mixi-x-face-alist
125 '(("default" . "X-Face: CY;j#FoBnpK^37`-IoJvN!J^u;GciiPmMQ@T)~RP1]t8iv?v)/bVI:I\"F!JfWJvhM5{zY!=
126 h.d+'g\\I{D>Ocy?Rc4uYUyOZj2%2Kl>,x-!MCSsyi3!L}psrrC1jlF,O?Ui>qf)X;sBz`/}\\066X%$
127 siG'|4K!2?==|oB&#E'5GGH\\#z[muyQ")))
129 (luna-define-method initialize-instance :after ((shimbun shimbun-mixi)
131 (shimbun-mixi-set-comment-cache-internal shimbun
132 (make-hash-table :test 'equal))
135 (luna-define-method shimbun-close :after ((shimbun shimbun-mixi))
136 (shimbun-mixi-set-comment-cache-internal shimbun nil)
139 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
140 (mapcar 'car shimbun-mixi-group-alist))
142 (luna-define-method shimbun-reply-to ((shimbun shimbun-mixi))
145 (defun shimbun-mixi-get-headers (shimbun objects &optional range)
149 (let ((object (car objects)))
150 (when (mixi-parent-p object)
151 (let* ((comments (mixi-get-comments object range))
152 (comment-headers (shimbun-mixi-get-headers shimbun
154 (while comment-headers
155 (push (car comment-headers) headers)
156 (setq comment-headers (cdr comment-headers)))))
157 (let ((class (mixi-object-class object))
158 (id (mixi-make-message-id object)))
159 (when (and (eq class 'mixi-comment)
160 (shimbun-search-id shimbun id))
163 (shimbun-create-header
165 (mixi-make-title object (string-match
167 (shimbun-current-group-internal
169 (mixi-make-author object)
170 (mixi-make-date object)
172 (if (eq class 'mixi-comment)
173 (mixi-make-message-id (mixi-comment-parent object))
176 (mixi-make-url object))
178 (when (eq class 'mixi-comment)
179 (puthash id (mixi-comment-content object)
180 (shimbun-mixi-comment-cache-internal shimbun)))))
181 (setq objects (cdr objects))))
184 (luna-define-method shimbun-get-headers ((shimbun shimbun-mixi)
186 (let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
187 shimbun-mixi-group-alist)))
188 (range (when (integerp range) (* range shimbun-mixi-page-articles))))
189 (shimbun-sort-headers
190 (shimbun-mixi-get-headers shimbun
191 (mixi-make-objects url-or-function range)
194 (defun shimbun-mixi-comment-article (url shimbun header)
195 (let* ((message-id (shimbun-header-id header))
196 (cache (shimbun-mixi-comment-cache-internal shimbun))
197 (article (gethash message-id cache)))
198 (unless (stringp article)
199 (let* ((parent (mixi-make-object-from-url url))
200 (comments (mixi-get-comments parent)))
202 (let ((id (mixi-make-message-id (car comments)))
203 (content (mixi-comment-content (car comments))))
204 (puthash id content cache)
205 (when (string= id message-id)
206 (setq article content)))
207 (setq comments (cdr comments)))))
210 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
211 header &optional outbuf)
212 (when (shimbun-current-group-internal shimbun)
213 (with-current-buffer (or outbuf (current-buffer))
215 (or (with-temp-buffer
216 (let* ((url (shimbun-article-url shimbun header))
217 (object (mixi-make-object-from-url url))
218 (article (if (string-match "#comment$" url)
219 (shimbun-mixi-comment-article
221 (mixi-make-content object))))
222 (mixi-make-reply-to object)
223 (when (stringp article)
225 (shimbun-message shimbun "shimbun: Make contents...")
226 (goto-char (point-min))
227 (prog1 (shimbun-make-contents shimbun header)
228 (shimbun-message shimbun "shimbun: Make contents...done")))
231 (defconst shimbun-mixi-to-regexp
232 "^mixi;\\([a-z]+\\);?\\([a-z0-9]+\\)?;?\\([0-9]+\\)?;?\\([0-9]+\\)?")
234 (defun shimbun-mixi-send-mail (to title content)
235 (when (string-match shimbun-mixi-to-regexp to)
236 (let ((method (match-string 1 to)))
237 (cond ((string= method "comment")
238 (let ((parent (match-string 2 to))
239 (owner-id (match-string 3 to))
240 (id (match-string 4 to)))
241 (if (string= parent "diary")
243 (mixi-make-diary (mixi-make-friend owner-id) id) content)
245 (concat mixi-object-prefix "make-" parent))))
247 (funcall func (mixi-make-community owner-id) id)
249 ((string= method "topic")
250 (mixi-post-topic (mixi-make-community (match-string 2 to))
252 ((string= method "diary")
253 (mixi-post-diary title content))
254 ((string= method "message")
255 (mixi-post-message (mixi-make-friend (match-string 2 to))
260 ;;; sb-mixi.el ends here