commands2.el 71.1 KB
Newer Older
1
;;;;; -*-coding: raw-text;-*-
Linus Tolke's avatar
Linus Tolke committed
2
3
;;;;;
;;;;; $Id$
4
;;;;; Copyright (C) 1991, 1996  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
5
6
7
8
9
;;;;;
;;;;; This file is part of the LysKOM server.
;;;;; 
;;;;; 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: commands2.el
;;;;
;;;; This file contains the code for some 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
48
;;; ================================================================
;;;              Lista medlemsskap - List membership

;;; Author: Linus Tolke
;;; Rewritten by ceder


49
;; This functions is left in its "asynchronous way".
David Kågedal's avatar
David Kågedal committed
50
(def-kom-command kom-membership ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
51
52
  "Show memberships last visited, priority, unread and name."
  (interactive)
David Byers's avatar
David Byers committed
53
  (let ((buffer (lyskom-get-buffer-create 'list-membership
David Byers's avatar
X    
David Byers committed
54
55
56
57
                                          (concat (buffer-name 
                                                   (current-buffer))
                                                  "-membership")
                                          t)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
58
59
    (save-window-excursion
      (set-buffer buffer)
David Byers's avatar
X    
David Byers committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
      (lyskom-view-mode)
      (lyskom-add-hook 'lyskom-new-membership-list-hook
                       'lyskom-update-membership-when-changed t)
      (setq truncate-lines t)
      (let ((inhibit-read-only t))
        (erase-buffer)
        (insert (lyskom-get-string 'your-memberships))
        (insert (lyskom-get-string 'memberships-header))))
    (save-selected-window
      (lyskom-display-buffer buffer))
    (lyskom-update-membership-buffer)))

(defun lyskom-update-membership-buffer ()
  (let ((buf (car (lyskom-buffers-of-category 'list-membership))))
    (when (buffer-live-p buf)
      (let ((inhibit-read-only t))
        (save-excursion (set-buffer buf)
                        (erase-buffer))
        (lyskom-traverse x lyskom-membership
          (initiate-get-conf-stat 'memberhsip 'lyskom-memb-received-1
                                  (membership->conf-no x)
                                  x buf))))))

(defun lyskom-update-membership-when-changed ()
  (let ((buffer (car (lyskom-buffers-of-category 'list-membership))))
    (if (buffer-live-p buffer)
        (save-excursion (set-buffer buffer)
                        (lyskom-update-membership-buffer))
      (lyskom-remove-hook 
       'lyskom-new-membership-list-hook
       'lyskom-update-membership-when-changed))))


93

Per Cederqvist's avatar
.  
Per Cederqvist committed
94
95
96
97
98
99
100
101
102
(defun lyskom-memb-received-1 (conf-stat membership buffer)
  "Part of kom-membership.
Get maps for the conference CONF-STAT. MEMBERSHIP is the users
membership in that conference. Call lyskom-memb-received with
the resulting MAP, CONF-STAT, MEMBERSHIP and BUFFER.
Args: CONF-STAT MEMBERSHIP BUFFER."
  (if (/= (conf-stat->conf-no conf-stat)
	  (membership->conf-no membership))
      (signal 'lyskom-internal-error '("lyskom-memb-received-1")))
103
104
105
106
  (let* ((first-wanted (1+ (membership->last-text-read membership)))
	 (last-existing  (+ (conf-stat->first-local-no conf-stat)
			    (conf-stat->no-of-texts conf-stat)
			    -1)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
107
108
109
    (if (> first-wanted last-existing)
	(lyskom-run 'membership 'lyskom-memb-received
		    nil conf-stat membership buffer)
110
111
112
113
114
115
116
117
118
119
      (if (> (- last-existing first-wanted) 50)
	  (lyskom-run 'membership 'lyskom-memb-received
		      (- last-existing first-wanted)
		      conf-stat membership buffer)
	(initiate-get-map 'membership 'lyskom-memb-received
			  (membership->conf-no membership)
			  first-wanted
			  (+ 1 last-existing
			     (- first-wanted))
			  conf-stat membership buffer)))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
120
121
122
123
124
125
126
127

(defun lyskom-memb-received (map conf-stat membership buffer)
  "Args: MAP CONF-STAT MEMBERSHIP BUFFER.
Prints membership in a conferences.
MAP may be nil if there are no new texts."
  (save-window-excursion
    (set-buffer buffer)
    (goto-char (point-max))
David Byers's avatar
X    
David Byers committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    (let ((lyskom-executing-command 'kom-membership)
          (lyskom-current-command 'kom-membership)
          (inhibit-read-only t))
      (lyskom-format-insert 'memberships-line
                            (lyskom-return-date-and-time
                             (membership->last-time-read
                              membership))
                            (membership->priority membership)
                            (cond
                             ((null map) 0)
                             ((numberp map) map)
                             ((listp map)
                              (length (lyskom-list-unread map membership)))
                             (t (signal
                                 'lyskom-internal-error
                                 '("Erroneous map in lyskom-memb-received"))))
                            conf-stat))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
145
146
147
148
149
150
151
152
153


;;; ================================================================
;;;          Status (f|r) M|te - Status for a conference

;;; Author: ceder (with some help by Linus)
;;; much enhanced by Inge Wallin (lyskom-status-conf-2 and beyond)


David Kågedal's avatar
David Kågedal committed
154
(def-kom-command kom-status-conf (&optional conf-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
155
156
157
158
  "Prints conference status.
If argument CONF-NO is existing and non-nil then this conference is used. 
otherwise: the conference is read with lyskom-completing-read."
  (interactive)
David Kågedal's avatar
David Kågedal committed
159
160
161
  (let ((conf-no
	 (or conf-no
	     (lyskom-read-conf-no (lyskom-get-string 'conf-for-status)
162
				  '(all) nil nil t)))
David Kågedal's avatar
David Kågedal committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
	conf-stat)
    (cache-del-conf-stat conf-no)
    (setq conf-stat (blocking-do 'get-conf-stat conf-no))
    (if (null conf-stat)
	(lyskom-insert-string 'no-such-conf)
      (let* ((type (conf-stat->conf-type conf-stat))
	     (box (conf-type->letterbox type))
	     (ori (conf-type->original type))
	     (pro (conf-type->rd_prot type))
	     (sec (conf-type->secret type)))
	(lyskom-format-insert 'status-record
			      conf-stat
			      conf-stat
			      (cond
			       ((or box ori pro sec)
David Kågedal's avatar
David Kågedal committed
178
179
180
181
182
183
184
185
186
187
188
189
				(concat
				 "("
				 (if box (lyskom-get-string 'Mailbox) "")
				 (if (and box (or sec ori pro)) ", " "")
				 (if sec (lyskom-get-string
					  'Protected) "")
				 (if (and sec (or ori pro)) ", " "")
				 (if ori (lyskom-get-string
					  'no-comments) "")
				 (if (and ori pro) ", " "")
				 (if pro (lyskom-get-string 'closed) "")
				 ")"))
David Kågedal's avatar
David Kågedal committed
190
			       (t ""))))
David Kågedal's avatar
David Kågedal committed
191
      (let ((creator (conf-stat->creator conf-stat)))
David Kågedal's avatar
David Kågedal committed
192
193
194
195
196
197
198
199
200
201
	(lyskom-format-insert 'created-by
			      creator
			      creator
			      (if (and 
				   (lyskom-conf-stat-p creator)
				   (> (length (conf-stat->name creator))
				      (- (lyskom-window-width) 46)))
				  "\n"
				"")))
      (lyskom-format-insert 'created-at
David Byers's avatar
David Byers committed
202
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
203
204
205
206
207
208
209
210
211
212
213
			     (conf-stat->creation-time conf-stat)))
      (lyskom-format-insert 'members
			    (conf-stat->no-of-members conf-stat))
      (lyskom-format-insert 'garb-nice
			    (conf-stat->garb-nice conf-stat))
      (lyskom-format-insert 'lowest-local-no
			    (conf-stat->first-local-no conf-stat))
      (lyskom-format-insert 'highest-local-no
			    (1- (+ (conf-stat->no-of-texts conf-stat)
				   (conf-stat->first-local-no conf-stat))))
      (lyskom-format-insert 'last-text-time
David Byers's avatar
David Byers committed
214
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
215
216
217
			     (conf-stat->last-written conf-stat)))
      (lyskom-format-insert 'no-of-motd
			    (conf-stat->msg-of-day conf-stat))
David Kågedal's avatar
David Kågedal committed
218
      (let ((superconf (conf-stat->super-conf conf-stat)))
David Kågedal's avatar
David Kågedal committed
219
220
221
222
223
224
225
226
227
	(lyskom-format-insert 'superconf-is-no-name
			      superconf
			      superconf
			      (if (and 
				   (lyskom-conf-stat-p superconf)
				   (> (length (conf-stat->name superconf))
				      (- (lyskom-window-width) 46)))
				  "\n"
				"")))
David Kågedal's avatar
David Kågedal committed
228
      (let ((permitted-submitters (conf-stat->permitted-submitters conf-stat)))
David Kågedal's avatar
David Kågedal committed
229
230
	(lyskom-format-insert 'permitted-submitters-no-name
			      permitted-submitters
David Kågedal's avatar
David Kågedal committed
231
232
233
234
235
			      (if (zerop permitted-submitters)
				  (lyskom-get-string 'Everybody)
				permitted-submitters)
			      ""))
      (let ((supervisor (conf-stat->supervisor conf-stat)))
David Kågedal's avatar
David Kågedal committed
236
237
238
	(lyskom-format-insert 'supervisor-is-no-name
			      supervisor
			      supervisor
David Kågedal's avatar
David Kågedal committed
239
			      ""))
David Kågedal's avatar
David Kågedal committed
240
241
242
243
244
245
246
247
      (lyskom-format-insert 'presentation-no
			    (conf-stat->presentation conf-stat))

      (if (zerop (conf-stat->msg-of-day conf-stat))
	  nil
	(lyskom-format-insert 'conf-has-motd conf-stat)
	(lyskom-view-text (conf-stat->msg-of-day conf-stat)))

248
      ;; Show all members of CONF-STAT if the user so wishes."
David Kågedal's avatar
David Kågedal committed
249
      (lyskom-scroll)
David Kågedal's avatar
David Kågedal committed
250
251
252
      (if (lyskom-j-or-n-p
	   (lyskom-get-string 'show-members-list-also-q))
	  (let ((member-list (blocking-do 'get-members
253
254
                                           (conf-stat->conf-no conf-stat)
                                           0 lyskom-max-int)))
David Kågedal's avatar
David Kågedal committed
255
256
257
258
259
260
261
262
	    
	    (lyskom-format-insert 'conf-has-these-members
				  conf-stat)
	    (if (lyskom-j-or-n-p (lyskom-get-string 'show-membership-info-q))
		
		(progn
		  (lyskom-insert-string 'member-list-header)
		  (lyskom-traverse 
263
		   member (member-list->members member-list)
David Kågedal's avatar
David Kågedal committed
264
265
		   (let ((membership (blocking-do
				      'query-read-texts 
266
				      (member->conf-no member)
David Kågedal's avatar
David Kågedal committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
				      (conf-stat->conf-no conf-stat))))
		     ;; Print a row describing the membership of MEMBER
		     ;; (described by MEMBERSHIP) in CONF-STAT.
		     (if (or (null membership))
			 (lyskom-insert-string 'secret-membership)
		       (lyskom-insert 
			(format "%17s"
				(lyskom-return-date-and-time
				 (membership->last-time-read membership))))
		       (let ((unread (- (+ (conf-stat->first-local-no
					    conf-stat)
					   (conf-stat->no-of-texts conf-stat))
					(membership->last-text-read membership)
					(length (membership->read-texts
						 membership))
					1)))
			 (lyskom-format-insert 'conf-membership-line
					       (if (zerop unread)
						   "         "
						 (format "%7d  " unread))
287
288
289
290
291
292
293
294
295
296
297
298
					       (member->conf-no member)
                                               (lyskom-return-membership-type (member->membership-type member))
                                               )
                         (when (and (member->created-by member)
                                    (not (zerop (member->created-by member)))
                                    (not (eq (member->conf-no member)
                                             (member->created-by member))))
                           (lyskom-format-insert 'conf-membership-line-2
                                                 (lyskom-return-date-and-time
                                                  (member->created-at member))
                                                 (member->created-by member)))
                         )))))
David Kågedal's avatar
David Kågedal committed
299
300
301
302
	      
	      ;; Don't show membership info
	      (lyskom-insert "\n")
	      (lyskom-traverse
303
304
305
	       member (member-list->members member-list)
	       (lyskom-format-insert "  %#1P\n" 
                                     (member->conf-no member)))))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
306
307
308
309
310
311
312
313
314


;;; ================================================================
;;;            Status (f|r) Person - status for a person

;;; Author: ceder
;;; Heavily enhanced: Inge Wallin (lyskom-status-pers-3 and beyond)


David Kågedal's avatar
David Kågedal committed
315
(def-kom-command kom-status-person (&optional pers-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
316
317
  "Prints status for a person."
  (interactive)
David Kågedal's avatar
David Kågedal committed
318
  (let ((pers-no
319
320
         (or pers-no
             (lyskom-read-conf-no (lyskom-get-string 'pers-for-status)
321
                                  '(pers) nil "" t)))
David Kågedal's avatar
David Kågedal committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
	conf-stat
	pers-stat)
    (cache-del-conf-stat pers-no)
    (cache-del-pers-stat pers-no)
    (setq pers-stat (blocking-do 'get-pers-stat pers-no))
    (setq conf-stat (blocking-do 'get-conf-stat pers-no))

    ;; "Print status about PERS-STAT. The name is in CONF-STAT"
    (if (or (null pers-stat)
	    (null conf-stat))
	(lyskom-insert-string 'no-such-pers)
      (lyskom-format-insert 'pers-status-record
			    conf-stat
			    conf-stat)
      (lyskom-format-insert 'created-time
David Byers's avatar
David Byers committed
337
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
			     (conf-stat->creation-time conf-stat)))

      (lyskom-format-insert 'created-confs
			    (pers-stat->created-confs pers-stat))
      (lyskom-format-insert 'created-persons
			    (pers-stat->created-persons pers-stat))
      (lyskom-format-insert 'created-texts
			    (1- (+ (pers-stat->no-of-created-texts pers-stat)
				   (pers-stat->first-created-text pers-stat))))
      (lyskom-format-insert 'created-lines
			    (pers-stat->created-lines pers-stat))
      (lyskom-format-insert 'created-chars
			    (pers-stat->created-bytes pers-stat))

      (lyskom-format-insert 'no-of-sessions
			    (pers-stat->sessions pers-stat))
      (if (zerop (pers-stat->total-time-present pers-stat))
	  nil
	(lyskom-format-insert 'present-time-d-h-m-s
			      (/ (pers-stat->total-time-present pers-stat)
				 (* 24 3600))
			      (% (/ (pers-stat->total-time-present pers-stat)
				    3600) 24)
			      (% (/ (pers-stat->total-time-present pers-stat)
				    60) 60)
			      (% (pers-stat->total-time-present pers-stat)
				 60)))
      (lyskom-format-insert 'last-log-in
David Byers's avatar
David Byers committed
366
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
367
368
369
370
371
			     (pers-stat->last-login pers-stat)))
      (lyskom-format-insert 'user-name
			    (pers-stat->username pers-stat))
      (lyskom-format-insert 'read-texts
			    (pers-stat->read-texts pers-stat))
372
373
      (if (= (pers-stat->pers-no pers-stat) lyskom-pers-no)
          (lyskom-format-insert 'marked-texts
David Kågedal's avatar
David Kågedal committed
374
				(pers-stat->no-of-marks pers-stat)))
David Kågedal's avatar
David Kågedal committed
375
      (lyskom-format-insert 'time-for-last-letter
David Byers's avatar
David Byers committed
376
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
377
378
			     (conf-stat->last-written conf-stat)))

David Kågedal's avatar
David Kågedal committed
379
      (let ((superconf (conf-stat->super-conf conf-stat)))
David Kågedal's avatar
David Kågedal committed
380
381
382
	(lyskom-format-insert 'superconf
			      superconf
			      superconf
David Kågedal's avatar
David Kågedal committed
383
			      ""))
David Kågedal's avatar
David Kågedal committed
384
      (if (not (zerop (conf-stat->supervisor conf-stat)))
David Kågedal's avatar
David Kågedal committed
385
	  (let ((supervisor (conf-stat->supervisor conf-stat)))
David Kågedal's avatar
David Kågedal committed
386
387
388
	    (lyskom-format-insert 'supervisor
				  supervisor
				  supervisor
David Kågedal's avatar
David Kågedal committed
389
				  "")))
David Kågedal's avatar
David Kågedal committed
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
      (lyskom-format-insert 'member-of-confs
			    (pers-stat->no-of-confs pers-stat))
      (lyskom-format-insert 'presentation
			    (conf-stat->presentation conf-stat))

      (if (not (zerop (conf-stat->msg-of-day conf-stat)))
	  (progn
	    (lyskom-format-insert 'has-motd conf-stat)
	    (lyskom-view-text (conf-stat->msg-of-day conf-stat))))

      ;; "Show all conferences CONF-STAT is a member of if the user so wishes."
      (lyskom-scroll)
      (if (null (lyskom-j-or-n-p (lyskom-get-string
				  'show-membership-list-also-q))) 
	  nil
	(let ((membership-list 
	       (blocking-do 'get-membership
			    (conf-stat->conf-no conf-stat)))
	      (lyskom-count-var 0))

	  (if (null membership-list)
	      (lyskom-format-insert 'not-allowed-see-confs conf-stat)
	    (lyskom-format-insert 'is-member-of conf-stat)
	    (lyskom-insert-string 'membership-list-header)
	    (setq lyskom-count-var 0)
	    (lyskom-traverse
David Kågedal's avatar
David Kågedal committed
416
417
418
419
420
421
422
423
	     membership membership-list
	     (let ((cs (cache-get-conf-stat
			(membership->conf-no membership))))
	       (and cs
		    (lyskom-time-greater
		     (membership->last-time-read membership)
		     (conf-stat->last-written conf-stat))
		    (cache-del-conf-stat (membership->conf-no membership))))
424
		  
David Kågedal's avatar
David Kågedal committed
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
	     ;; "Print a row describing the membership of
	     ;; MEMBER-CONF-STAT
	     (let ((member-conf-stat
		    (blocking-do 'get-conf-stat 
				 (membership->conf-no membership))))
	       (if (or (null member-conf-stat)
		       (null membership))
		   (lyskom-insert-string 'secret-membership)
		 (lyskom-insert 
		  (format "%17s"
			  (lyskom-return-date-and-time
			   (membership->last-time-read membership))))
		 (let ((unread (- (+ (conf-stat->first-local-no
				      member-conf-stat)
				     (conf-stat->no-of-texts
				      member-conf-stat))
				  (membership->last-text-read membership)
				  (length (membership->read-texts
					   membership))
				  1)))
		   (lyskom-format-insert
		    'pers-membership-line
		    (if (zerop unread) "       " (format "%6d " unread))
		    (if (= (conf-stat->conf-no conf-stat)
			   (conf-stat->supervisor member-conf-stat))
			(lyskom-get-string 'is-supervisor-mark)
		      "  ")
452
453
454
455
456
457
458
459
460
461
462
463
		    member-conf-stat
                    (lyskom-return-membership-type (membership->type membership))
                    )
                   (when (and (membership->created-by membership)
                              (not (zerop (membership->created-by membership)))
                              (not (eq (conf-stat->conf-no conf-stat)
                                       (membership->created-by membership))))
                     (lyskom-format-insert 'pers-membership-line-2
                                           (lyskom-return-date-and-time
                                            (membership->created-at membership))
                                           (membership->created-by membership)))

David Kågedal's avatar
David Kågedal committed
464
		   (setq lyskom-count-var (+ lyskom-count-var unread)))))))
David Kågedal's avatar
David Kågedal committed
465
466
467
468
469

	  ;; "Print the total number of unread texts for the person CONF-STAT."
	  (lyskom-format-insert 'his-total-unread 
				conf-stat
				lyskom-count-var))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
470
471
472
473
474
475
476



;;; ================================================================
;;;              Skicka meddelande - Send message

;;; Author: Inge Wallin
477
;;; Rewritten to use lyskom-read-conf-no by Linus Tolke
478
;;; Modified to use default recipient by David Byers
Per Cederqvist's avatar
.  
Per Cederqvist committed
479
480


481
(def-kom-command kom-send-message (&optional who message)
482
  "Send a message to one of the users in KOM right now."
Per Cederqvist's avatar
.  
Per Cederqvist committed
483
  (interactive)
David Kågedal's avatar
David Kågedal committed
484
485
486
487
  (let ((target (or who
		    (lyskom-read-conf-no
		     (format (lyskom-get-string 'who-to-send-message-to)
			     (lyskom-get-string 'everybody))
488
489
490
                     (if kom-permissive-completion
                         '(all)
                       '(login conf))
David Kågedal's avatar
David Kågedal committed
491
		     ;; Initial string:
492
                     t
David Kågedal's avatar
David Kågedal committed
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
		     (cond
		      ((eq kom-default-message-recipient 'everybody) nil)

		      ((and (eq kom-default-message-recipient 'group)
			    lyskom-last-group-message-recipient)
		       (cons lyskom-last-group-message-recipient 0))

		      ((or (and (eq kom-default-message-recipient 'group)
				(null lyskom-last-group-message-recipient))
			   (and (eq kom-default-message-recipient 'sender)
				lyskom-last-personal-message-sender))
		       (cons lyskom-last-personal-message-sender 0))

		      (t 
		       (if lyskom-last-personal-message-sender
			   (cons lyskom-last-personal-message-sender 0)
David Byers's avatar
David Byers committed
509
510
			 "")))
                     t))))
David Kågedal's avatar
David Kågedal committed
511
    (if (zerop target)
512
	(lyskom-insert (lyskom-get-string 'message-all-info))
David Kågedal's avatar
David Kågedal committed
513
514
      (lyskom-format-insert 'message-recipient-info target))
    (lyskom-send-message target message)))
Linus Tolke's avatar
Linus Tolke committed
515
  
516

517
(def-kom-command kom-send-alarm (&optional message)
518
519
  "Send a message to all of the users in KOM right now."
  (interactive)
520
  (lyskom-send-message 0 message))
Per Cederqvist's avatar
.  
Per Cederqvist committed
521
522


David Byers's avatar
David Byers committed
523
524
525
526
(defvar lyskom-message-recipient)
(defvar lyskom-message-string)


David Byers's avatar
David Byers committed
527
528
529
530
531
532
533
534
535
536
537
538
(defun lyskom-send-message-minibuffer-setup-hook ()
  (unwind-protect
      (run-hooks 'lyskom-send-message-setup-hook)
    (remove-hook 'minibuffer-setup-hook 
                 'lyskom-send-message-minibuffer-setup-hook)))

(defun lyskom-send-message-minibuffer-exit-hook ()
  (unwind-protect
      (run-hooks 'lyskom-send-message-exit-hook)
    (remove-hook 'minibuffer-exit-hook
                 'lyskom-send-message-minibuffer-exit-hook)))

David Byers's avatar
David Byers committed
539
540
(defun lyskom-send-message (pers-no
                            message &optional dontshow)
David Byers's avatar
David Byers committed
541
542
543
  "Send a message to the person with the number PERS-NO.  PERS-NO == 0
means send the message to everybody. MESSAGE is the message to
send. If DONTSHOW is non-nil, don't display the sent message."
David Byers's avatar
David Byers committed
544
  (let* ((lyskom-message-string nil)
David Byers's avatar
David Byers committed
545
         (reply nil)
David Byers's avatar
David Byers committed
546
547
         (lyskom-message-recipient nil)
         (lyskom-last-text-format-flags nil))
David Byers's avatar
David Byers committed
548
549

    (add-hook 'minibuffer-setup-hook
David Byers's avatar
David Byers committed
550
              'lyskom-send-message-minibuffer-setup-hook)
David Byers's avatar
David Byers committed
551
    (add-hook 'minibuffer-exit-hook
David Byers's avatar
David Byers committed
552
              'lyskom-send-message-minibuffer-exit-hook)
David Byers's avatar
David Byers committed
553
554
    (setq lyskom-message-string 
          (or message
David Byers's avatar
David Byers committed
555
556
557
              (lyskom-read-string (lyskom-get-string 'message-prompt)
                                  nil
                                  'lyskom-message-history)))
David Byers's avatar
David Byers committed
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
    (setq lyskom-message-recipient (if (zerop pers-no)
                                       nil
                                     (blocking-do 'get-conf-stat 
                                                  pers-no)))

    (run-hooks 'lyskom-send-message-hook)
    (if lyskom-message-string
        (progn
          (setq reply (blocking-do 'send-message pers-no
                                   lyskom-message-string))

          (if reply
              (if (not dontshow)
                  (lyskom-handle-as-personal-message
                   (if lyskom-message-recipient
                       (lyskom-format 'message-sent-to-user
                                      lyskom-message-string 
                                      lyskom-message-recipient)
                     (lyskom-format 'message-sent-to-all
                                    lyskom-message-string))
                   lyskom-pers-no
                   lyskom-filter-outgoing-messages))
            (lyskom-format-insert-before-prompt
             'message-nope 
             (or lyskom-message-recipient
                 (lyskom-get-string 'everybody))
             lyskom-message-string)))
      (lyskom-insert-string 'interrupted))                   ;+++ lyskom-errno
586
    ))
Per Cederqvist's avatar
.  
Per Cederqvist committed
587

David Byers's avatar
David Byers committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
(defun lyskom-send-message-trim-newlines ()
  (let ((size (length lyskom-message-string)))
    (while (and (> size 0)
                (eq ?\n (aref lyskom-message-string (1- size))))
      (setq size (1- size)))
    (cond ((and (eq size 0)
                (not (lyskom-j-or-n-p (lyskom-get-string 
                                       'send-empty-message-p))))
           (setq lyskom-message-string nil))
          ((eq size 0)
           (setq lyskom-message-string ""))
          (t (setq lyskom-message-string (substring lyskom-message-string 
                                                    0 size))))))

602
603
604
(lyskom-external-function lyskom-resize-minibuffer-mode)
(lyskom-external-function resize-minibuffer-setup)

605
606
607
608
609
610
611
(defun lyskom-send-message-turn-off-resize-on-exit ()
  (resize-minibuffer-mode -1)
  (remove-hook 'lyskom-send-message-exit-hook
               'lyskom-send-message-turn-off-resize-on-exit))
               
(defun lyskom-send-message-resize-minibuffer ()
  "Temporarily turn on resizing of minibuffer"
David Byers's avatar
David Byers committed
612
613
614
615
616
617
618
619
620
  (let ((tmp nil))
    (if (not resize-minibuffer-mode)
        (progn
          (if (not (memq 'resize-minibuffer-setup minibuffer-setup-hook))
              (setq tmp t))
          (resize-minibuffer-mode 0)
          (if tmp (resize-minibuffer-setup))
          (add-hook 'lyskom-send-message-exit-hook
                    'lyskom-send-message-turn-off-resize-on-exit)))))
621
622
623
624


(defun lyskom-send-message-auto-fill ()
  "Temporarily turn on auto fill in minibuffer"
David Byers's avatar
X    
David Byers committed
625
  (setq fill-column 78)                 ;+++ Ta bort?
626
627
  (auto-fill-mode 1))

Per Cederqvist's avatar
.  
Per Cederqvist committed
628
629
630
631
632
633
634


;;; ================================================================
;;;       Endast l{sa senaste - Set unread articles in a conf. 
;;;            (Skip or re-read articles).

;;; Author: Linus Tolke
635
;;; Rehacked: David K}gedal
Per Cederqvist's avatar
.  
Per Cederqvist committed
636
637


638
(def-kom-command kom-set-unread (&optional arg conf-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
639
  "Set number of unread articles in current conference."
640
  (interactive "P")
641
  (setq conf-no (or conf-no lyskom-current-conf))
642
  (if (and (zerop lyskom-current-conf) (null conf-no))
643
644
645
      (progn
        (lyskom-insert-string 'not-present-anywhere)
        (lyskom-insert-string "\n"))
646
    (let ((conf-stat (blocking-do 'get-conf-stat conf-no)))
647
648
649
650
651
652
653
654
655
656
657
658
      (if (null conf-stat)              ;+++ annan errorhantering
          (lyskom-insert "Error!\n")	;+++ Hrrrmmmmffff????
        (let* ((narg (prefix-numeric-value arg))
               (n (if (and arg
                           (<= 0 narg)
                           (<= narg (conf-stat->no-of-texts conf-stat)))
                      narg
                    (lyskom-read-num-range 
                     0 (conf-stat->no-of-texts conf-stat)
                     (lyskom-format 'only-last
                                    (conf-stat->no-of-texts conf-stat)
                                    (conf-stat->name conf-stat)))))
659
660
661
662
663
	       (result (blocking-do 'set-unread conf-no n))
               (membership (blocking-do 'query-read-texts
					lyskom-pers-no
					conf-no))
	       )
David Byers's avatar
David Byers committed
664
          (ignore result)
665
666
667
668
669
670
	  (lyskom-replace-membership membership lyskom-membership)
	  (if (= conf-no lyskom-current-conf)
	      (set-read-list-empty lyskom-reading-list))
	  (read-list-delete-read-info conf-no lyskom-to-do-list)
	  (lyskom-prefetch-map conf-no membership)
	  )))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
671
672
673
674
675
676
677
678
679
680



;;; ================================================================
;;;                 Lista Nyheter - List News

;;; Author:   Linus Tolke
;;; Rehacked: Inge Wallin


681
(defvar lyskom-special-conf-name "\\`\\(Inl.gg .t mig\\|NL:\\)\\'"
682
683
  "Regexp to match conf names that are special.")

David Kågedal's avatar
David Kågedal committed
684
(def-kom-command kom-list-news (&optional num)
Per Cederqvist's avatar
.  
Per Cederqvist committed
685
  "Print the number of unread articles to the user."
David Kågedal's avatar
David Kågedal committed
686
  (interactive "P")
David Kågedal's avatar
David Kågedal committed
687

688
689
690
  (unless kom-allow-incompleteness
    (sit-for 0)
    (lyskom-prefetch-all-confs))
David Kågedal's avatar
David Kågedal committed
691

David Kågedal's avatar
David Kågedal committed
692
  (let ((num-arg (cond
693
694
695
696
697
                  ((numberp num) num)
                  ((and (listp num)
                        (numberp (car num))) (car num))
                  (t nil)))
        (sum 0))
Per Cederqvist's avatar
.  
Per Cederqvist committed
698
699
700
    (mapcar
     (function
      (lambda (info)
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
        (let ((un (length (cdr (read-info->text-list info))))
              (name (conf-stat->name (read-info->conf-stat info)))
              (conf-stat (read-info->conf-stat info)))
          (cond
           ((eq (read-info->type info) 'CONF)
            (if (or (not num-arg)
                    (>= (-- num-arg) 0))
                (lyskom-insert 
                 (if (and (boundp 'lyskom-special-conf-name)
                          (stringp lyskom-special-conf-name)
                          (string-match lyskom-special-conf-name name))
                     (if (/= un 1)
                         (lyskom-format 'you-have-unreads-special un conf-stat)
                       (lyskom-format 'you-have-an-unread-special conf-stat))
                   (if (/= un 1)
                       (lyskom-format 'you-have-unreads un conf-stat)
                     (lyskom-format 'you-have-an-unread conf-stat)))))
            (setq sum (+ sum un)))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
719
720
     (read-list->all-entries lyskom-to-do-list))
    (if (= 0 sum)
721
        (lyskom-insert-string 'you-have-read-everything)
Per Cederqvist's avatar
.  
Per Cederqvist committed
722
723
      (lyskom-insert 
       (if (/= sum 1)
724
725
726
           (lyskom-format 'total-unreads 
                          sum)
         (format (lyskom-get-string 'total-unread)))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741


;;; ================================================================
;;; 			V{nta - Idle wait


(defun kom-busy-wait (arg)
  "Sets the kom-session in wait-mode.
The wait-mode is interrupted when a text in a conference with higher priority
than that of the next text to be read.
If you want another priority to break that the ones higher that the next text 
to be read, give the priority as a prefix argument.
When a text is received the new text is displayed."
  (interactive "P")
  (lyskom-start-of-command 'kom-busy-wait)
David Kågedal's avatar
David Kågedal committed
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
  (unwind-protect
      (let ((waitfor (or (cond
			  ((integerp arg) arg)
			  ((listp arg) (car arg)))
			 (read-info->priority
			  (read-list->first lyskom-to-do-list))
			 -2)))
	(lyskom-tell-server kom-mercial)
	(if (not (read-list-isempty lyskom-reading-list))
	    (set-read-list-empty lyskom-reading-list))
	(if (= waitfor -2)
	    (lyskom-insert-string 'waiting-for-anything)
	  (lyskom-format-insert 'waiting-higher-than waitfor))
	(lyskom-scroll)
	(setq lyskom-is-waiting
	      (list '>
		    '(or (read-info->priority
			  (read-list->first lyskom-reading-list))
			 (read-info->priority
			  (read-list->first lyskom-to-do-list))
			 257)
		    waitfor))
	(while lyskom-is-waiting
	  ;; This is a bit trial-and-error stuff at the momemt.
	  ;; o How to make personal messages appear *fast*
	  ;; o How to enable C-g with a quick response
David Kågedal's avatar
David Kågedal committed
768
	  (sit-for 0)
David Kågedal's avatar
David Kågedal committed
769
770
771
772
773
774
	  (accept-process-output nil 1)
	  (sit-for 0)
	  (if lyskom-quit-flag
	      (signal 'quit nil))))
    (lyskom-end-of-command))
  ;; We are done waiting
775
  (lyskom-beep kom-ding-on-wait-done)
David Kågedal's avatar
David Kågedal committed
776
777
778
779
  (if (read-list-isempty lyskom-reading-list)
      (kom-go-to-next-conf))
  (kom-next-command))
  
Per Cederqvist's avatar
.  
Per Cederqvist committed
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799


(defun lyskom-time-greater (time1 time2)
  "Returns t if TIME2 is before TIME1 chronologically."
  (cond
   ((< (time->year time2) (time->year time1)))
   ((< (time->mon time2) (time->mon time1)))
   ((< (time->mday time2) (time->mday time1)))
   ((< (time->hour time2) (time->hour time1)))
   ((< (time->min time2) (time->min time1)))
   ((< (time->sec time2) (time->sec time1)))
   (t nil)))


;;; ================================================================
;;;               Lista {rende - list summary

;;; Author: Linus Tolke


David Kågedal's avatar
David Kågedal committed
800
(def-kom-command kom-list-summary ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
801
802
803
804
  "List a summary of the unread in the current conf.
The summary contains the date, number of lines, author and subject of the text
on one line."
  (interactive)
David Kågedal's avatar
David Kågedal committed
805
806
  (if (read-list-isempty lyskom-reading-list)
      (lyskom-insert-string 'have-to-be-in-conf-with-unread)
807
	
David Kågedal's avatar
David Kågedal committed
808
809
810
    (lyskom-list-summary
      (text-list->texts 
       (read-info->text-list 
811
	(let ((len (read-list-length lyskom-reading-list))
David Kågedal's avatar
David Kågedal committed
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
	      (r 0))
	  (while (< r len)
	    (let ((type (read-info->type 
			 (read-list->nth lyskom-reading-list
					 r))))
	      (if (or (eq type 'CONF)
		      (eq type 'REVIEW-MARK)
		      (eq type 'REVIEW))
		  (setq len 0)
		(++ r))))
	  (read-list->nth lyskom-reading-list r)))))))


(defun lyskom-list-summary (texts)
  "List a summary of the texts in TEXTS.
The summary contains the date, number of lines, author and subject of the text
on one line."
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
  (let ((time (blocking-do 'get-time))
	(author-width (/ (- (lyskom-window-width) 22) 3)))
    
    ;; Start fetching all text-stats and text to list them.
    (lyskom-format-insert (concat "%-8#1s%-6#2s%-4#3s %-"
				  (int-to-string author-width)
				  "#4s  %#5s\n")
			  (lyskom-get-string 'Texts)
			  (lyskom-get-string 'Date)
			  (lyskom-get-string 'Lines)
			  (lyskom-get-string 'Author)
			  (lyskom-get-string 'Subject))
    (lyskom-traverse
	text-no texts
      (let ((text-stat (blocking-do 'get-text-stat text-no))
	    (text (blocking-do 'get-text text-no))
	    ;; We could do som optimization here. 
	    ;; We really don't need the whole text.
	    )
	(lyskom-print-summary-line text-stat text text-no 
849
850
				   (time->year time) (time->yday time))
	(sit-for 0)))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
851
852


David Kågedal's avatar
David Kågedal committed
853
(defun lyskom-print-summary-line (text-stat text text-no year day)
Per Cederqvist's avatar
.  
Per Cederqvist committed
854
855
856
857
858
859
860
861
862
863
  "Handle the info, fetch the author and print it.
Args: TEXT-STAT TEXT TEXT-NO YEAR DAY.
The year and day is there to be able to choose format on the day.
Format is 23:29 if the text is written today. Otherwise 04-01."
  (if (not (and text-stat text))	;+++ B{ttre felhantering.
      (lyskom-format-insert 'could-not-read text-no)
    (let* ((lines (text-stat->no-of-lines text-stat))
	   (txt (text->text-mass text))
	   (eos (string-match (regexp-quote "\n") txt))
	   (subject (substring txt 0 eos))
David Byers's avatar
David Byers committed
864
	   ;; length of the number %%%%%% :8
Per Cederqvist's avatar
.  
Per Cederqvist committed
865
866
867
868
869
870
871
872
873
874
	   ;; length for time is: 6
	   (time (text-stat->creation-time text-stat))
	   (time (if (and (= year (time->year time))
			  (= day (time->yday time)))
		     (format "%02d:%02d" (time->hour time)
			     		 (time->min time))
		   (format "%02d-%02d" (1+ (time->mon time))
			   	       (time->mday time))))
	   ;; length for lines is: 4
	   ;; We split the rest between author and subject
David Byers's avatar
David Byers committed
875
876
	   (namelen (/ (- (lyskom-window-width) 22) 3))
	   (subjlen (/ (* (- (lyskom-window-width) 22) 2) 3))
877
878
879
880
881
882
	   (format-string (concat "%=-8#1n%#2s%4#3d  %=-"
				  (int-to-string namelen)
				  "#4P  %[%#5@%=-"
				  (int-to-string subjlen)
				  "#6r%]\n")))
      (lyskom-format-insert format-string
883
884
885
			    text-no
			    time
			    lines
886
			    (text-stat->author text-stat)
887
888
			    (lyskom-default-button 'text
						   text-no)
889
			    subject))))
890

Per Cederqvist's avatar
.  
Per Cederqvist committed
891
892


David Byers's avatar
David Byers committed
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
;;; ============================================================
;;; kom-list-marks                      Lista markeringar
;;; Author: David Byers

(def-kom-command kom-list-marks (&optional which-mark)
  (interactive "P")
  (when (not (numberp which-mark))
    (setq which-mark (lyskom-read-num-range 
                      0 255
                      (lyskom-get-string 'list-which-mark) nil nil nil t)))
  (let ((marks
         (sort (listify-vector (blocking-do 'get-marks))
               (lambda (a b) (< (mark->mark-type a) (mark->mark-type b))))))
  (let ((time (blocking-do 'get-time))
	(author-width (/ (- (lyskom-window-width) 26) 3)))
    
    ;; Start fetching all text-stats and text to list them.
    (lyskom-format-insert (concat "%-4#6s%-8#1s%-6#2s%-4#3s %-"
				  (int-to-string author-width)
				  "#4s  %#5s\n")
			  (lyskom-get-string 'Texts)
			  (lyskom-get-string 'Date)
			  (lyskom-get-string 'Lines)
			  (lyskom-get-string 'Author)
			  (lyskom-get-string 'Subject)
                          (lyskom-get-string 'mark-type))
;    (lyskom-insert (make-string (1- (window-width)) ?-))
;    (lyskom-insert "\n")
    (lyskom-traverse
	mark marks
      (when (or (null which-mark)
                (eq (mark->mark-type mark) which-mark))
        (let* ((text-no (mark->text-no mark))
               (text-stat (blocking-do 'get-text-stat text-no))
               (text (blocking-do 'get-text text-no))
	    ;; We could do som optimization here. 
	    ;; We really don't need the whole text.
	    )
          (lyskom-print-mark-summary-line mark text-stat text text-no 
                                     (time->year time) (time->yday time))
          (sit-for 0))))
;    (lyskom-insert (make-string (1- (window-width)) ?-))
;    (lyskom-insert "\n")
    )))
                           
(defun lyskom-print-mark-summary-line (mark text-stat text text-no year day)
  "Handle the info, fetch the author and print it.
Args: TEXT-STAT TEXT TEXT-NO YEAR DAY.
The year and day is there to be able to choose format on the day.
Format is 23:29 if the text is written today. Otherwise 04-01."
  (lyskom-format-insert "%3#1d " (mark->mark-type mark))
  (if (not (and text-stat text))	;+++ B{ttre felhantering.
      (lyskom-format-insert 'could-not-read text-no)
    (let* ((lines (text-stat->no-of-lines text-stat))
	   (txt (text->text-mass text))
	   (eos (string-match (regexp-quote "\n") txt))
	   (subject (substring txt 0 eos))
	   ;; length of the number %%%%%% :8
	   ;; length for time is: 6
	   (time (text-stat->creation-time text-stat))
	   (time (if (and (= year (time->year time))
			  (= day (time->yday time)))
		     (format "%02d:%02d" (time->hour time)
			     		 (time->min time))
		   (format "%02d-%02d" (1+ (time->mon time))
			   	       (time->mday time))))
	   ;; length for lines is: 4
	   ;; We split the rest between author and subject
	   (namelen (/ (- (lyskom-window-width) 26) 3))
	   (subjlen (/ (* (- (lyskom-window-width) 26) 2) 3))
	   (format-string (concat "%=-8#1n%#2s%4#3d  %=-"
				  (int-to-string namelen)
				  "#4P  %[%#5@%=-"
				  (int-to-string subjlen)
				  "#6r%]\n")))
      (lyskom-format-insert format-string
			    text-no
			    time
			    lines
			    (text-stat->author text-stat)
			    (lyskom-default-button 'text
						   text-no)
			    subject))))


David Byers's avatar
David Byers committed
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
;;; ============================================================
;;;     kom-who-am-i - Vem r jag
;;;
;;; Author: David Byers

(def-kom-command kom-who-am-i ()
  "Show my name"
  (interactive)
  (if (and lyskom-current-conf
           (not (zerop lyskom-current-conf)))
      (lyskom-format-insert 'who-i-am-present 
                            lyskom-pers-no
                            lyskom-current-conf)
    (lyskom-format-insert 'who-i-am-not-present lyskom-pers-no))

  (lyskom-format-insert 
   'who-i-am-server
   lyskom-server-name
996
   (version-info->software-version lyskom-server-version-info))
David Byers's avatar
David Byers committed
997
998
999
1000

  (lyskom-format-insert 'who-i-am-client
                        lyskom-clientversion)

For faster browsing, not all history is shown. View entire blame