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.
32 (luna-define-class shimbun-mixi (shimbun) ())
34 (defcustom shimbun-mixi-group-alist '(("new-diaries" . mixi-get-new-diaries)
35 ("new-comments" . mixi-get-new-comments)
36 ("new-bbses" . mixi-get-new-bbses)
37 ("messages" . mixi-get-messages)
38 ("my-diaries" . "/home.pl"))
39 "*An alist of mixi shimbun group definition.
40 Each element looks like (NAME . URL) or (NAME . FUNCTION).
41 NAME is a shimbun group name.
42 URL is the URL for mixi access point of the group. When URL is friend's, get
43 his/her diaries as article. When community's, get its BBSes. When diary's
44 or BBS's, get its comments.
45 FUNCTION is the function for getting articles."
47 :type '(repeat (cons :fromat "%v"
48 (string :tag "Group name")
49 (radio (string :tag "URL")
50 (const :tag "New diaries" mixi-get-new-diaries)
51 (const :tag "New comments" mixi-get-new-comments)
52 (const :tag "New BBSes" mixi-get-new-bbses)
53 (const :tag "Messages" mixi-get-messages)
54 (function :tag "Other function")))))
56 ;; FIXME: Don't use this user option.
57 (defcustom shimbun-mixi-page-articles 10
58 "*How many articles are there in one page."
62 (defcustom shimbun-mixi-get-comment-p t
63 "*If non-nil, get diaries or BBSes together with its comments."
67 (luna-define-method shimbun-groups ((shimbun shimbun-mixi))
68 (mapcar 'car shimbun-mixi-group-alist))
70 (defun shimbun-mixi-make-subject (object)
71 (let ((class (mixi-object-class object)))
72 (cond ((eq class 'mixi-comment)
73 (concat "Re: " (shimbun-mixi-make-subject
74 (mixi-comment-parent object))))
75 (t (mixi-object-title object)))))
77 (defun shimbun-mixi-make-from (object)
78 (let ((owner (mixi-object-owner object)))
79 (mixi-friend-nick owner)))
81 (defun shimbun-mixi-make-date (object)
82 (let* ((time (mixi-object-time object))
83 (cts (current-time-string time))
84 (day-of-week (substring cts 0 3))
85 (month (substring cts 4 7)))
86 (concat day-of-week ", "
87 (format-time-string "%d" time) " "
89 (format-time-string "%Y %H:%M:%S %z" time))))
91 (defun shimbun-mixi-make-message-id (object)
92 (let ((class (mixi-object-class object)))
94 (format-time-string "%Y%m%d%H%M" (mixi-object-time object)) "."
95 (if (eq class 'mixi-comment)
96 (concat (mixi-friend-id (mixi-comment-owner object)) "@"
97 (mixi-object-id (mixi-comment-parent object)) "."
98 (mixi-friend-id (mixi-object-owner
99 (mixi-comment-parent object))) ".")
100 (concat (mixi-object-id object) "@"
101 (mixi-object-id (mixi-object-owner object)) "."))
102 (mixi-object-name object) ".mixi.jp"
105 (defun shimbun-mixi-make-xref (object)
106 (let ((class (mixi-object-class object)))
107 (cond ((eq class 'mixi-diary)
108 (mixi-expand-url (mixi-diary-page object)))
109 ((eq class 'mixi-topic)
110 (mixi-expand-url (mixi-topic-page object)))
111 ((eq class 'mixi-event)
112 (mixi-expand-url (mixi-event-page object)))
113 ((eq class 'mixi-comment)
114 (concat (shimbun-mixi-make-xref (mixi-comment-parent object))
116 ((eq class 'mixi-message)
117 (mixi-expand-url (mixi-message-page object))))))
119 (defun shimbun-mixi-make-body (object)
120 (mixi-object-content object))
122 (defun shimbun-mixi-get-headers (shimbun objects &optional range)
126 (mapc (lambda (object)
127 (when (mixi-object-p object)
128 (let ((class (mixi-object-class object))
129 (id (shimbun-mixi-make-message-id object)))
131 (shimbun-create-header
133 (shimbun-mixi-make-subject object)
134 (shimbun-mixi-make-from object)
135 (shimbun-mixi-make-date object)
137 (if (eq class 'mixi-comment)
138 (shimbun-mixi-make-message-id
139 (mixi-comment-parent object))
142 (shimbun-mixi-make-xref object))
144 (when (and shimbun-mixi-get-comment-p
145 (or (eq class 'mixi-diary)
146 (eq class 'mixi-topic)
147 (eq class 'mixi-event)))
148 (let ((comments (mixi-get-comments object range)))
149 (mapc (lambda (header)
150 (push header headers))
151 (shimbun-mixi-get-headers shimbun
156 (luna-define-method shimbun-get-headers ((shimbun shimbun-mixi)
158 (let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
159 shimbun-mixi-group-alist)))
160 (range (when (integerp range) (* range shimbun-mixi-page-articles)))
162 (if (stringp url-or-function)
163 (let* ((object (mixi-make-object-from-url url-or-function))
164 (class (mixi-object-class object)))
165 (cond ((eq class 'mixi-friend)
166 (setq objects (mixi-get-diaries object range)))
167 ((eq class 'mixi-community)
168 (setq objects (mixi-get-bbses object range)))
169 ((or (eq class 'mixi-diary)
170 (eq class 'mixi-topic)
171 (eq class 'mixi-event))
172 (setq objects (mixi-get-comments object range)))
173 (t (error (concat (symbol-name class)
174 " is not supported yet.")))))
175 (setq objects (funcall url-or-function range)))
176 (shimbun-sort-headers (shimbun-mixi-get-headers shimbun objects range))))
178 (defun shimbun-comment-article (url header)
179 (let ((parent (mixi-make-object-from-url url))
180 (date (shimbun-header-date header))
181 (message-id (shimbun-header-id header)))
183 (mapc (lambda (comment)
184 (let ((id (mixi-friend-id (mixi-comment-owner comment)))
185 (time (shimbun-mixi-make-date comment)))
186 (when (and (string= time date)
187 (string-match (concat "^<[0-9]+\\." id "@")
189 ;; FIXME: Concat parent's information?
190 (throw 'found (mixi-comment-content comment)))))
191 (mixi-get-comments parent)))))
193 (luna-define-method shimbun-article ((shimbun shimbun-mixi)
194 header &optional outbuf)
195 (when (shimbun-current-group-internal shimbun)
196 (with-current-buffer (or outbuf (current-buffer))
198 (or (with-temp-buffer
199 (let* ((url (shimbun-article-url shimbun header))
200 (article (if (string-match "#comment$" url)
201 (shimbun-comment-article url header)
202 ;; FIXME: Concat community information?
203 (shimbun-mixi-make-body
204 (mixi-make-object-from-url url)))))
205 (when (stringp article)
207 (shimbun-message shimbun "shimbun: Make contents...")
208 (goto-char (point-min))
209 (prog1 (shimbun-make-contents shimbun header)
210 (shimbun-message shimbun "shimbun: Make contents...done")))
215 ;;; sb-mixi.el ends here