* riece-300.el (riece-handle-317-message): Format idle seconds in
[riece] / lisp / riece-300.el
index 018144c..52f7eba 100644 (file)
   (if (string-match
        (concat "^\\(" riece-user-regexp "\\) \\([0-9]+\\) ")
        string)
-      (let ((user (match-string 1 string))
-           (idle (match-string 2 string)))
+      (let* ((user (match-string 1 string))
+            (seconds (string-to-number (match-string 2 string)))
+            (units (list (cons (/ seconds 60 60 24) "days")
+                         (cons (mod (/ seconds 60 60) 24) "hours")
+                         (cons (mod (/ seconds 60) 60) "minutes")
+                         (cons (mod seconds 60) "seconds"))))
        (riece-insert-info
         (list riece-dialogue-buffer riece-others-buffer)
         (concat
          (riece-concat-server-name
-          (format "%s is %s seconds idle"
+          (format "%s is %s idle"
                   (riece-format-identity
                    (riece-make-identity user riece-server-name)
                    t)
-                  idle))
+                  (mapconcat #'identity
+                             (delq nil
+                                   (mapcar
+                                    (lambda (unit)
+                                      (if (/= (car unit) 0)
+                                          (format "%d %s"
+                                                  (car unit) (cdr unit))))
+                                    units))
+                             ", ")))
          "\n")))))
 
 (defun riece-handle-319-message (prefix number name string)
                 (substring string (match-end 0))))
        "\n"))))
 
-(defvar riece-353-string nil)
+(defvar riece-353-message-alist nil)
 (defun riece-handle-353-message (prefix number name string)
   "RPL_NAMREPLY        \"[=\*@] <channel> :[[@|+]<nick> [[@|+]<nick> [...]]]\"."
+  (make-local-variable 'riece-353-message-alist)      
   (if (string-match "^[=\*@] *\\([^ ]+\\) +:?" string)
-      (let ((channel (match-string 1 string))
-           (start 0)
-           user)
-       (make-local-variable 'riece-353-string)
-       (setq riece-353-string (concat riece-353-string
-                                      (substring string (match-end 0)))))))
+      (let* ((channel (match-string 1 string))
+            (entry (riece-identity-assoc channel riece-353-message-alist t)))
+       (if entry
+           (setcdr entry
+                   (concat (cdr entry)
+                           (substring string (match-end 0))))
+         (setq riece-353-message-alist
+               (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)
             (channel-identity (riece-make-identity channel
                                                    riece-server-name))
             (buffer (riece-channel-buffer channel-identity))
-            (string (copy-sequence riece-353-string))
+            (entry (riece-identity-assoc channel riece-353-message-alist t))
+            (string (cdr entry))
             (start 0)
             users)
-       (setq riece-353-string nil)
+       (if entry
+           (setq riece-353-message-alist
+                 (delq entry riece-353-message-alist)))
        (while (string-match
                (concat "\\([@+]\\)?\\(" riece-user-regexp "\\) *")
                string start)