* liece-emacs.el (liece-emacs-unread-character): Abolish.
[elisp/liece.git] / lisp / liece-handle.el
index ae0927f..522282e 100644 (file)
     (liece-insert-notice (append liece-D-buffer liece-O-buffer)
                          (concat (substring rest (match-end 0)) "\n"))
     (return-from liece-handle-notice-message))
-
-  (with-liece-decryption (rest prefix)
-    (if (run-hook-with-args-until-success 'liece-notice-cleartext-hook
-                                         prefix rest)
-       (return-from liece-handle-notice-message))
+  (if (run-hook-with-args-until-success 'liece-notice-cleartext-hook
+                                       prefix rest)
+      (return-from liece-handle-notice-message))
     
-    (multiple-value-bind (chnl temp) (liece-split-line rest)
-      ;; This is a ctcp reply but contains additional messages
-      ;; at the left or/and right side.
-      (if (liece-handle-ctcp-message-p temp)
-         (setq temp (liece-ctcp-notice prefix temp)))
-      (if (liece-handle-message-check-empty temp)
-         (return-from liece-handle-notice-message))
-
-      ;; Normal message via notice.
-      (setq chnl (liece-channel-virtual chnl))
-      (let ((liece-message-target chnl)
-           (liece-message-speaker prefix)
-           (liece-message-type 'notice))
-       (liece-display-message temp)))))
+  (multiple-value-bind (chnl temp) (liece-split-line rest)
+    ;; This is a ctcp reply but contains additional messages
+    ;; at the left or/and right side.
+    (if (liece-handle-ctcp-message-p temp)
+       (setq temp (liece-ctcp-notice prefix temp)))
+    (if (liece-handle-message-check-empty temp)
+       (return-from liece-handle-notice-message))
+
+    ;; Normal message via notice.
+    (setq chnl (liece-channel-virtual chnl))
+    (let ((liece-message-target chnl)
+         (liece-message-speaker prefix)
+         (liece-message-type 'notice))
+      (liece-display-message temp))))
 
 (defun* liece-handle-privmsg-message (prefix rest)
   (if (liece-handle-message-check-ignored prefix rest)
       (return-from liece-handle-privmsg-message))
-  (with-liece-decryption (rest prefix)
-    (if (run-hook-with-args-until-success 'liece-privmsg-cleartext-hook
-                                         prefix rest)
-       (return-from liece-handle-privmsg-message))
+  (if (run-hook-with-args-until-success 'liece-privmsg-cleartext-hook
+                                       prefix rest)
+      (return-from liece-handle-privmsg-message))
 
-    (multiple-value-bind (chnl temp) (liece-split-line rest)
-      (setq temp (or temp ""))
-      ;; This is a ctcp request but contains additional messages
-      ;; at the left or/and right side.
-      (if (liece-handle-ctcp-message-p temp)
-         (setq temp (liece-ctcp-message prefix chnl temp)))
-      (if (liece-handle-message-check-empty temp)
-         (return-from liece-handle-privmsg-message))
+  (multiple-value-bind (chnl temp) (liece-split-line rest)
+    (setq temp (or temp ""))
+    ;; This is a ctcp request but contains additional messages
+    ;; at the left or/and right side.
+    (if (liece-handle-ctcp-message-p temp)
+       (setq temp (liece-ctcp-message prefix chnl temp)))
+    (if (liece-handle-message-check-empty temp)
+       (return-from liece-handle-privmsg-message))
 
-      (setq chnl (liece-channel-virtual chnl))
-      
-      ; beep
-      (if liece-beep-on-bells
-         (progn
-           (and (string-match "\007" rest) (beep t))
-           (if (liece-nick-equal chnl liece-real-nickname)
-               (and liece-beep-when-privmsg (beep t))
-             (with-current-buffer (if liece-channel-buffer-mode
-                                      (format liece-channel-buffer-format
-                                              chnl)
-                                    liece-dialogue-buffer)
-                                  (and liece-beep (beep t))))
-           (let ((i 0)
-                 (word (nth 0 liece-beep-words-list)))
-             (while word
-               (and (string-match word rest) (beep t))
-               (setq i (1+ i))
-               (setq word (nth i liece-beep-words-list))))))
-
-      ;; Append timestamp if we are being away.
-      (and (string-equal "A" liece-away-indicator)
-          (liece-nick-equal chnl liece-real-nickname)
-          (setq temp
-                (concat temp " ("
-                        (funcall liece-format-time-function (current-time))
-                        ")")))
-      
-      ;; Normal message.
-      (let ((liece-message-target chnl)
-           (liece-message-speaker prefix)
-           (liece-message-type 'privmsg))
-       (liece-display-message temp))
+    (setq chnl (liece-channel-virtual chnl))
       
-      (and (liece-nick-equal chnl liece-real-nickname)
-          (not (liece-nick-equal prefix liece-current-chat-partner))
-          (liece-message (_ "A private message has arrived from %s")
-                          prefix)))))
+    (when liece-beep-on-bells
+      (if (string-match "\007" rest)
+         (liece-beep))
+      (if (liece-nick-equal chnl liece-real-nickname)
+         (and liece-beep-when-privmsg (liece-beep))
+       (with-current-buffer (if liece-channel-buffer-mode
+                                (liece-pick-buffer-1 chnl)
+                              liece-dialogue-buffer)
+         (if liece-beep
+             (liece-beep))))
+      (dolist (word liece-beep-words-list)
+       (if (string-match word rest)
+           (liece-beep))))
+
+    ;; Append timestamp if we are being away.
+    (if (and (string-equal "A" liece-away-indicator)
+            (liece-nick-equal chnl liece-real-nickname))
+       (setq temp
+             (concat temp " ("
+                     (funcall liece-format-time-function (current-time))
+                     ")")))
+
+    ;; Normal message.
+    (let ((liece-message-target chnl)
+         (liece-message-speaker prefix)
+         (liece-message-type 'privmsg))
+      (liece-display-message temp))
+
+    ;; Append to the unread list.
+    (let ((item (if (eq liece-command-buffer 'chat)
+                   liece-current-chat-partner
+                 liece-current-channel)))
+      (unless (liece-channel-equal chnl item)
+       (if (liece-channel-unread-p chnl)
+           (setq liece-channel-unread-list
+                 (delete chnl liece-channel-unread-list)))
+       (setq liece-channel-unread-list
+             (cons chnl liece-channel-unread-list))
+      (run-hook-with-args 'liece-channel-unread-hook chnl)))
+
+    (if (and (liece-nick-equal chnl liece-real-nickname)
+            (not (liece-nick-equal prefix liece-current-chat-partner)))
+       (liece-message (_ "A private message has arrived from %s")
+                      prefix))))
 
 (defun liece-handle-ping-message (prefix rest)
   (liece-send "PONG :%s" rest)
   (or (string-match " +:" rest)
       (return-from liece-handle-invite-message))
   (and liece-beep-when-invited liece-beep-on-bells
-       (beep t))
+       (liece-beep))
   (let ((chnl (liece-channel-virtual (substring rest (match-end 0)))))
     (liece-insert-info (append liece-D-buffer liece-O-buffer)
                        (format "%s invites you to channel %s\n"