commands1.el 168 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
Linus Tolke's avatar
Linus Tolke committed
2
3
;;;;;
;;;;; $Id$
4
;;;;; Copyright (C) 1991-2002  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
5
;;;;;
6
;;;;; This file is part of the LysKOM Emacs LISP client.
Linus Tolke's avatar
Linus Tolke committed
7
8
9
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
10
;;;;; the Free Software Foundation; either version 2, or (at your option) 
Linus Tolke's avatar
Linus Tolke committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
Per Cederqvist's avatar
.    
Per Cederqvist committed
26
27
28
29
30
31
32
33
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: commands1.el
;;;;
;;;; This file contains the code for some of the high level commands.
;;;;

34
35
36
37
(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))

38
39
40
(eval-when-compile
  (require 'lyskom-command "command"))

41

Per Cederqvist's avatar
.    
Per Cederqvist committed
42
43
44
45
46
47
;;; ================================================================
;;;                  F} uppmuntran - Get appreciation 

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
48
(def-kom-command kom-get-appreciation ()
49
  "Provides a little light in the dark."
Per Cederqvist's avatar
.    
Per Cederqvist committed
50
  (interactive)
David Kågedal's avatar
David Kågedal committed
51
52
  (lyskom-insert-string 'appreciation))
  
Per Cederqvist's avatar
.    
Per Cederqvist committed
53
54
55
56
57
58
59

;;; ================================================================
;;;                      F} Sk{ll - Get abuse

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
60
(def-kom-command kom-get-abuse ()
61
  "Provides a bit of verbal abuse."
Per Cederqvist's avatar
.    
Per Cederqvist committed
62
  (interactive)
David Kågedal's avatar
David Kågedal committed
63
  (lyskom-insert-string 'abuse))
Per Cederqvist's avatar
.    
Per Cederqvist committed
64
65
66
67
68
69
70
71


;;; ================================================================
;;;            Utpl}na - Delete a person or a conference

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
72
(def-kom-command kom-delete-conf ()
73
74
75
76
77
  "Deletes a person or a conference. In order to delete a conference
you must be the supervisor of the conference. Once a conference is
deleted, it can never be restored, and texts with no recipients other
than the deleted conference will become inaccessible, and will
eventually be permanently deleted."
Per Cederqvist's avatar
.    
Per Cederqvist committed
78
  (interactive)
David Kågedal's avatar
David Kågedal committed
79
  (let ((conf-stat 
80
	 (lyskom-read-conf-stat 'what-conf-to-delete '(all) nil nil t)))
David Kågedal's avatar
David Kågedal committed
81
82
83
84
85
86
87
88
89
90
    (if conf-stat
	(if (lyskom-ja-or-nej-p
	     (lyskom-format 'confirm-delete-pers-or-conf
			    (if (conf-type->letterbox (conf-stat->conf-type 
						       conf-stat))
				(lyskom-get-string 'the-pers)
			      (lyskom-get-string 'the-conf))
			    (conf-stat->name conf-stat)))
	    (if (blocking-do 'delete-conf
			     (conf-stat->conf-no conf-stat))
91
92
93
94
95
96
97
98
99
100
101
102
103
104
		(progn
		  (lyskom-format-insert 'conf-is-deleted
					(conf-stat->name conf-stat))
		  (when (= (conf-stat->conf-no conf-stat)
			   lyskom-pers-no)
		    (lyskom-insert (lyskom-get-string
				    'you-have-deleted-yourself))
		    (setq lyskom-pers-no nil
			  lyskom-membership nil
			  lyskom-to-do-list (lyskom-create-read-list)
			  lyskom-reading-list (lyskom-create-read-list)
			  lyskom-pending-commands (cons
						   'kom-start-anew
						   lyskom-pending-commands))))
David Kågedal's avatar
David Kågedal committed
105
106
107
108
	      (lyskom-format-insert 'you-could-not-delete
				    conf-stat))
	  (lyskom-insert-string 'deletion-not-confirmed))
      (lyskom-insert-string 'somebody-else-deleted-that-conf))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
109
110
111
112
113
114
115
116


;;; ================================================================
;;;                Radera (text) - Delete a text

;;; Author: Inge Wallin


117
(def-kom-command kom-delete-text (text-no)
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  "Permanently deletes a text. In order to delete a text you must
be the author of the text, or the supervisor of the author.

It is a very bad idea to delete texts that have comments. By deleting
a text with comments, the comments lost their context. This can lead
to fragmented discussion trees, where it is impossible to understand
what a comment means, or indeed what the whole discussion is about.

Instead of deleting a text, consider moving it to a conference created
specifically for storing texts that are no longer interesting. Several
LysKOM systems have such conferences, so ask around.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
132
133
  (interactive (list (lyskom-read-text-no-prefix-arg 'what-text-to-delete)))
  (if text-no
David Byers's avatar
David Byers committed
134
135
136
      (let* ((text-stat (blocking-do 'get-text-stat text-no))
             (num-marks (and text-stat (text-stat->no-of-marks text-stat)))
             (num-comments (and text-stat (length (lyskom-text-comments text-stat))))
137
             (is-marked-by-me (cache-text-is-marked text-no)))
David Byers's avatar
David Byers committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

        (if (null text-stat)
            (lyskom-report-command-answer nil)
          (when (and (or (eq 0 num-marks)
                         (lyskom-j-or-n-p 
                          (lyskom-format 'delete-marked-text
                                         (if (> num-marks 0)
                                             (if is-marked-by-me
                                                 (if (= num-marks 1)
                                                     (lyskom-get-string 'delete-marked-by-you)
                                                   (lyskom-format 'delete-marked-by-you-and-others
                                                                  (1- num-marks)))
                                               (lyskom-format 'delete-marked-by-several
                                                              num-marks))))))
                     (or (eq 0 num-comments)
                         (progn (lyskom-format-insert "%#1@%#2t\n" 
154
                                                      `(face ,kom-warning-face)
David Byers's avatar
David Byers committed
155
156
157
158
159
160
161
162
163
164
165
                                                      (lyskom-get-string 'delete-commented-text-help))
                                (lyskom-beep t)
                                (and (lyskom-j-or-n-p
                                      (lyskom-get-string 'delete-commented-text))
                                     (lyskom-j-or-n-p
                                      (lyskom-get-string 'really-delete-commented-text))))))
            (lyskom-format-insert 'deleting-text text-no)
            (when (lyskom-report-command-answer 
                   (blocking-do 'delete-text text-no))
              (when is-marked-by-me
                (lyskom-unmark-text text-no))))))
166
    (lyskom-insert 'confusion-what-to-delete)))
David Byers's avatar
David Byers committed
167

Per Cederqvist's avatar
.    
Per Cederqvist committed
168
169
170
171
172
173
174
175
176


;;; ================================================================
;;;        ]terse presentation - Review the presentation
;;;               for a person or a conference

;;; Author: Inge Wallin


David Byers's avatar
David Byers committed
177
(def-kom-command kom-review-presentation (&optional text-or-conf-no)
178
179
180
181
182
183
184
  "Reviews the presentation for a person or a conference. If you give
a prefix argument it is treated as a text number prefix argument (see
`lyskom-read-text-no-prefix-arg'), and this command shows the
presentation of the author of that text.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
185
186
187
188
  (interactive (and current-prefix-arg ; only peek at textno:s when prefixed!
		    (list (lyskom-read-text-no-prefix-arg
			   'text-to-see-author-of))))
  (let ((conf-stat
David Byers's avatar
David Byers committed
189
         (if text-or-conf-no
190
             (blocking-do 'get-conf-stat
David Byers's avatar
David Byers committed
191
192
193
194
                          (if (interactive-p)
                              (text-stat->author
                               (blocking-do 'get-text-stat text-or-conf-no))
                            text-or-conf-no))
195
196
           (lyskom-read-conf-stat 'presentation-for-whom '(all)
                                  nil nil t))))
David Byers's avatar
David Byers committed
197
198
    (lyskom-review-presentation conf-stat)))

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
(def-kom-command kom-unread-presentation (&optional text-or-conf-no)
  "Marks the presentation for a person or a conference as unread. If
you give a prefix argument it is treated as a text number prefix
argument (see `lyskom-read-text-no-prefix-arg'), and this command
unreads the presentation of the author of that text.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
  (interactive (and current-prefix-arg ; only peek at textno:s when prefixed!
		    (list (lyskom-read-text-no-prefix-arg
			   'text-to-unread-author-of))))
  (let ((conf-stat
         (if text-or-conf-no
             (blocking-do 'get-conf-stat
                          (if (interactive-p)
                              (text-stat->author
                               (blocking-do 'get-text-stat text-or-conf-no))
                            text-or-conf-no))
217
218
           (lyskom-read-conf-stat 'unread-presentation-for-whom
                                  '(all) nil nil t))))
219
220
221
222
223
224
225
    (if (zerop (conf-stat->presentation conf-stat))
        (lyskom-format-insert 'has-no-presentation conf-stat)
      (lyskom-format-insert 'marking-text-unread
                            (conf-stat->presentation conf-stat))
      (lyskom-report-command-answer
       (lyskom-mark-unread (conf-stat->presentation conf-stat))))))

David Byers's avatar
David Byers committed
226
227
228
229
230
231
232
233
234
235
236
237
238
239
(defun lyskom-review-presentation (conf-stat)
  "Review the presentation of conference CONF-STAT."
  (if (null conf-stat)
      (lyskom-insert-string 'somebody-deleted-that-conf)
    (lyskom-format-insert 'review-presentation-of
                          conf-stat)
    (if (/= (conf-stat->presentation conf-stat) 0)
        (lyskom-view-text (conf-stat->presentation conf-stat))
      (lyskom-format-insert 'has-no-presentation
                            conf-stat))
    (lyskom-traverse faq (lyskom-get-aux-item 
                          (conf-stat->aux-items conf-stat)
                          14)
      (lyskom-print-comment-like-aux faq conf-stat))))  
240
241

(defun lyskom-print-comment-like-aux (item object)
David Byers's avatar
David Byers committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
  (when (lyskom-aux-item-validate (aux-item->data item) 'lyskom-string-to-int)
    (let* ((text-no (string-to-int (aux-item->data item)))
           (text-stat nil)
           (text nil))
      (unless kom-deferred-printing
        (blocking-do-multiple ((x-text (get-text text-no))
                               (x-text-stat (get-text-stat text-no)))
          (setq text-stat x-text-stat text x-text)))

      (cond ((or text-stat (not kom-deferred-printing))
             (lyskom-insert-comment-like-aux item text-no text-stat text object))
            (t (let ((defer-info (lyskom-create-defer-info
                                  'get-text-stat
                                  text-no
                                  'lyskom-insert-deferred-comment-like-aux
                                  (point-max-marker)
                                  (length lyskom-defer-indicator)
                                  nil   ; Filled in later
                                  (list item object text-no))))
                 (lyskom-format-insert "%#1s\n" lyskom-defer-indicator)
                 (lyskom-defer-insertion defer-info)))))))
263

David Byers's avatar
David Byers committed
264
(defun lyskom-insert-comment-like-aux (item text-no text-stat text object)
265
266
267
268
269
270
  (let* ((author (if text-stat (text-stat->author text-stat) nil))
         (mx-from (car (lyskom-get-aux-item (text-stat->aux-items text-stat)
                                            17)))
         (mx-author (car (lyskom-get-aux-item (text-stat->aux-items text-stat)
                                              16)))
         (formats (lyskom-aux-item-definition-field item 'text-header-line))
David Byers's avatar
David Byers committed
271
         (subject (lyskom-print-faq-format-subject text text-stat text-no))
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
         content-type
         )
    (if (and mx-from
             (setq content-type
                   (car (lyskom-get-aux-item (text-stat->aux-items 
                                              text-stat) 1))))
        (progn (string-match "^\\(\\S-+\\)" (aux-item->data content-type))
               (setq content-type (format "(%s) "
                                          (aux-item->data content-type))))
      (setq content-type ""))
    (setq author (or (lyskom-format-mx-author mx-from mx-author) author))

    (lyskom-format-insert (cond ((not (listp formats)) formats)
                                ((<= (length formats) 1) (car formats))
                                (author (elt formats 1))
                                (t (elt formats 0)))
                          text-no
                          author
                          content-type
                          (lyskom-aux-item-terminating-button item
David Byers's avatar
David Byers committed
292
293
                                                              object)
                          subject)
294
295
296
297
298
299
    (lyskom-insert "\n")))

;;; FIXME: This contains code that duplicates the code in 
;;; lyskom-insert-deferred-header-comm. That's a BAD THING.

(defun lyskom-insert-deferred-comment-like-aux (text-stat defer-info)
David Byers's avatar
David Byers committed
300
301
302
303
304
305
306
  (initiate-get-text 'deferred
                     'lyskom-insert-deferred-comment-like-aux-2
                     (elt (defer-info->data defer-info) 2)
                     text-stat
                     defer-info))

(defun lyskom-insert-deferred-comment-like-aux-2 (text text-stat defer-info)
307
308
309
310
311
312
313
314
315
  (let* ((author (if text-stat (text-stat->author text-stat) nil))
         (item (elt (defer-info->data defer-info) 0))
         (object (elt (defer-info->data defer-info) 1))
         (text-no (elt (defer-info->data defer-info) 2))
         (mx-from (car (lyskom-get-aux-item (text-stat->aux-items text-stat)
                                            17)))
         (mx-author (car (lyskom-get-aux-item (text-stat->aux-items text-stat)
                                              16)))
         (formats (lyskom-aux-item-definition-field item 'text-header-line))
David Byers's avatar
David Byers committed
316
         (subject (lyskom-print-faq-format-subject text text-stat text-no))
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
         content-type
         )
    (if (and mx-from
             (setq content-type
                   (car (lyskom-get-aux-item (text-stat->aux-items 
                                              text-stat) 1))))
        (progn (string-match "^\\(\\S-+\\)" (aux-item->data content-type))
               (setq content-type (format "(%s) "
                                          (aux-item->data content-type))))
      (setq content-type ""))
    (setq author (or (lyskom-format-mx-author mx-from mx-author) author))

    (set-defer-info->format defer-info 
                            (cond ((not (listp formats)) formats)
                                  ((<= (length formats) 1) (car formats))
                                  (author (elt formats 1))
                                  (t (elt formats 0))))
    (lyskom-replace-deferred defer-info
                             text-no
                             author
                             content-type
                             (lyskom-aux-item-terminating-button item
David Byers's avatar
David Byers committed
339
340
                                                                 object)
                             subject)))
341
342
343



344

Per Cederqvist's avatar
.    
Per Cederqvist committed
345
346
347


;;; ================================================================
348
;;;          Återse det kommenterade - View commented text
Per Cederqvist's avatar
.    
Per Cederqvist committed
349
350

;;; Author: Inge Wallin
351
;;; Modified by: David Kågedal, Johan Sundström
Per Cederqvist's avatar
.    
Per Cederqvist committed
352

353
(def-kom-command kom-view-commented-text (text-no)
354
355
356
357
358
359
360
361
  "Views the text that the selected text is a comment to. If the
current text is comment or footnote to several texts then the first
text is shown and the remaining texts are reviewed.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg').

See `kom-review-uses-cache'."
362
  (interactive (list (lyskom-read-text-no-prefix-arg 'review-commented-q)))
363
364
365
  (if text-no
      (progn
	(lyskom-tell-internat 'kom-tell-read)
366
367
        (unless kom-review-uses-cache
          (cache-del-text-stat text-no))
368
369
	(lyskom-view-commented-text
	 (blocking-do 'get-text-stat text-no)))
370
    (lyskom-insert-string 'confusion-what-to-view)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
371

David Byers's avatar
David Byers committed
372
373
374
375
376
377
378
379
380
381
382
(def-kom-command kom-unread-commented-text (text-no)
  "MArkes the texts that the selected text is a comment to as unread.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
  (interactive (list (lyskom-read-text-no-prefix-arg 'unread-commented-q)))
  (if text-no
      (lyskom-unread-commented-text 
       (blocking-do 'get-text-stat text-no))
    (lyskom-insert-string 'confusion-what-to-mark-unread)))

Per Cederqvist's avatar
.    
Per Cederqvist committed
383

384
(def-kom-command kom-view-previous-commented-text (text-no)
385
386
387
388
389
390
391
392
393
394
395
396
  "Views the text that the selected text is a comment to. If the
current text is comment or footnote to several texts then the first
text is shown and the remaining texts are reviewed.

Without a prefix argument this will display the text that the
next-to-last text in the buffer is a comment to. With a prefix
argument this command is identical to `kom-view-commented-text'.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')

See `kom-review-uses-cache'."
397
398
399
400
  (interactive (list (lyskom-read-text-no-prefix-arg 'review-commented-q nil
                                                     lyskom-previous-text)))
  (cond (text-no
         (lyskom-tell-internat 'kom-tell-read)
401
402
        (unless kom-review-uses-cache
          (cache-del-text-stat text-no))
403
         (lyskom-view-commented-text
David Byers's avatar
David Byers committed
404
          (blocking-do 'get-text-stat text-no)))
405
        (t (lyskom-insert-string 'confusion-what-to-view))))
406

407

David Byers's avatar
David Byers committed
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
(def-kom-command kom-unread-previous-commented-text (text-no)
  "Marks the texts that the selected text is a comment to as unread.

Without a prefix argument this will display the text that the
next-to-last text in the buffer is a comment to. With a prefix
argument this command is identical to `kom-unread-commented-text'.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')"
  (interactive (list (lyskom-read-text-no-prefix-arg 'review-commented-q nil
                                                     lyskom-previous-text)))
  (if text-no
      (lyskom-unread-commented-text
       (blocking-do 'get-text-stat text-no))
    (lyskom-insert-string 'confusion-what-to-mark-unread)))


425
426
(defun lyskom-text-stat-commented-texts (text-stat)
  "Return a list of the text-nos that TEXT-STAT is a comment or footnote to."
427
  (let* ((misc-info-list (and text-stat
428
429
430
431
432
                              (text-stat->misc-info-list text-stat)))
         (misc-infos (and misc-info-list
                          (append (lyskom-misc-infos-from-list
                                   'COMM-TO misc-info-list)
                                  (lyskom-misc-infos-from-list
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
                                   'FOOTN-TO misc-info-list)))))
    (and misc-infos
	 (mapcar
	  (function
	   (lambda (misc-info)
	     (if (equal (misc-info->type misc-info)
			'COMM-TO)
		 (misc-info->comm-to misc-info)
	       (misc-info->footn-to misc-info))))
	  misc-infos))))


(defun lyskom-view-commented-text (text-stat)
  "Handles the return from the initiate-get-text-stat, displays and builds list."
  (let ((text-nos (lyskom-text-stat-commented-texts text-stat)))
448
    (if text-nos
449
450
451
452
453
454
        (progn
          (lyskom-format-insert 'review-text-no 
                                (car text-nos))
          (if (cdr text-nos)
              (read-list-enter-read-info
               (lyskom-create-read-info
David Byers's avatar
David Byers committed
455
                'REVIEW nil (lyskom-review-get-priority)
456
457
458
                (lyskom-create-text-list (cdr text-nos))
                lyskom-current-text)
               lyskom-reading-list t))
459
460
          (unless kom-review-uses-cache
            (cache-del-text-stat (car text-nos)))
461
462
463
464
          (lyskom-view-text (car text-nos)
			    nil nil nil 
			    nil nil nil
			    t))
465
      (lyskom-insert-string 'no-comment-to))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
466

David Byers's avatar
David Byers committed
467
468
469
470
471
472
473
474
475
(defun lyskom-unread-commented-text (text-stat)
  "Marks the texts that TEXT-STAT is a comment to as unread."
  (let ((text-nos (lyskom-text-stat-commented-texts text-stat)))
    (if text-nos
        (lyskom-traverse text-no text-nos
          (lyskom-format-insert 'marking-text-unread text-no)
          (lyskom-report-command-answer (lyskom-mark-unread text-no)))
      (lyskom-insert-string 'no-comment-to-to-unread))))

Per Cederqvist's avatar
.    
Per Cederqvist committed
476
477
478
479

(defun lyskom-misc-infos-from-list (type list)
  "Get all the misc-infos from the misc-info-list LIST with the same type
as TYPE. If no such misc-info, return NIL"
David Byers's avatar
David Byers committed
480
481
482
483
484
  (let ((result nil))
    (while list
      (when (equal type (misc-info->type (car list)))
        (setq result (cons (car list) result)))
      (setq list (cdr list)))
David Kågedal's avatar
David Kågedal committed
485
    (nreverse result)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
486
487
488
489
490
491


;;; ================================================================
;;;                         Brev - Send letter
;;; Author: Inge Wallin

492
(def-kom-command kom-send-letter (&optional pers-no)
493
494
  "Send a personal letter to a person. This command is similar to
`kom-write-text', but intended specifically for sending personal
495
496
497
498
499
500
messages.

Several settings affect writing texts in general.
`kom-write-texts-in-window' controls which window is used to write the
comment; `kom-confirm-multiple-recipients' affects how multiple
recipients are handled."
Per Cederqvist's avatar
.    
Per Cederqvist committed
501
  (interactive)
502
  (lyskom-tell-internat 'kom-tell-write-letter)
David Byers's avatar
David Byers committed
503
  (lyskom-write-text pers-no 'who-letter-to))
Per Cederqvist's avatar
.    
Per Cederqvist committed
504
505
506
507
508
509


;;; ================================================================
;;;           Bli medlem i m|te - Become a member of a conference
;;;             Addera medlem - Add somebody else as a member

510
;;; Author: David Byers, David Kågedal
Per Cederqvist's avatar
.    
Per Cederqvist committed
511

David Kågedal's avatar
David Kågedal committed
512
(def-kom-command kom-add-member ()
513
514
515
516
  "Invite a person as a member of a conference. Depending on the
server configuration this command may either create an invitation or
simply make the person a member of the conference without asking them
for confirmation."
Per Cederqvist's avatar
.    
Per Cederqvist committed
517
  (interactive)
518
  (lyskom-add-member))
Per Cederqvist's avatar
.    
Per Cederqvist committed
519

520
(def-kom-command kom-add-self (&optional conf)
521
522
523
524
525
526
527
528
  "Become a member of a conference. The default priority of the
membership is determined by `kom-membership-default-priority' and its
placement by `kom-membership-default-placement' You can also use this
command to change the priority of an existing membership and to
re-join a conference of which you are a passive member.

See `kom-membership-default-priority' and 
`kom-membership-default-placement'"
Per Cederqvist's avatar
.    
Per Cederqvist committed
529
  (interactive)
530
531
  (lyskom-add-member (blocking-do 'get-conf-stat lyskom-pers-no)
                     conf))
David Byers's avatar
David Byers committed
532
533
534


(def-kom-command kom-change-priority (&optional conf)
535
536
  "Changes the priority of a single membership. If you want to change
the priority of several memberships, use `kom-prioritize' instead."
David Byers's avatar
David Byers committed
537
  (interactive)
538
539
  (let* ((conf-stat (if conf 
                        (blocking-do 'get-conf-stat conf)
540
541
                      (lyskom-read-conf-stat  'change-priority-for-q
                                              '(all) nil nil t)))
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
         (mship (and conf-stat (lyskom-get-membership (conf-stat->conf-no conf-stat) t))))
    (cond 
     ((null conf-stat) (lyskom-format-insert 'no-such-conf))
     ((null mship) (lyskom-format-insert 'not-member-of-conf conf-stat))
     ((membership-type->passive (membership->type mship))
      (lyskom-format-insert 'cant-change-priority-of-passive))
     (t (lyskom-add-member (blocking-do 'get-conf-stat lyskom-pers-no)
                           conf-stat
                           t
                           t
                           (list (membership->priority mship))
                           nil
                           t
                           'change-priority-for)))))

Per Cederqvist's avatar
.    
Per Cederqvist committed
557

558
(defun lyskom-add-member-by-no (conf-no pers-no &optional no-of-unread mship-type thendo &rest data)
Per Cederqvist's avatar
.    
Per Cederqvist committed
559
560
  "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 
561
for person PERS-NO and send them into lyskom-add-member."
David Byers's avatar
David Byers committed
562
  (blocking-do-multiple ((whereto (get-conf-stat conf-no))
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
                         (who (get-conf-stat pers-no)))
    (prog1 
        (lyskom-add-member who whereto mship-type no-of-unread)
      (and thendo (apply thendo data)))))


(defun lyskom-add-member (&optional pers-conf-stat conf-conf-stat
                                    mship-type no-of-unread priority 
                                    position force message-string)
  "Add PERS-CONF-STAT to CONF-CONF-STAT. 
Returns non-nil if person if person is a member of the conference
after this call has comleted.

Optional MSHIP-TYPE is the membership type to use. If it is t, keep
the old membership type (if one exists).

Optional NO-OF-UNREAD specifies how many unread texts to leave in 
the conference. If set to t, don't change the number of unread.

Optional PRIORITY is the priority of the membership. If it is a list,
this function will prompt with the car of the list as the default
priority.

Optional POSITION is the position of the new membership.

If optional FORCE is non-nil, add even if the user is already a
member of the conference.

If optional MESSAGE-STRING is non-nil, use it as the prompt
when adding the membership.

This function will prompt interactively for any information not
specified when calling it. This function blocks, so it may not
be called from a callback."
  (let* ((who (or pers-conf-stat (lyskom-read-conf-stat 'who-to-add '(pers) nil nil t)))
         (pers-stat (blocking-do 'get-pers-stat (conf-stat->conf-no who)))
         (self (eq (conf-stat->conf-no who) lyskom-pers-no))
         (whereto (or conf-conf-stat (lyskom-read-conf-stat (if self 
                                                                'where-to-add-self
                                                              'where-to-add) '(all) nil nil t)))
         (mship (lyskom-is-member (conf-stat->conf-no whereto) (conf-stat->conf-no who)))
         (mship-type (if (and (eq mship-type t) mship)
                         (membership->type mship)
                       mship-type))
         (became-member nil))

    (cond
Per Cederqvist's avatar
.    
Per Cederqvist committed
610

611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
     ;; Already a member
     ((and mship 
           (not (and self
                     (or force
                         (membership-type->passive (membership->type mship))
                         (membership-type->invitation (membership->type mship))))))
      (lyskom-format-insert (if self 'you-already-member 'add-already-member)
                            whereto who)
      (setq became-member t))


     ;; We're already passive members, so depassivate
     ((and mship self
           (membership-type->passive (membership->type mship)))
      (set-membership-type->passive (membership->type mship) nil)
      (set-membership-type->message-flag (membership->type mship) t)
      (lyskom-format-insert 'activate-mship whereto)
      (let ((res (blocking-do 'set-membership-type
                              lyskom-pers-no
                              (conf-stat->conf-no whereto)
                              (membership->type mship))))
        (lyskom-report-command-answer res)
        (when res
          (setq became-member t)
          (lyskom-format-insert 'activate-mship-done whereto)
          (lp--update-buffer (membership->conf-no mship))
          (lyskom-fetch-start-of-map whereto mship))))


     ;; We be adding someone for real
     (t (let* ((no-of-unread (cond ((eq no-of-unread t) nil)
                                   (no-of-unread)
                                   (t (when (and self
                                                 (not (membership-type->passive
                                                       (membership->type mship))))
                                        (lyskom-read-num-range-or-date 
                                         0 
                                         (conf-stat->no-of-texts whereto)
                                         (lyskom-format 'initial-unread)
                                         nil
                                         t
                                         nil)))))
               (priority (cond ((numberp priority) priority)
                               ((not self)
                                (lyskom-read-num-range 0 255 (lyskom-get-string 'other-priority-q) nil 100))
                               ((and (null priority)
                                     (numberp kom-membership-default-priority)
                                     (< kom-membership-default-priority 256)
                                     (>= kom-membership-default-priority 0))
                                kom-membership-default-priority)
                               (t (lyskom-read-num-range 0 255
                                                         (lyskom-get-string 'priority-q)
                                                         nil 
                                                         (cond (mship (membership->priority mship))
                                                               ((listp priority) (car priority)))))))
               (position (or position 
                             (cond ((not self) 1)
                                   ((and (numberp kom-membership-default-placement)
                                         (>= kom-membership-default-placement 0))
                                    kom-membership-default-placement)
                                   ((eq kom-membership-default-placement 'first) 0)
                                   ((eq kom-membership-default-placement 'last) (length lyskom-membership))
                                   (t (lyskom-read-num-range
                                       0 (pers-stat->no-of-confs pers-stat)
                                       (lyskom-format 'where-on-list-q
                                                      (length lyskom-membership)))))))
               (message-flag (if mship-type
                                 (membership-type->message-flag mship-type)
                               (lyskom-j-or-n-p (lyskom-format 'set-message-flag-q whereto))))

               (mship-type (or mship-type
                               (lyskom-create-membership-type (not self) nil nil message-flag
                                                              nil nil nil nil)))

               (no-of-unread-string (cond ((null no-of-unread) nil)
                                          ((numberp no-of-unread)
                                           (lyskom-format 'member-in-conf-with-unread no-of-unread))
                                          ((listp no-of-unread)
                                           (lyskom-format 'member-in-conf-with-unread-date
                                                          (elt no-of-unread 0)
                                                          (car (rassq (elt no-of-unread 1)
                                                                      lyskom-month-names))
                                                          (elt no-of-unread 2)))))
               )

          ;; Now add the member; we've got all the information we need

          ;; Adding ourselves. Adjust where so the membership
          ;; list remains sorted. Find the closest position to
          ;; where at which we can put the membership and keep
          ;; the membership lsit sorted.

          (when (eq lyskom-pers-no (conf-stat->conf-no who))
            (let ((mship-list lyskom-membership)
                  (mship nil)
                  (index 0)
                  (found nil))
              (while mship-list
                (setq mship (car mship-list)
                      mship-list (cdr mship-list))
                (cond ((> (membership->priority mship) priority))
                      ((< (membership->priority mship) priority) 
                       (setq position index mship-list nil found t))
                      ((and (= (membership->priority mship) priority)
                            (= index position))
                       (setq mship-list nil found t))
                      ((and (= (membership->priority mship) priority)
                            (> index position))
                       (setq position index mship-list nil found t)))
                (setq index (1+ index))
                (unless found (setq position (1+ index))))))

          ;; Print the prompt

          (lyskom-format-insert (cond (message-string)
                                      ((and self mship
                                            (membership-type->invitation
                                             (membership->type mship)))
                                       'accepting-invitation)
                                      (self 'member-in-conf)
                                      (t 'add-member-in))
                                who whereto no-of-unread-string)

          ;; Do the add thing

          (lyskom-ignoring-async (18 lyskom-pers-no (conf-stat->conf-no whereto))
            (let ((res (blocking-do 'add-member
                                    (conf-stat->conf-no whereto)
                                    (conf-stat->conf-no who)
                                    priority position mship-type)))

              (cond 

               ;; Failure 

               ((null res) 
                (lyskom-insert-string 'nope)
                (let* ((errno lyskom-errno)
                       (err-stat lyskom-err-stat)
                       (is-supervisor (lyskom-is-supervisor (conf-stat->conf-no whereto)
                                                            lyskom-pers-no))
                       (is-member (lyskom-is-member (conf-stat->conf-no whereto)
                                                    (conf-stat->conf-no who)))
                       (rd-prot (conf-type->rd_prot (conf-stat->conf-type whereto))))


                  (cond (is-member
                         (lyskom-format-insert 'add-already-member who whereto))
                        ((and rd-prot is-supervisor)
                         (lyskom-insert-error errno err-stat))
                        (rd-prot (let ((supervisorconf (blocking-do
                                                        'get-conf-stat
                                                        (conf-stat->supervisor whereto))))
                                   (if supervisorconf
                                       (lyskom-format-insert 'is-read-protected-contact-supervisor
                                                             whereto
                                                             supervisorconf)
                                     (lyskom-format-insert 'cant-find-supervisor
                                                           whereto))))
                        (t (lyskom-insert-error errno err-stat)))))

               (t
                (setq became-member t)

                ;; If we're re-adding a membership, then we need to set the
                ;; membership type explicity since add-member won't

                (when (and self mship)
                  (blocking-do 'set-membership-type
                               (conf-stat->conf-no who)
                               (conf-stat->conf-no whereto)
                               mship-type))

                (cache-del-pers-stat (conf-stat->conf-no who))
                (cache-del-conf-stat (conf-stat->conf-no whereto))

                (when self
                  (when no-of-unread
                    (cond ((listp no-of-unread)
                           (let* ((target-date (lyskom-create-time 0 0 0 (elt no-of-unread 2) (elt no-of-unread 1) (elt no-of-unread 0) 0 0 nil))
                                  (text (lyskom-find-text-by-date whereto target-date)))
                             (when text
                               (blocking-do 'set-last-read 
                                            (conf-stat->conf-no whereto)
                                            (car text)))))
                          ((numberp no-of-unread) 
                           (blocking-do 'set-unread (conf-stat->conf-no whereto)
                                        no-of-unread))))
                  (let ((mship (blocking-do 'query-read-texts
                                            lyskom-pers-no 
                                            (conf-stat->conf-no whereto)
                                            t 0)))
                    (if (< (membership->priority mship) lyskom-session-priority)
                        (lyskom-format-insert-before-prompt
                         'member-in-conf-with-low-priority
                         whereto)
                      (unless (membership->position mship)
                        (set-membership->position mship position))
                      (if (lyskom-try-get-membership (conf-stat->conf-no whereto) t)
                          (progn (lyskom-replace-membership mship)
                                 (lyskom-fetch-start-of-map whereto mship))
                        (lyskom-add-membership mship
                                               whereto
                                               t))))
                  (lp--update-buffer (conf-stat->conf-no whereto)))
                (lyskom-insert-string 'done))))))))
    became-member))
Per Cederqvist's avatar
.    
Per Cederqvist committed
818

Linus Tolke's avatar
Linus Tolke committed
819

820
(defun lyskom-add-membership (membership conf-no-or-stat &optional blocking)
Per Cederqvist's avatar
.    
Per Cederqvist committed
821
  "Adds MEMBERSHIP to the sorted list of memberships.
822
823
824
If BLOCKING is non-nil, block while reading the conference map until at 
least one text has been seen. CONF-NO-OR-STAT is the conf-no to add 
unless BLOCKING is t, in which cast it is the conf-stat."
Per Cederqvist's avatar
.    
Per Cederqvist committed
825
826
  (if membership
      (progn
David Byers's avatar
David Byers committed
827
	(lyskom-insert-membership membership)
828
829
830
        (if blocking
            (lyskom-fetch-start-of-map conf-no-or-stat membership)
          (lyskom-prefetch-map conf-no-or-stat membership))
David Byers's avatar
X    
David Byers committed
831
832
        (lyskom-run-hook-with-args 'lyskom-add-membership-hook
                                   membership))
833
    (lyskom-insert-string 'conf-does-not-exist)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
834
835
836
837
838
839
840



;;; ================================================================
;;;     Uttr{d - Subtract yourself as a member from a conference
;;;     Uteslut medlem - Subtract somebody else as a member

841
842
;;; Author: David Byers
;;; Based on code by Inge Wallin
Per Cederqvist's avatar
.    
Per Cederqvist committed
843
844
845
846


;; Subtract another person

David Kågedal's avatar
David Kågedal committed
847
(def-kom-command kom-sub-member ()
848
849
  "Remove a member from a conference. To do this you need to be the
supervisor of the conference or of the member being removed."
Per Cederqvist's avatar
.    
Per Cederqvist committed
850
  (interactive)
David Kågedal's avatar
David Kågedal committed
851
  (lyskom-sub-member
852
853
   (lyskom-read-conf-stat 'who-to-exclude '(pers) nil nil t)
   (lyskom-read-conf-stat 'where-from-exclude '(all) nil nil t)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
854
855


856
(def-kom-command kom-sub-self (&optional conf-no)
857
  "Resign your membership of a conference. If
858
`kom-unsubscribe-makes-passive' is set, them resigning once converts
859
860
861
862
your membership to a passive membership and resigning twice removes
the membership completely (if the server supports passive
memberships).

863
See `kom-unsubscribe-makes-passive'."
Per Cederqvist's avatar
.    
Per Cederqvist committed
864
  (interactive)
865
866
  (let* ((me (blocking-do 'get-conf-stat lyskom-pers-no))
	 (conf (if conf-no (blocking-do 'get-conf-stat conf-no)
867
                 (lyskom-read-conf-stat 'leave-what-conf
868
                                        '(membership) nil nil t))))
869
    (lyskom-sub-member me conf)))
870

871
(defun lyskom-sub-member (pers conf &optional have-message)
872
  "Remove the person indicated by PERS as a member of CONF."
873
874
875
876
877
878
  (let* ((reply nil)
         (self (= (conf-stat->conf-no pers) lyskom-pers-no))
         (mship (and self 
                     kom-unsubscribe-makes-passive
                     (lyskom-get-membership (conf-stat->conf-no conf))))
         (passivate (and mship
David Byers's avatar
David Byers committed
879
                         (lyskom-have-call 102) ; set-membership-type
880
881
882
                         (not (membership-type->passive
                               (membership->type mship))))))

883
884
    (cond ((null pers) (lyskom-insert-string 'error-fetching-person))
	  ((null conf) (lyskom-insert-string 'error-fetching-conf))
885
          (passivate 
886
           (lyskom-prefetch-cancel-prefetch-map (conf-stat->conf-no conf))
887
888
           (unless have-message
             (lyskom-format-insert 'unsubscribe-to conf))
889
           (set-membership-type->passive (membership->type mship) t)
890
           (set-membership-type->message-flag (membership->type mship) nil)
891
892
893
894
895
896
897
898
899
900
           (setq reply (blocking-do 'set-membership-type
                                    (conf-stat->conf-no pers)
                                    (conf-stat->conf-no conf)
                                    (membership->type mship)))
           (if (not reply)
               (lyskom-format-insert 'unsubscribe-failed
                                     (lyskom-get-string 'You)
                                     conf)
             (lyskom-insert-string 'done)
             (lyskom-format-insert 'passivate-done conf)
David Byers's avatar
David Byers committed
901
902
             (when (= (conf-stat->conf-no conf) lyskom-current-conf)
               (lyskom-leave-current-conf))
903
	     (read-list-delete-read-info (conf-stat->conf-no conf)
David Byers's avatar
David Byers committed
904
905
					 lyskom-to-do-list)
             (lp--update-buffer (conf-stat->conf-no conf))))
906
	  (t
907
908
909
           (when self
             (lyskom-prefetch-cancel-prefetch-map (conf-stat->conf-no conf)))

910
911
912
913
	   (if self
	       (lyskom-format-insert 'unsubscribe-to conf)
	     (lyskom-format-insert 'exclude-from pers conf))

David Byers's avatar
David Byers committed
914
915
916
917
           (lyskom-ignoring-async (8 (conf-stat->conf-no conf))
             (setq reply (blocking-do 'sub-member
                                      (conf-stat->conf-no conf)
                                      (conf-stat->conf-no pers))))
918
	   (if self
David Byers's avatar
David Byers committed
919
	       (lyskom-remove-membership (conf-stat->conf-no conf)))
920
921
922
923
	   (if (not reply)
	       (lyskom-format-insert 'unsubscribe-failed
				     (if self
					 (lyskom-get-string 'You)
924
				       (conf-stat->name pers))
925
				     conf)
926
	     (lyskom-insert-string 'done)
David Byers's avatar
David Byers committed
927
928
929
	     (when (and self (= (conf-stat->conf-no conf)
                              lyskom-current-conf))
               (lyskom-leave-current-conf))
930
	     (read-list-delete-read-info (conf-stat->conf-no conf)
931
					 lyskom-to-do-list))))))
932
	   
Per Cederqvist's avatar
.    
Per Cederqvist committed
933

934
	 
935

Per Cederqvist's avatar
.    
Per Cederqvist committed
936
937
938
939
940
941
;;; ================================================================
;;;                 Skapa m|te - Create a conference

;;; Author: ???


David Kågedal's avatar
David Kågedal committed
942
(def-kom-command kom-create-conf (&optional name)
943
944
945
946
947
948
949
  "Create a new conference. Use this command when you want to create a
new conference. It will ask for all required information.

Before creating a conference, check that there isn't already one
covering the intended topics. There may be a conference for discussing
converence creation where you can ask. If there isn't, there is
probably a general Q&A conference where you can ask."
David Kågedal's avatar
David Kågedal committed
950
  (interactive)
David Kågedal's avatar
David Kågedal committed
951
952
953
  (let* ((conf-name (or name
			(lyskom-read-string
			 (lyskom-get-string 'name-of-conf))))
954
	 (open (j-or-n-p (lyskom-get-string 'anyone-member)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
955
	 (secret (if (not open)
956
957
958
		     (j-or-n-p (lyskom-get-string 'secret-conf))))
	 (orig (j-or-n-p (lyskom-get-string 'comments-allowed)))
         (anarchy (j-or-n-p (lyskom-get-string 'anonymous-allowed)))
David Byers's avatar
David Byers committed
959
         (secmem (and (lyskom-have-feature long-conf-types)
960
                      (not (lyskom-j-or-n-p (lyskom-get-string 'secret-members-allowed)))))
961
	 (life-expectancy (lyskom-read-number 'new-garb-nice-q))
962
	 (keep-commented (lyskom-read-number 'new-keep-commented-q))
963
	 (conf-no (blocking-do 'create-conf
David Kågedal's avatar
David Kågedal committed
964
			       conf-name
965
			       (lyskom-create-conf-type (not open)
David Kågedal's avatar
David Kågedal committed
966
967
							(not orig)
							secret
968
969
							nil
                                                        anarchy
David Byers's avatar
David Byers committed
970
                                                        secmem
971
                                                        nil
972
973
                                                        nil)
                               nil)))
David Kågedal's avatar
David Kågedal committed
974
    (if (null conf-no)
David Kågedal's avatar
David Kågedal committed
975
976
977
	(progn
	  (lyskom-format-insert 'could-not-create-conf
				conf-name)
Per Cederqvist's avatar
Per Cederqvist committed
978
	  (lyskom-insert-error))
David Kågedal's avatar
David Kågedal committed
979
980
981
982
983
984
985
986
987
      (progn
	(let ((conf-stat (blocking-do 'get-conf-stat conf-no)))
	  (lyskom-format-insert 'created-conf-no-name 
				(or conf-stat conf-no)
				(or conf-stat conf-name)
				(if conf-stat
				    (lyskom-default-button 'conf conf-stat)
				  nil)))
	(lyskom-scroll)
988
989
990
	(lyskom-add-member-by-no conf-no 
                                 lyskom-pers-no
                                 nil
991
                                 nil
David Kågedal's avatar
David Kågedal committed
992
993
994
				 (if secret
				     nil ; Don't write a presentation
				   'lyskom-create-conf-handler-2)
995
				 conf-no conf-name)
996
997
	(blocking-do 'set-garb-nice conf-no life-expectancy)
	(blocking-do 'set-keep-commented conf-no keep-commented)))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
998
999
1000
1001
1002
1003


(defun lyskom-create-conf-handler-2 (conf-no conf-name)
  "Starts editing a presentation for the newly created conference.
This does lyskom-end-of-command"
  (lyskom-tell-internat 'kom-tell-conf-pres)
1004
  (let ((conf (blocking-do 'get-conf-stat conf-no)))
David Kågedal's avatar
David Kågedal committed
1005
    (if conf
1006
1007
        (lyskom-dispatch-edit-text lyskom-proc
                                   (lyskom-create-misc-list
David Byers's avatar
David Byers committed
1008
                                    'RECPT
1009
1010
1011
1012
                                    (server-info->conf-pres-conf 
                                     lyskom-server-info))
                                   conf-name ""
                                   'lyskom-set-presentation conf-no))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1013
1014
1015
1016
1017


(defun lyskom-set-presentation (text-no conf-no)
  "Set presentation of a conference. Args: text-no conf-no."
  (initiate-set-presentation 'background nil conf-no text-no)
1018
  (cache-del-conf-stat conf-no))	;+++Borde {ndra i cachen i st{llet.
Per Cederqvist's avatar
.    
Per Cederqvist committed
1019
1020
1021
1022
1023
1024
1025
1026
					;+++ Kan tas bort n{r det existerar 
					;asynkrona meddelanden som talar om att
					;n}got {r {ndrat.
    

(defun lyskom-set-conf-motd (text-no conf-no)
  "Set motd of a conference. Args: text-no conf-no."
  (initiate-set-conf-motd 'background nil conf-no text-no)
1027
  (cache-del-conf-stat conf-no))	;+++Borde {ndra i cachen i st{llet.
Per Cederqvist's avatar
.    
Per Cederqvist committed
1028
1029
1030
1031
1032
1033
1034
1035
					;+++ Kan tas bort n{r det existerar 
					;asynkrona meddelanden som talar om att
					;n}got {r {ndrat.
    

;;; ================================================================
;;;                  Kommentera - write comment
;;; Author: ???
1036
;;; FIXME: Does not use def-kom-command
Per Cederqvist's avatar
.    
Per Cederqvist committed
1037
1038


1039
(def-kom-command kom-write-comment (text-no)
1040
1041
1042
1043
1044
1045
1046
1047
1048
  "Write a comment to the selected text.

Several settings affect writing texts in general.
`kom-write-texts-in-window' controls which window is used to write the
comment; `kom-confirm-multiple-recipients' affects how multiple
recipients are handled.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
  :prompt-format (concat "%#1C " (if text-no
                                     (lyskom-format " (%#1n)" text-no)
                                   ""))
  (interactive (list (let ((lyskom-current-command 'kom-write-comment))
                       (lyskom-read-text-no-prefix-arg 'what-comment-no))))
  (if text-no
      (progn
        (lyskom-nag-about-presentation)
        (blocking-do-multiple ((text (get-text text-no))
                               (text-stat (get-text-stat text-no)))
          (when (or (null (text-stat-find-aux text-stat 4))
                    (lyskom-j-or-n-p 
                     (lyskom-get-string 'no-comments-q)))
            (if (and (text-stat-find-aux text-stat 5)
                     (lyskom-j-or-n-p
                      (lyskom-get-string 'private-answer-q)))
                (lyskom-private-answer-soon
                 text-stat
                 text
                 text-no)
              (lyskom-write-comment-soon text-stat
                                         text
                                         text-no
                                         'comment)))))
    (lyskom-insert-string 'confusion-who-to-reply-to)))

Per Cederqvist's avatar
.    
Per Cederqvist committed
1075
1076


1077
(def-kom-command kom-write-footnote (text-no)
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
  "Write a footnote to the selected text. In order to write a footnote
you must be the author, or superviser of the author, of the selected
text.

Several settings affect writing texts in general.
`kom-write-texts-in-window' controls which window is used to write the
comment; `kom-confirm-multiple-recipients' affects how multiple
recipients are handled.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg'). Without a prefix argument this
command will write a footnote to the most recently read or written
applicable text."
1091
1092
1093
  :prompt-format (concat "%#1C " (if text-no
                                     (lyskom-format " (%#1n)" text-no)
                                   ""))
1094
1095
  (interactive (list (lyskom-read-text-no-prefix-arg 'what-footnote-no nil
                                                     'last-seen-written)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1096
  (if text-no
1097
1098
1099
1100
      (lyskom-write-comment-soon
       (blocking-do 'get-text-stat text-no)
       (blocking-do 'get-text text-no)
       text-no 'footnote)
1101
    (lyskom-insert-string 'confusion-what-to-footnote)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1102
1103


1104
(def-kom-command kom-comment-previous (text-no)
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
  "Write a comment to the selected text. Without a prefix argument
the selected text is the next-to-last text in the buffer.

Several settings affect writing texts in general.
`kom-write-texts-in-window' controls which window is used to write the
comment; `kom-confirm-multiple-recipients' affects how multiple
recipients are handled.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
1115
1116
1117
  :prompt-format (concat "%#1C " (if text-no
                                     (lyskom-format " (%#1n)" text-no)
                                   ""))
1118
1119
1120
1121
1122
  (interactive (list (lyskom-read-text-no-prefix-arg 'what-comment-no nil
                                                     lyskom-previous-text)))
  (if text-no
      (blocking-do-multiple ((text-stat (get-text-stat text-no))
                             (text (get-text text-no)))
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
        (when (or (null text-stat)
                  (null text)
                  (null (text-stat-find-aux text-stat 4))
                  (lyskom-j-or-n-p 
                   (lyskom-get-string 'no-comments-q)))
          (if (and (text-stat-find-aux text-stat 5)
                   (lyskom-j-or-n-p
                    (lyskom-get-string 'private-answer-q)))
              (lyskom-private-answer-soon
               text-stat
               text
1134
1135
1136
1137
1138
1139
               text-no)
            (lyskom-write-comment-soon
             text-stat
             text
             text-no
             'comment))))
1140
    (lyskom-insert-string 'confusion-what-to-comment)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1141
1142
1143
1144
1145


(defun lyskom-write-comment-soon (text-stat text text-no type)
  "Write a comment to the text with TEXT-STAT, TEXT and, TEXT-NO.
TYPE is either 'comment or 'footnote."
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
  (let ((str (and text-stat text (text->decoded-text-mass text text-stat))))
    (cond
     ;; Text not found?
     ((or (null text-stat)
          (null text))
      (lyskom-format-insert 'cant-read-textno text-no))
     ;; Give header.
     ((string-match "\n" str)
      (lyskom-write-comment text-stat
                            (substring str 0 (match-beginning 0))
                            type))
     ;; The commented text had no header.
     (t (lyskom-write-comment text-stat "" type)))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1159
1160
1161
1162
1163
1164
1165


(defun lyskom-write-comment (text-stat subject type)
  "Write a comment to the text associated with TEXT-STAT.
The default subject is SUBJECT. TYPE is either 'comment or 'footnote."
  (if (null text-stat)
      (progn
1166
        (lyskom-insert-string 'confusion-what-to-comment))
David Byers's avatar
David Byers committed
1167
1168
    (let ((ccrep nil)
          (bccrep nil))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1169
      (lyskom-tell-internat (if (eq type 'comment)
1170
1171
                                'kom-tell-write-comment
                              'kom-tell-write-footnote))
1172
      (let (data)
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
        (mapcar 
         (function
          (lambda (misc-info)
            (cond
             ((eq 'RECPT (misc-info->type misc-info))
              (setq data 
                    (cons (blocking-do 'get-conf-stat 
                                       (misc-info->recipient-no misc-info))
                          data)))
             ((and (eq type 'footnote)
                   (eq 'CC-RECPT (misc-info->type misc-info)))
              (setq ccrep (cons (misc-info->recipient-no misc-info) 
                                ccrep))
David Byers's avatar
David Byers committed
1186
1187
1188
1189
1190
1191
1192
              (setq data (cons (blocking-do 'get-conf-stat
                                            (misc-info->recipient-no misc-info))
                               data)))
             ((and (eq type 'footnote)
                   (eq 'BCC-RECPT (misc-info->type misc-info)))
              (setq bccrep (cons (misc-info->recipient-no misc-info) 
                                 bccrep))
1193
1194
1195
1196
              (setq data (cons (blocking-do 'get-conf-stat
                                            (misc-info->recipient-no misc-info))
                               data))))))
         (text-stat->misc-info-list text-stat))
David Byers's avatar
David Byers committed
1197
1198
1199
1200
1201
1202
1203
        (lyskom-comment-recipients (nreverse data)
                                   lyskom-proc 
                                   text-stat
                                   subject 
                                   type 
                                   (nreverse ccrep) 
                                   (nreverse bccrep))))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1204
1205


1206
(defun lyskom-comment-recipients (data lyskom-proc text-stat
David Byers's avatar
David Byers committed
1207
				       subject type ccrep bccrep)
Per Cederqvist's avatar
.    
Per Cederqvist committed
1208
  "Compute recipients to a comment to a text.
David Byers's avatar
David Byers committed
1209
Args: DATA, LYSKOM-PROC TEXT-STAT SUBJECT TYPE CCREP BCCREP.
1210
1211
1212
DATA is a list of all the recipients that should receive this text.
If DATA contains more than one conference the user is asked (using y-or-n-p)
if all conferences really should receive the text.
1213
1214
The call is continued to the lyskom-edit-text.
TYPE is info whether this is going to be a comment of footnote.
David Byers's avatar
David Byers committed
1215
1216
CCREP is a list of all recipients that are going to be cc-recipients.
BCCREP is a list of all recipient that are going to be bcc-recipients."
1217

1218
  (condition-case nil
1219
      ;; Catch any quits
1220
1221
      (progn
	;; Filter multiple recipients through y-or-n-p.
1222
1223
	(if (and (eq kom-confirm-multiple-recipients 'before)
                 (> (length data) 1)
1224
1225
1226
		 (not (and (= (length data) 2)
			   (or (= lyskom-pers-no (conf-stat->conf-no
						  (car data)))
1227
			       (= lyskom-pers-no (conf-stat->conf-no
1228
1229
1230
						  (car (cdr data))))))))
	    (let ((new-data nil))
	      (while data
Linus Tolke's avatar
Linus Tolke committed
1231
		(if (lyskom-j-or-n-p (lyskom-format 'comment-keep-recpt-p
1232
1233
1234
1235
1236
1237
1238
1239
					     (conf-stat->name (car data))))
		    (setq new-data (cons (car data) new-data)))
		(setq data (cdr data)))
	      (setq data (nreverse new-data))))	    

	(let* ((member nil)
	       (recver (lyskom-create-misc-list
			(cond 
David Byers's avatar
David Byers committed
1240
1241
			 ((eq type 'comment) 'COMM-TO)
			 ((eq type 'footnote) 'FOOTN-TO)
1242
1243
1244
1245
1246
			 (t (signal 'lyskom-internal-error
				    (list "Unknown comment type" type))))
			(text-stat->text-no text-stat)))
	       (recpts nil))
	  (while data
1247
1248
1249
1250
1251
1252
	    (let* ((conf-stat (car data))
                   (confno (conf-stat->conf-no conf-stat))
                   (commno (if (eq type 'footnote)
                               confno
                             (conf-stat->comm-conf conf-stat))))
	      (if (memq commno recpts)
1253
1254
1255
1256
		  nil
		(setq recver
		      (append recver
			      (list
David Byers's avatar
David Byers committed
1257
			       (cons (cond
David Byers's avatar
David Byers committed
1258
1259
1260
                                      ((memq confno ccrep) 'CC-RECPT)
                                      ((memq confno bccrep) 'BCC-RECPT)
                                      (t 'RECPT))
1261
1262
                                     commno))))
		(if (lyskom-get-membership commno)
1263
		    (setq member t))
1264
		(setq recpts (cons commno recpts))))
1265
1266
1267
	    (setq data (cdr data)))
	  ;; Add the user to the list of recipients if he isn't a member in
	  ;; any of the recipients.
1268
	  (when (not member)
1269
	      (setq recver (append recver
1270
1271
1272
				   (list (cons 'RECPT
                                               (or (lyskom-get-send-comments-to lyskom-pers-no)
                                                   lyskom-pers-no))))))
1273
1274
1275
1276
	  (lyskom-edit-text lyskom-proc 
			    recver
			    subject "")))

David Byers's avatar
David Byers committed
1277
    (quit (signal 'quit nil))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1278
1279
1280
1281


;;; ================================================================
;;;                Personligt svar - personal answer
1282
;;;
Per Cederqvist's avatar
.    
Per Cederqvist committed
1283
;;; Author: ???
1284
;;; Rewritten using blocking-do by: Linus Tolke
Per Cederqvist's avatar
.    
Per Cederqvist committed
1285
1286


1287
(def-kom-command kom-private-answer (text-no)
1288
1289
1290
1291
1292
1293
1294
1295
1296
  "Write a private answer to the selected text.

Several settings affect writing texts in general.
`kom-write-texts-in-window' controls which window is used to write the
comment; `kom-confirm-multiple-recipients' affects how multiple
recipients are handled.

This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
1297
1298
1299
  :prompt-format (concat "%#1C " (if text-no
                                     (lyskom-format " (%#1n)" text-no)
                                   ""))
1300
  (interactive (list (lyskom-read-text-no-prefix-arg 'what-private-no)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1301
  (if text-no
1302
1303
1304
1305
1306
1307
      (blocking-do-multiple ((text-stat (get-text-stat text-no))
                             (text (get-text text-no)))
        (when (or (null (text-stat-find-aux text-stat 4))
                  (lyskom-j-or-n-p 
                   (lyskom-get-string 'no-comments-q)))
          (lyskom-private-answer-soon text-stat text text-no)))
1308
    (lyskom-insert-string 'confusion-who-to-reply-to)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1309
1310


1311
(defun lyskom-private-answer-soon (text-stat text text-no)
Per Cederqvist's avatar
.    
Per Cederqvist committed
1312
  "Write a private answer to TEXT-STAT, TEXT."
1313
  (if (and text-stat text)
1314
1315
1316
1317
      (let ((str (text->decoded-text-mass text text-stat)))
        (if (string-match "\n" str)
            (lyskom-private-answer text-stat
                                   (substring str
David Byers's avatar
David Byers committed
1318
                                              0 (match-beginning 0)))
David Byers's avatar
David Byers committed
1319
1320
          (lyskom-private-answer text-stat "")))
    (lyskom-format-insert 'no-such-text-no text-no)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1321
1322
1323
1324


(defun lyskom-private-answer (text-stat subject)
  "Write a private answer. Args: TEXT-STAT SUBJECT."
Joel Rosdahl's avatar
Joel Rosdahl committed
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
  (cond ((null text-stat)
         (lyskom-insert-string 'confusion-what-to-answer-to))
        ((= (text-stat->author text-stat) 0)
         (lyskom-insert-string 'personal-comment-to-anonymous))
        (t
         (lyskom-tell-internat 'kom-tell-write-reply)
         (cache-del-conf-stat (text-stat->author text-stat))
         (let* ((conf-stat (blocking-do 'get-conf-stat
                                        (text-stat->author text-stat))))
           (if (if (zerop (conf-stat->msg-of-day conf-stat))
                   t
                 (progn
                   (recenter 1)
                   (lyskom-format-insert 'has-motd
                                         conf-stat)
                   (lyskom-view-text (conf-stat->msg-of-day conf-stat))
                   (if (lyskom-j-or-n-p (lyskom-get-string 'motd-persist-q))
                       t
                     nil)))
David Byers's avatar
David Byers committed
1344
1345
1346

               (lyskom-edit-text lyskom-proc
                                 (if (= (text-stat->author text-stat) lyskom-pers-no)
Joel Rosdahl's avatar
Joel Rosdahl committed
1347
                                     (lyskom-create-misc-list
David Byers's avatar
David Byers committed
1348
1349
                                      'COMM-TO (text-stat->text-no text-stat)
                                      'RECPT (text-stat->author text-stat))
Joel Rosdahl's avatar
Joel Rosdahl committed
1350
                                   (lyskom-create-misc-list
David Byers's avatar
David Byers committed
1351
1352
1353
                                    'COMM-TO (text-stat->text-no text-stat)
                                    'RECPT (text-stat->author text-stat)
                                    'RECPT lyskom-pers-no))
David Byers's avatar
David Byers committed
1354
                                 subject ""))))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1355
1356


1357
1358
;;; ================================================================
;;;    Personligt svar p} f|reg}ende - kom-private-answer-previous
1359
;;;
1360
;;; Author: ceder