From 7e7d49c69eb406c51f824709416adcf04461453f Mon Sep 17 00:00:00 2001 From: ueno Date: Mon, 29 Aug 2005 02:55:29 +0000 Subject: [PATCH] * riece-identity.el (riece-coding-system-for-identity): Moved from riece-coding.el. (riece-decoded-string-for-identity): Ditto. * riece-300.el (riece-handle-322-message): Decode message per channel. (riece-handle-set-topic): Ditto. * riece-handle.el (riece-handle-notice-message): Decode message per channel. (riece-handle-part-message): Ditto. (riece-handle-kick-message): Ditto. (riece-handle-topic-message): Ditto. --- lisp/ChangeLog | 16 ++++++++ lisp/riece-300.el | 95 +++++++++++++++++++++++++----------------------- lisp/riece-coding.el | 23 ------------ lisp/riece-handle.el | 49 +++++++++++++++++-------- lisp/riece-identity.el | 23 ++++++++++++ 5 files changed, 121 insertions(+), 85 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3facbe6..81f2717 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,19 @@ +2005-08-29 Daiki Ueno + + * riece-identity.el (riece-coding-system-for-identity): Moved from + riece-coding.el. + (riece-decoded-string-for-identity): Ditto. + + * riece-300.el (riece-handle-322-message): Decode message per + channel. + (riece-handle-set-topic): Ditto. + + * riece-handle.el (riece-handle-notice-message): Decode message + per channel. + (riece-handle-part-message): Ditto. + (riece-handle-kick-message): Ditto. + (riece-handle-topic-message): Ditto. + 2005-08-28 Daiki Ueno * riece-handle.el (riece-handle-privmsg-message): Use diff --git a/lisp/riece-300.el b/lisp/riece-300.el index 109f2f2..ab992c3 100644 --- a/lisp/riece-300.el +++ b/lisp/riece-300.el @@ -257,27 +257,29 @@ (cons (cons channel (substring string (match-end 0))) riece-353-message-alist)))))) -(defun riece-handle-322-message (prefix number name string) - (if (string-match "^\\([^ ]+\\) \\([0-9]+\\) :?" string) - (let* ((channel (match-string 1 string)) - (visible (match-string 2 string)) - (topic (substring string (match-end 0)))) - (riece-channel-set-topic (riece-get-channel channel) topic) - (let* ((channel-identity (riece-make-identity channel - riece-server-name)) - (buffer (riece-channel-buffer channel-identity))) - (riece-insert-info buffer (concat visible " users, topic: " - topic "\n")) - (riece-insert-info - (if (and riece-channel-buffer-mode - (not (eq buffer riece-channel-buffer))) - (list riece-dialogue-buffer riece-others-buffer) - riece-dialogue-buffer) - (concat - (riece-concat-server-name - (format "%s: %s users, topic: %s" - (riece-format-identity channel-identity t) visible topic)) - "\n")))))) +(defun riece-handle-322-message (prefix number name decoded) + (let* ((parameters (riece-split-parameters (riece-decoded-string decoded))) + (channel (car parameters)) + (visible (nth 1 parameters)) + (channel-identity (riece-make-identity channel riece-server-name)) + (buffer (riece-channel-buffer channel-identity)) + topic) + (setq parameters (riece-split-parameters + (riece-decoded-string-for-identity decoded + channel-identity)) + topic (nth 1 parameters)) + (riece-channel-set-topic (riece-get-channel channel) topic) + (riece-insert-info buffer (concat visible " users, topic: " topic "\n")) + (riece-insert-info + (if (and riece-channel-buffer-mode + (not (eq buffer riece-channel-buffer))) + (list riece-dialogue-buffer riece-others-buffer) + riece-dialogue-buffer) + (concat + (riece-concat-server-name + (format "%s: %s users, topic: %s" + (riece-format-identity channel-identity t) visible topic)) + "\n")))) (defun riece-handle-324-message (prefix number name string) (if (string-match "^\\([^ ]+\\) \\([^ ]+\\) " string) @@ -301,31 +303,32 @@ mode-string)) "\n")))))) -(defun riece-handle-set-topic (prefix number name string remove) - (if (string-match "^\\([^ ]+\\) :?" string) - (let* ((channel (match-string 1 string)) - (message (substring string (match-end 0))) - (channel-identity (riece-make-identity channel riece-server-name)) - (buffer (riece-channel-buffer channel-identity))) - (if remove - (riece-channel-set-topic (riece-get-channel channel) nil) - (riece-channel-set-topic (riece-get-channel channel) message) - (riece-insert-info buffer (concat "Topic: " message "\n")) - (riece-insert-info - (if (and riece-channel-buffer-mode - (not (eq buffer riece-channel-buffer))) - (list riece-dialogue-buffer riece-others-buffer) - riece-dialogue-buffer) - (concat - (riece-concat-server-name - (format "Topic for %s: %s" - (riece-format-identity channel-identity t) - message)) - "\n"))) - (riece-emit-signal 'channel-topic-changed - channel-identity - (unless remove - message))))) +(defun riece-handle-set-topic (prefix number name decoded remove) + (let* ((parameters (riece-split-parameters (riece-decoded-string decoded))) + (channel (car parameters)) + topic + (channel-identity (riece-make-identity channel riece-server-name)) + (buffer (riece-channel-buffer channel-identity))) + (if remove + (riece-channel-set-topic (riece-get-channel channel) nil) + (setq parameters (riece-split-parameters + (riece-decoded-string-for-identity decoded + channel-identity)) + topic (nth 1 parameters)) + (riece-channel-set-topic (riece-get-channel channel) topic) + (riece-insert-info buffer (concat "Topic: " topic "\n")) + (riece-insert-info + (if (and riece-channel-buffer-mode + (not (eq buffer riece-channel-buffer))) + (list riece-dialogue-buffer riece-others-buffer) + riece-dialogue-buffer) + (concat + (riece-concat-server-name + (format "Topic for %s: %s" + (riece-format-identity channel-identity t) + topic)) + "\n"))) + (riece-emit-signal 'channel-topic-changed channel-identity topic))) (defun riece-handle-331-message (prefix number name string) (riece-handle-set-topic prefix number name string t)) diff --git a/lisp/riece-coding.el b/lisp/riece-coding.el index ec2aa14..3da47a9 100644 --- a/lisp/riece-coding.el +++ b/lisp/riece-coding.el @@ -76,19 +76,6 @@ specifying the coding systems for decoding and encoding respectively." coding-system decoded) decoded)) -(defun riece-coding-system-for-identity (identity) - (let ((alist riece-coding-system-alist) - matcher) - (catch 'found - (while alist - (setq matcher (riece-parse-identity (car (car alist)))) - (if (and (equal (riece-identity-server matcher) - (riece-identity-server identity)) - (equal (riece-identity-prefix matcher) - (riece-identity-prefix identity))) - (throw 'found (cdr (car alist)))) - (setq alist (cdr alist)))))) - ;; The following functions are API used by handler functions. For the ;; meantime DECODED is actually a string (with some text properties). ;; In the future, however, the implementation _should_ be changed so @@ -103,16 +90,6 @@ specifying the coding systems for decoding and encoding respectively." (defalias 'riece-decoded-string 'identity) -(defun riece-decoded-string-for-identity (decoded identity) - "Return the string decoded for IDENTITY." - (let ((coding-system (riece-coding-system-for-identity identity))) - (if (and coding-system - (not (eq (riece-decoded-coding-system string) - coding-system))) - (riece-decode-coding-string-1 (riece-decoded-encoded-string decoded) - coding-system) - decoded))) - (provide 'riece-coding) ;;; riece-coding.el ends here diff --git a/lisp/riece-handle.el b/lisp/riece-handle.el index dc94fd7..53be6f2 100644 --- a/lisp/riece-handle.el +++ b/lisp/riece-handle.el @@ -78,14 +78,14 @@ (riece-format-identity new-identity t))) "\n")))) -(defun riece-handle-privmsg-message (prefix string) +(defun riece-handle-privmsg-message (prefix decoded) (let* ((user (riece-prefix-nickname prefix)) - (parameters (riece-split-parameters (riece-decoded-string string))) + (parameters (riece-split-parameters (riece-decoded-string decoded))) (targets (split-string (car parameters) ",")) message) (setq parameters (riece-split-parameters (riece-decoded-string-for-identity - string + decoded (riece-make-identity (car targets) riece-server-name))) message (nth 1 parameters)) (riece-display-message @@ -98,12 +98,17 @@ (riece-identity-equal-no-server user riece-real-nickname))))) -(defun riece-handle-notice-message (prefix string) +(defun riece-handle-notice-message (prefix decoded) (let* ((user (if prefix (riece-prefix-nickname prefix))) - (parameters (riece-split-parameters string)) + (parameters (riece-split-parameters (riece-decoded-string decoded))) (targets (split-string (car parameters) ",")) - (message (nth 1 parameters))) + message) + (setq parameters (riece-split-parameters + (riece-decoded-string-for-identity + decoded + (riece-make-identity (car targets) riece-server-name))) + message (nth 1 parameters)) (if user (riece-display-message (riece-make-message (riece-make-identity user @@ -158,18 +163,22 @@ "\n"))) (setq channels (cdr channels))))) -(defun riece-handle-part-message (prefix string) +(defun riece-handle-part-message (prefix decoded) (let* ((user (riece-prefix-nickname prefix)) - (parameters (riece-split-parameters string)) + (parameters (riece-split-parameters (riece-decoded-string decoded))) ;; RFC2812 3.2.2 doesn't recommend server to send part ;; messages which contain multiple targets. (channels (split-string (car parameters) ",")) - (message (nth 1 parameters)) (user-identity (riece-make-identity user riece-server-name))) (while channels (let* ((channel-identity (riece-make-identity (car channels) riece-server-name)) - (buffer (riece-channel-buffer channel-identity))) + (buffer (riece-channel-buffer channel-identity)) + message) + (setq parameters (riece-split-parameters + (riece-decoded-string-for-identity decoded + channel-identity)) + message (nth 1 parameters)) (riece-insert-change buffer (concat @@ -195,15 +204,19 @@ (riece-naming-assert-part user (car channels)) (setq channels (cdr channels))))) -(defun riece-handle-kick-message (prefix string) +(defun riece-handle-kick-message (prefix decoded) (let* ((kicker (riece-prefix-nickname prefix)) - (parameters (riece-split-parameters string)) + (parameters (riece-split-parameters (riece-decoded-string decoded))) (channel (car parameters)) (user (nth 1 parameters)) - (message (nth 2 parameters)) + message (kicker-identity (riece-make-identity kicker riece-server-name)) (channel-identity (riece-make-identity channel riece-server-name)) (user-identity (riece-make-identity user riece-server-name))) + (setq parameters (riece-split-parameters + (riece-decoded-string-for-identity decoded + channel-identity)) + message (nth 2 parameters)) (riece-naming-assert-part user channel) (let ((buffer (riece-channel-buffer channel-identity))) (riece-insert-change @@ -337,13 +350,17 @@ (riece-format-identity channel-identity))) "\n")))) -(defun riece-handle-topic-message (prefix string) +(defun riece-handle-topic-message (prefix decoded) (let* ((user (riece-prefix-nickname prefix)) - (parameters (riece-split-parameters string)) + (parameters (riece-split-parameters (riece-decoded-string decoded))) (channel (car parameters)) - (topic (nth 1 parameters)) + topic (user-identity (riece-make-identity user riece-server-name)) (channel-identity (riece-make-identity channel riece-server-name))) + (setq parameters (riece-split-parameters + (riece-decoded-string-for-identity decoded + channel-identity)) + topic (nth 1 parameters)) (riece-channel-set-topic (riece-get-channel channel) topic) (riece-emit-signal 'channel-topic-changed channel-identity topic) diff --git a/lisp/riece-identity.el b/lisp/riece-identity.el index adada4c..61b9820 100644 --- a/lisp/riece-identity.el +++ b/lisp/riece-identity.el @@ -184,6 +184,29 @@ The rest of arguments are the same as `completing-read'." ;;; (error "Invalid channel name!")) identity)) +(defun riece-coding-system-for-identity (identity) + (let ((alist riece-coding-system-alist) + matcher) + (catch 'found + (while alist + (setq matcher (riece-parse-identity (car (car alist)))) + (if (and (equal (riece-identity-server matcher) + (riece-identity-server identity)) + (equal (riece-identity-prefix matcher) + (riece-identity-prefix identity))) + (throw 'found (cdr (car alist)))) + (setq alist (cdr alist)))))) + +(defun riece-decoded-string-for-identity (decoded identity) + "Return the string decoded for IDENTITY." + (let ((coding-system (riece-coding-system-for-identity identity))) + (if (and coding-system + (not (eq (riece-decoded-coding-system decoded) + coding-system))) + (riece-decode-coding-string-1 (riece-decoded-encoded-string decoded) + coding-system) + decoded))) + (provide 'riece-identity) ;;; riece-identity.el ends here -- 1.7.10.4