-(defun riece-unread-display-message-function (message)
- (unless (or (riece-message-own-p message)
- (equal (riece-message-target message) riece-current-channel))
- (setq riece-unread-channels
- (delete (riece-message-target message) riece-unread-channels))
- (add-to-list 'riece-unread-channels
- (riece-message-target message))
- (riece-unread-update-channel-list-buffer)))
-
-(defun riece-unread-channel-switch-hook ()
- (setq riece-unread-channels
- (delete riece-current-channel
- riece-unread-channels))
- (riece-unread-update-channel-list-buffer))
-
-(defun riece-unread-update-channel-list-buffer ()
- (if riece-channel-list-buffer-mode
- (save-excursion
- (set-buffer riece-channel-list-buffer)
- (let ((inhibit-read-only t)
- buffer-read-only)
- (goto-char (point-min))
- (while (not (eobp))
- (if (looking-at "\\( ?[0-9]+:\\)\\(.\\)\\(.+\\)")
- (let ((channel (save-match-data
- (riece-parse-identity (match-string 3)))))
- (replace-match
- (concat "\\1"
- (if (member channel riece-unread-channels)
- "!"
- "\\2")
- "\\3"))))
- (forward-line))))))
-
+(defvar riece-unread-enabled nil)
+
+(defconst riece-unread-description
+ "Mark channels where \"unread\" messages arrived")
+
+(defun riece-unread-after-display-message-function (message)
+ (if riece-unread-enabled
+ (let ((target (if (riece-message-private-p message)
+ (riece-message-speaker message)
+ (riece-message-target message))))
+ (unless (or (riece-message-own-p message)
+ (riece-message-type message)
+ (riece-identity-equal target riece-current-channel)
+ (riece-identity-member target riece-unread-channels))
+ (setq riece-unread-channels (cons target riece-unread-channels))
+ (riece-emit-signal 'channel-list-changed)))))
+
+(defun riece-unread-after-switch-to-channel-function (last)
+ (if riece-unread-enabled
+ (setq riece-unread-channels
+ (delete riece-current-channel
+ riece-unread-channels))))
+
+(defun riece-unread-format-identity-for-channel-list-buffer (index identity)
+ (if (and riece-unread-enabled
+ (riece-identity-member identity riece-unread-channels))
+ (concat (format "%2d:!" index)
+ (riece-format-identity identity))))
+
+(defun riece-unread-format-identity-for-channel-list-indicator (index identity)
+ (if (and riece-unread-enabled
+ (riece-identity-member identity riece-unread-channels))
+ (let ((string (riece-format-identity identity))
+ (start 0))
+ ;; Escape % -> %%.
+ (while (string-match "%" string start)
+ (setq start (1+ (match-end 0))
+ string (replace-match "%%" nil nil string)))
+ (list (format "%d:" index)
+ (riece-propertize-modeline-string
+ string 'face 'riece-modeline-unread-face)))))
+