From: bg66 Date: Tue, 24 Oct 2006 08:57:24 +0000 (+0000) Subject: * mixi.el (mixi-message-cache): New variable. X-Git-Tag: cache-file-branchpoint~39 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecefdbaf0dac4c905edc69ff6502ec2c0af770a7;p=elisp%2Fmixi.git * mixi.el (mixi-message-cache): New variable. (mixi-make-message): New function. (mixi-message-p): New macro. (mixi-message-page): Ditto. (mixi-message-owner-regexp): New constant. (mixi-message-subject-regexp): Ditto. (mixi-message-time-regexp): Ditto. (mixi-message-content-regexp): Ditto. (mixi-message-realize): New function. (mixi-message-realize-p): New accessor method. (mixi-message-id): Ditto. (mixi-message-box): Ditto. (mixi-message-owner): Ditto. (mixi-message-title): Ditto. (mixi-message-time): Ditto. (mixi-message-content): Ditto. (mixi-message-touch): Ditto. (mixi-message-set-owner): Ditto. (mixi-message-set-title): Ditto. (mixi-message-set-time): Ditto. (mixi-message-set-content): Ditto. (mixi-message-list-page): New macro. (mixi-message-list-regexp): New constant. (mixi-get-messages): New function. --- diff --git a/ChangeLog b/ChangeLog index 41f585b..5cad941 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2006-10-24 OHASHI Akira + + * mixi.el (mixi-message-cache): New variable. + (mixi-make-message): New function. + (mixi-message-p): New macro. + (mixi-message-page): Ditto. + (mixi-message-owner-regexp): New constant. + (mixi-message-subject-regexp): Ditto. + (mixi-message-time-regexp): Ditto. + (mixi-message-content-regexp): Ditto. + (mixi-message-realize): New function. + (mixi-message-realize-p): New accessor method. + (mixi-message-id): Ditto. + (mixi-message-box): Ditto. + (mixi-message-owner): Ditto. + (mixi-message-title): Ditto. + (mixi-message-time): Ditto. + (mixi-message-content): Ditto. + (mixi-message-touch): Ditto. + (mixi-message-set-owner): Ditto. + (mixi-message-set-title): Ditto. + (mixi-message-set-time): Ditto. + (mixi-message-set-content): Ditto. + (mixi-message-list-page): New macro. + (mixi-message-list-regexp): New constant. + (mixi-get-messages): New function. + 2006-10-24 Daiki Ueno * mixi.el (with-mixi-decoded-time-value): Abolished. diff --git a/mixi.el b/mixi.el index e101a12..dfe2348 100644 --- a/mixi.el +++ b/mixi.el @@ -1498,6 +1498,157 @@ Increase this value when unexpected error frequently occurs." (mixi-get-comments diary))) items))) +;; Message object. +(defvar mixi-message-cache (make-hash-table :test 'equal)) +(defun mixi-make-message (id box) + "Return a message object." + (mixi-make-cache (list id box) + (cons 'mixi-message (vector nil id box nil nil nil nil)) + mixi-message-cache)) + +(defmacro mixi-message-p (message) + `(eq (mixi-object-class ,message) 'mixi-message)) + +(defmacro mixi-message-page (message) + `(concat "/view_message.pl?id=" (mixi-message-id ,message) + "&box=" (mixi-message-box ,message))) + +(defconst mixi-message-owner-regexp + "º¹½Ð¿Í : \\(.+\\)") +(defconst mixi-message-title-regexp + "·ï¡¡Ì¾ : \\(.+\\) +") +(defconst mixi-message-time-regexp + "Æü¡¡ÉÕ : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ  ") +(defconst mixi-message-content-regexp + "\\(.+\\)") + +(defun mixi-message-realize (message) + "Realize a MESSAGE." + (unless (mixi-message-realize-p message) + (with-mixi-retrieve (mixi-message-page message) + (if (string-match mixi-message-owner-regexp buffer) + (mixi-message-set-owner message + (mixi-make-friend (match-string 1 buffer) + (match-string 2 buffer))) + (signal 'error (list 'cannot-find-owner message))) + (if (string-match mixi-message-title-regexp buffer) + (mixi-message-set-title message (match-string 1 buffer)) + (signal 'error (list 'cannot-find-title message))) + (if (string-match mixi-message-time-regexp buffer) + (mixi-message-set-time + message (encode-time 0 (string-to-number (match-string 5 buffer)) + (string-to-number (match-string 4 buffer)) + (string-to-number (match-string 3 buffer)) + (string-to-number (match-string 2 buffer)) + (string-to-number (match-string 1 buffer)))) + (signal 'error (list 'cannot-find-time message))) + (if (string-match mixi-message-content-regexp buffer) + (mixi-message-set-content message (mixi-remove-markup + (match-string 1 buffer))) + (signal 'error (list 'cannot-find-content message)))) + (mixi-message-touch message))) + +(defun mixi-message-realize-p (message) + "Return the timestamp of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (aref (cdr message) 0)) + +(defun mixi-message-id (message) + "Return the id of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (aref (cdr message) 1)) + +(defun mixi-message-box (message) + "Return the box of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (aref (cdr message) 2)) + +(defun mixi-message-owner (message) + "Return the owner of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (mixi-message-realize message) + (aref (cdr message) 3)) + +(defun mixi-message-title (message) + "Return the title of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (mixi-message-realize message) + (aref (cdr message) 4)) + +(defun mixi-message-time (message) + "Return the date of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (mixi-message-realize message) + (aref (cdr message) 5)) + +(defun mixi-message-content (message) + "Return the content of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (mixi-message-realize message) + (aref (cdr message) 6)) + +(defun mixi-message-touch (message) + "Set the timestamp of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (aset (cdr message) 0 (current-time))) + +(defun mixi-message-set-owner (message owner) + "Set the owner of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (aset (cdr message) 3 owner)) + +(defun mixi-message-set-title (message title) + "Set the title of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (aset (cdr message) 4 title)) + +(defun mixi-message-set-time (message time) + "Set the date of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (aset (cdr message) 5 time)) + +(defun mixi-message-set-content (message content) + "Set the content of MESSAGE." + (unless (mixi-message-p message) + (signal 'wrong-type-argument (list 'mixi-message-p message))) + (aset (cdr message) 6 content)) + +(defmacro mixi-message-list-page (&optional box) + `(concat "/list_message.pl?page=%d" + (when ,box (concat "&box=" ,box)))) + +(defconst mixi-message-list-regexp + "") + +(defun mixi-get-messages (&rest args) + "Get messages." + (when (> (length args) 2) + (signal 'wrong-number-of-arguments (list 'mixi-get-messages + (length args)))) + (let ((box (nth 0 args)) + (max-numbers (nth 1 args))) + (when (or (not (stringp box)) (stringp max-numbers)) + (setq box (nth 1 args)) + (setq max-numbers (nth 0 args))) + (let ((items (mixi-get-matched-items (mixi-message-list-page box) + max-numbers + mixi-message-list-regexp))) + (mapcar (lambda (item) + (mixi-make-message (nth 0 item) (nth 1 item))) + items)))) + (provide 'mixi) ;;; mixi.el ends here