Commit 6114fab2 authored by David Byers's avatar David Byers
Browse files

Fixed bug 854 (join/leave all conferences)

Detailed changes:
> 	Fix bug 854:
> 	* commands2.el (kom-join-all-conferences): New command.
> 	(kom-leave-all-conferences): New command.
>
> 	* commands1.el (lyskom-add-member-by-no): Added no-of-unread
> 	parameter.
>
> 	* lyskom-buttons.el (lyskom-highlight-i-am-supervisor): Use
> 	lyskom-i-am-supervisor.
>
> 	* utilities.el (lyskom-i-am-supervisor): New function.
> 	(lyskom-get-all-conferences): New function.
>
parent bf056bd0
2003-03-16 David Byers <david.byers@swipnet.se>
Fix bug 854:
* commands2.el (kom-join-all-conferences): New command.
(kom-leave-all-conferences): New command.
* commands1.el (lyskom-add-member-by-no): Added no-of-unread
parameter.
* lyskom-buttons.el (lyskom-highlight-i-am-supervisor): Use
lyskom-i-am-supervisor.
* utilities.el (lyskom-i-am-supervisor): New function.
(lyskom-get-all-conferences): New function.
Fix bug 842:
* commands1.el (kom-add-member-answer): Don't enter memberships
under the current session priority.
......
......@@ -641,15 +641,16 @@ the priority of several memberships, use `kom-prioritize' instead."
;;; NOTE: This function is also called from lyskom-go-to-conf-handler
;;; and from lyskom-create-conf-handler.
(defun lyskom-add-member-by-no (conf-no pers-no &optional thendo &rest data)
(defun lyskom-add-member-by-no (conf-no pers-no &optional no-of-unread thendo &rest data)
"Fetch info to be able to add a person to a conf.
Get the conf-stat CONF-NO for the conference and the conf-stat and pers-stat
for person PERS-NO and send them into lyskom-try-add-member."
(blocking-do-multiple ((whereto (get-conf-stat conf-no))
(who (get-conf-stat pers-no))
(pers-stat (get-pers-stat pers-no)))
(let ((result (lyskom-try-add-member whereto who pers-stat nil nil t)))
(lyskom-add-member-answer result whereto who)
(let ((result (lyskom-try-add-member whereto who pers-stat
nil nil t nil no-of-unread)))
(lyskom-add-member-answer result whereto who no-of-unread)
(if thendo
(apply thendo data))
(car result))))
......@@ -915,7 +916,7 @@ See `kom-unsubscribe-makes-passive'."
(cons ccn 0)
"")) t))))
(defun lyskom-sub-member (pers conf)
(defun lyskom-sub-member (pers conf &optional have-message)
"Remove the person indicated by PERS as a member of CONF."
(let* ((reply nil)
(self (= (conf-stat->conf-no pers) lyskom-pers-no))
......@@ -931,7 +932,8 @@ See `kom-unsubscribe-makes-passive'."
((null conf) (lyskom-insert-string 'error-fetching-conf))
(passivate
(lyskom-prefetch-cancel-prefetch-map (conf-stat->conf-no conf))
(lyskom-format-insert 'unsubscribe-to conf)
(unless have-message
(lyskom-format-insert 'unsubscribe-to conf))
(set-membership-type->passive (membership->type mship) t)
(setq reply (blocking-do 'set-membership-type
(conf-stat->conf-no pers)
......@@ -1028,7 +1030,9 @@ probably a general Q&A conference where you can ask."
(lyskom-default-button 'conf conf-stat)
nil)))
(lyskom-scroll)
(lyskom-add-member-by-no conf-no lyskom-pers-no
(lyskom-add-member-by-no conf-no
lyskom-pers-no
nil
(if secret
nil ; Don't write a presentation
'lyskom-create-conf-handler-2)
......
......@@ -3114,6 +3114,146 @@ Note that this is advisory only; clients may ignore your redirection."
)
;;; ================================================================
;;; Kamikaze functions!
(def-kom-command kom-join-all-conferences ()
"Join all conferences.
You want to be really careful doing this. It will take a while and
is probably not what you really want to do."
(interactive)
(let* ((conf-nos (lyskom-get-all-conferences t))
(confirm-each (or (lyskom-j-or-n-p 'confirm-each-join)
(not (lyskom-j-or-n-p
(lyskom-format 'no-confirm-each-sure
(length conf-nos))))))
(no-of-unread (lyskom-read-num-range-or-date
0
lyskom-max-int
(lyskom-format 'initial-unread)
nil
t
nil))
(kom-membership-default-priority
(lyskom-read-num-range 0 255
(lyskom-get-string 'priority-q)
nil nil)))
(while conf-nos
(unless (or (lyskom-get-membership (car conf-nos) t)
(and confirm-each
(not (lyskom-j-or-n-p (lyskom-format 'confirm-join
(car conf-nos))))))
(lyskom-add-member-by-no (car conf-nos) lyskom-pers-no no-of-unread))
(setq conf-nos (cdr conf-nos)))))
(def-kom-command kom-leave-all-conferences ()
"Leave all conferences.
This command will ignore certain conferences. It will not leave your
letterbox, secret or closed conferences without confirmation. Note
that this command could take a very long time to complete."
(interactive)
(let* ((auto-regular nil)
(auto-secret nil)
(auto-closed nil)
(confs nil))
(lyskom-message (lyskom-get-string 'getting-all-confs))
(let* ((xlist (lyskom-get-all-conferences))
(count (length xlist))
(index 0))
(setq confs (delq nil
(mapcar (lambda (conf-no)
(setq index (1+ index))
(lyskom-message
(lyskom-format 'getting-all-confs-progress index count))
(when (or (lyskom-try-get-membership conf-no t)
(lyskom-is-member conf-no lyskom-pers-no))
conf-no))
xlist)))
(lyskom-message (lyskom-get-string 'getting-all-confs-done)))
(while confs
(let* ((conf (car confs))
(conf-stat (blocking-do 'get-conf-stat conf))
(conf-type (conf-stat->conf-type conf-stat))
(unsubscribe nil))
(setq lyskom-last-viewed (point-max))
(lyskom-format-insert 'unsubscribe-to-2
conf-stat
(lyskom-conf-type-marker conf-stat))
(when (cond
;; Won't auto-unsub letterbox
((= (conf-stat->conf-no conf-stat) lyskom-pers-no)
(lyskom-insert (lyskom-get-string
'unsub-all-skipping-letterbox))
nil)
;; Won't unsub if we are supervisor
((lyskom-i-am-supervisor conf-stat t)
(lyskom-insert-string 'unsub-all-skipping-supervised)
nil)
;; Check secret conferences
((conf-type->secret conf-type)
(if auto-secret
t
(let ((ans (lyskom-a-or-b-or-c-p (lyskom-format 'unsub-secret-conf-q conf-stat)
'(abc-yes abc-no unsub-all-secret)
'abc-no)))
(cond ((eq ans 'abc-no)
(lyskom-insert-string 'cancelled) nil)
((eq ans 'abc-yes) t)
((eq ans 'unsub-all-secret)
(setq auto-secret t)
t)))))
;; Skip closed only if doit is
((conf-type->rd_prot conf-type)
(if auto-closed
t
(let ((ans (lyskom-a-or-b-or-c-p (lyskom-format 'unsub-closed-conf-q conf-stat)
'(abc-yes abc-no unsub-all-closed)
'abc-no)))
(cond ((eq ans 'abc-no)
(lyskom-insert-string 'cancelled) nil)
((eq ans 'abc-yes) t)
((eq ans 'unsub-all-closed)
(setq auto-closed t)
t)))))
;; Regular conference
(t
(if auto-regular
t
(let ((ans (lyskom-a-or-b-or-c-p (lyskom-format 'unsub-open-conf-q conf-stat)
'(abc-yes abc-no unsub-all-open)
'abc-no)))
(cond ((eq ans 'abc-no)
(lyskom-insert-string 'cancelled) nil)
((eq ans 'abc-yes) t)
((eq ans 'unsub-all-open)
(setq auto-regular t)
t))))))
;; How's that for a really long condition? Lots of
;; cool side effects and user interactions. Don't
;; you just love functional programming?
;; Now we've either printed a message or we've
;; decided to unsubscribe.
(lyskom-sub-member (blocking-do 'get-conf-stat lyskom-pers-no)
conf-stat
t)
))
(setq confs (cdr confs)))
))
;;; ================================================================
;;; Temporary function for when we moved kom-extended-command from a
;;; to x.
......
......@@ -454,12 +454,29 @@ and you have finished reading. Please come back later.
(change-priority-for-q . "Change priority of conference: ")
(change-priority-for . "Changing priority of %#2M...")
(unsubscribe-to . "Leaving %#1M...")
(passivate-done . "You are now a passive member of %#1M.
Leave the conference again to unsubscribe completely.\n")
(unsubscribe-to-2 . "Leaving %#1M%#2s...")
(confirm-each-join . "Confirm joining each individual conference? ")
(no-confirm-each-sure . "Are you sure you want to join %#1d conferences automatically? ")
(confirm-join . "Join %#1M? ")
(getting-all-confs . "Getting a list of all conferences...")
(getting-all-confs-progress . "Getting a list of all conferences (%#1d/%#2d)...")
(getting-all-confs-done . "Getting a list of all conferences...done")
(unsub-all-skipping-letterbox . "nix\nThis is your letterbox.\n")
(unsub-all-skipping-supervised . "nix\nYou are the supervisor of the conference.\n")
(unsub-secret-conf-q . "%#1M is secret. Leave anyway? ")
(unsub-all-secret . "aLeave all secret conferences")
(unsub-closed-conf-q . "%#1M r close. Leave anyway? ")
(unsub-all-closed . "aLeave all closed conferences")
(unsub-open-conf-q . "Leave %#1M? ")
(unsub-all-open . "aLeave all open conferences")
(abc-yes . "yYes")
(abc-no . "nNo")
(exclude-from . "Removing %#1P from %#2M...")
(unsubscribe-failed . "\nDidn't work. Perhaps %#1P isn't a member of %#2M?\n")
(passivate-done . "You are now a passive member of %#1M.
Leave the conference again to unsubscribe completely.\n")
(You . "You")
(could-not-create-conf . "Couldn't create the conference \"%#1s\".\n")
......@@ -2103,6 +2120,9 @@ environment to one that uses \"%#2s\" to encode text.
(kom-unread-faq . "Unread FAQ")
(kom-unread-marked-texts . "Unread marked (texts)")
(kom-unread-all-marked-texts . "Unread all markeed (texts)")
(kom-join-all-conferences . "Join all conferences")
(kom-leave-all-conferences . "Leave (almost) all conferences")
))
(lyskom-language-var global lyskom-language-codes en
......
......@@ -1359,17 +1359,8 @@ ARG interpreted by `lyskom-highlight-function-get-conf-stat'.
This function never makes server calls, so if the information required
to answer accurately is not cached, this function will return an incorrect
result (nil instead of t)."
(let ((marshal nil)
(conf-stat (lyskom-highlight-function-get-conf-stat arg)))
(when conf-stat
(let ((conf (conf-stat->supervisor conf-stat))
(result nil))
(while (and (not (memq conf marshal)) conf (not result))
(setq marshal (cons conf marshal))
(if (lyskom-try-get-membership conf t)
(setq result t)
(setq conf (conf-stat->supervisor (cache-get-conf-stat conf)))))
result))))
(let ((conf-stat (lyskom-highlight-function-get-conf-stat arg)))
(lyskom-i-am-supervisor conf-stat nil)))
(defun lyskom-highlight-has-no-presentation (arg)
"Returns non-nil if lyskom-pers-no is the supervisor of CONF-STAT.
......
......@@ -445,6 +445,23 @@ du har l
(change-priority-for-q . "ndra prioritet fr mte: ")
(change-priority-for . "ndra prioritet p %#2M...")
(unsubscribe-to . "Uttrda ur %#1M...")
(unsubscribe-to-2 . "Uttrda ur %#1M%#2s...")
(confirm-each-join . "Vill du bekrfta medlemskap i varje enskilt mte? ")
(no-confirm-each-sure . "r du helt sker p att du vill g med i %#1d mten automatiskt? ")
(confirm-join . "G med i %#1M? ")
(getting-all-confs . "Hmtar en lista med alla mten...")
(getting-all-confs-progress . "Hmtar en lista med alla mten (%#1d/%#2d)...")
(getting-all-confs-done . "Hmtar en lista med alla mten...klart")
(unsub-all-skipping-letterbox . "nix\nMtet r din brevlda.\n")
(unsub-all-skipping-supervised . "nix\nDu r organisatr fr mtet.\n")
(unsub-secret-conf-q . "%#1M r hemligt. Vill du g ur mtet nd? ")
(unsub-all-secret . "aG ur alla hemliga mten")
(unsub-closed-conf-q . "%#1M r slutet. Vill du g ur mtet nd? ")
(unsub-all-closed . "aG ur alla slutna mten")
(unsub-open-conf-q . "Vill du g ur %#1M? ")
(unsub-all-open . "aG ur alla ppna mten")
(abc-yes . "jJa")
(abc-no . "nNej")
(exclude-from . "Utesluta %#1P frn %#2M...")
......@@ -2136,6 +2153,9 @@ teckenkodning.
(kom-unread-faq . "Olsmarkera FAQ")
(kom-unread-marked-texts . "Olsmarkera markerade")
(kom-unread-all-marked-texts . "Olsmarkera alla markerade")
(kom-join-all-conferences . "Bli medlem i alla mten")
(kom-leave-all-conferences . "Uttrd ur (nstan) alla mten")
))
(lyskom-language-var local lyskom-language-codes sv
......
......@@ -1292,7 +1292,14 @@ is the conference to use and TYPE is the type of recipient (numeric)."
(t nil)))))
(if want-type result (car result))))
(defun lyskom-get-all-conferences (&optional feep)
"Return a list of all conferences.
If FEEP is non-nil, show progress messages"
(and feep (lyskom-message (lyskom-get-string 'getting-all-confs)))
(prog1 (mapcar 'conf-z-info->conf-no
(conf-z-info-list->conf-z-infos
(blocking-do 'lookup-z-name "" nil t)))
(and feep (lyskom-message (lyskom-get-string 'getting-all-confs-done)))))
(defun lyskom-is-supervisor (conf-no viewer-no)
"Return non-nil if the supervisor of CONF-NO is VIEWER-NO."
......@@ -1316,6 +1323,26 @@ Cannot be called from a callback."
((lyskom-is-member (conf-stat->supervisor conf-stat) viewer-no) t)
(t nil))))
(defun lyskom-i-am-supervisor (conf-stat &optional may-block)
"Returns non-nil if lyskom-pers-no is the supervisor of CONF-STAT.
If MAY-BLOCK is non-nil, this function never makes server calls, so if
the information required to answer accurately is not cached, this
function will return an incorrect result (nil instead of t)."
(let ((marshal nil))
(when conf-stat
(let ((conf (conf-stat->supervisor conf-stat))
(result nil))
(while (and (not (memq conf marshal)) conf (not result))
(setq marshal (cons conf marshal))
(if (lyskom-try-get-membership conf t)
(setq result t)
(if may-block
(setq conf (conf-stat->supervisor
(blocking-do 'get-conf-stat conf)))
(setq conf (conf-stat->supervisor (cache-get-conf-stat conf))))))
result))))
(defun lyskom-is-member (conf-no pers-no &optional queue)
"Return the membership in CONF-NO of PERS-NO
......
......@@ -2957,6 +2957,8 @@ Users are encouraged to use their best sense of humor."
kom-unread-faq
kom-unread-server-faq
kom-unread-presentation
kom-join-all-conferences
kom-leave-all-conferences
))
;;; ================================================================
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment