view-text.el 24.1 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1 2
;;;;;
;;;;; $Id$
3
;;;;; Copyright (C) 1991, 1996  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4 5 6 7 8
;;;;;
;;;;; 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 
9
;;;;; the Free Software Foundation; either version 2, or (at your option) 
Linus Tolke Y's avatar
Linus Tolke Y committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
;;;;; 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
25 26 27 28 29 30 31 32 33 34
;;; ================================================================
;;; ================================================================
;;;
;;; File: view-text.el
;;; 
;;; This file contains functions that have to do with putting
;;; a text into the lyskom buffer.
;;;


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


40 41
(defun lyskom-view-text (text-no &optional mark-as-read
				 follow-comments conf-stat priority
42
				 build-review-tree filter-active)
43 44
  "Display text number TEXT-NO.
Args: TEXT-NO &optional MARK-AS-READ FOLLOW-COMMENTS CONF-STAT 
Per Cederqvist's avatar
.  
Per Cederqvist committed
45 46 47 48 49 50
PRIORITY BUILD-REVIEW-TREE.
If MARK-AS-READ is non-nil the text will be marked as read.
If FOLLOW-COMMENTS is non-nil all comments and footnotes to this text will be
read before the next text. CONF-STAT must be the conference status of the
current conference, and PRIORITY the priority, if FOLLOW-COMMENTS is non-nil.
If BUILD-REVIEW-TREE is non-nil then it fixes a new entry in the 
51 52 53
lyskom-reading-list to read the comments to this.

Note that this function must not be called asynchronously."
54

55 56
  (let ((inhibit-read-only t)
	(filter (and filter-active
David Byers's avatar
David Byers committed
57 58 59
                     (lyskom-filter-text-p text-no)))
        (start nil)
        (end nil)
David Byers's avatar
David Byers committed
60 61
        (todo nil)
        (lyskom-last-text-format-flags nil))
62
    (cond ((eq filter 'skip-text) (lyskom-filter-prompt text-no 'filter-text)
63
	   (setq todo 'next-text)
David Kågedal's avatar
David Kågedal committed
64
	   (lyskom-mark-as-read (blocking-do 'get-text-stat text-no))
65 66 67
	   'next-text)
	  ((eq filter 'skip-tree)
	   (lyskom-filter-prompt text-no 'filter-tree)
David Kågedal's avatar
David Kågedal committed
68 69 70 71 72 73

	   ;;(initiate-get-text-stat 'main 'lyskom-jump text-no t)
	   ;; Let's try something else:
	   (lyskom-jump (blocking-do 'get-text-stat text-no) t)
	   (lyskom-wait-queue 'main)

74
	   (setq todo 'next-text)
75 76 77 78 79
	   'next-text)
	  (t
	   (if (not (or (null filter) 
			(eq filter 'dontshow)))
	       (lyskom-message "%s" (lyskom-get-string 'invalid-filter-list)))
80
	   (if (eq filter 'dontshow)
81
	       (setq todo 'next-text))
82 83 84 85 86
	   (blocking-do-multiple ((text-stat (get-text-stat text-no))
				  (text (get-text text-no)))
	     (if (and text-stat
		      text)
		 (progn
87
                   (run-hooks 'lyskom-view-text-hook)
88 89 90
		   ;; Use a marker, because the buffer may lose data
		   ;; at the top if kom-max-buffer-size is set.
		   (setq start (point-max-marker))
91 92
		   (lyskom-format-insert "%#1n " 
					 text-stat)
93
		   (lyskom-print-date-and-time (text-stat->creation-time
David Kågedal's avatar
David Kågedal committed
94 95
						text-stat)
					       'time-y-m-d-h-m)
96 97 98 99 100 101 102 103 104
		   (lyskom-insert 
		    (if (= 1 (text-stat->no-of-lines text-stat))
			(lyskom-get-string 'line)
		      (lyskom-format 'lines 
				     (let ((n (text-stat->no-of-lines
					       text-stat)))
				       (if (= n 0) ; Added to increase
					   2 ; compatibility with old KOM. /lw
					 n)))))
105 106 107
		   
		   (if (eq filter 'dontshow)
		       (lyskom-format-insert "%#1P %#2s\n"
108 109
					     (text-stat->author text-stat)
					     (lyskom-get-string 'filtered))
110
		     (lyskom-format-insert "%#1P\n"
111
					   (text-stat->author text-stat)))
112
		   
113
		   (setq end (point-max))
David Byers's avatar
David Byers committed
114

David Kågedal's avatar
David Kågedal committed
115 116
		   (if (and kom-text-properties
			    (null filter)
117
			    (not (lyskom-face-default-p 'kom-first-line-face)))
David Kågedal's avatar
David Kågedal committed
118 119
		       (add-text-properties
			start end '(face kom-first-line-face)))
120
		   (set-marker start nil)
David Byers's avatar
David Byers committed
121

122
		   ;; All recipients and other header lines.
123 124

		   (if (eq filter 'dontshow)
David Kågedal's avatar
David Kågedal committed
125 126
		       (lyskom-mark-as-read
			(blocking-do 'get-text-stat text-no))
127 128 129 130 131 132 133
		     (lyskom-traverse misc
			 (text-stat->misc-info-list text-stat)
		       (let ((type (misc-info->type misc)))
			 (cond
			  ((or (eq type 'RECPT)
			       (eq type 'CC-RECPT))
			   (lyskom-print-header-recpt 
David Kågedal's avatar
David Kågedal committed
134
			    (misc-info->recipient-no misc)
135 136 137 138
			    misc))
			  ((eq type 'COMM-IN)
			   (if kom-reading-puts-comments-in-pointers-last
			       nil
139 140 141 142
                             (if lyskom-show-comments ; +++SOJGE
                                 (lyskom-print-header-comm
                                  (misc-info->comm-in misc)
                                  misc))))
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
			  ((eq type 'FOOTN-IN)
			   (if kom-reading-puts-comments-in-pointers-last
			       nil
			     (lyskom-print-header-comm
			      (misc-info->footn-in misc)
			      misc)))
			  ((eq type 'COMM-TO)
			   (lyskom-print-header-comm (misc-info->comm-to misc)
						     misc))
			  ((eq type 'FOOTN-TO)
			   (lyskom-print-header-comm (misc-info->footn-to misc)
						     misc))
			  )))
		     (let ((num-marks (text-stat->no-of-marks text-stat))
			   (is-marked-by-me (cache-text-is-marked
					     (text-stat->text-no text-stat))))
		       (if (> num-marks 0)
			   (lyskom-insert 
			    (if is-marked-by-me
				(if (= num-marks 1)
				    (lyskom-get-string 'marked-by-you)
				  (if (= num-marks 2)
				      (lyskom-get-string 
				       'marked-by-you-and-one)
				    (lyskom-format 'marked-by-you-and-several
						   (1- num-marks))))
169
			      (if (= num-marks 1)
170 171 172
				  (lyskom-get-string 'marked-by-one)
				(lyskom-format 'marked-by-several
					       num-marks))))))
173
		   
174
		     (lyskom-print-text text-stat text
175
					mark-as-read text-no))
176 177 178 179 180 181
		   
		   
		   (if kom-reading-puts-comments-in-pointers-last
		       (lyskom-view-text-handle-saved-comments text-stat))
		   
		   (if (or follow-comments
David Kågedal's avatar
David Kågedal committed
182 183
			   ;; Checking build-review-tree should not be
			   ;; necessary, really /davidk
184 185
			   build-review-tree)
		       ;; This shows footnotes also.
186 187 188 189 190 191 192
		       (progn
			 ;; this is a bit silly, as it prefetches all
			 ;; the texts many times.
			 (lyskom-prefetch-texttree text-no)
			 (lyskom-follow-comments text-stat
						 conf-stat mark-as-read
						 priority build-review-tree)))
193
		   )
194
	       (lyskom-format-insert 'no-such-text-no text-no)))))
195
    todo))
196
	  
197 198 199 200 201
	  


(defun lyskom-follow-comments (text-stat conf-stat 
					 mark-as-read priority review-tree)
Per Cederqvist's avatar
.  
Per Cederqvist committed
202
  "Arrange so that all comments and footnotes to this text will be read.
203 204 205 206
This will essentially fix the reading list and issue calls for the cache to be
filled.

Arguments are: TEXT-STAT CONF-STAT PRIORITY REVIEW-TREE
Per Cederqvist's avatar
.  
Per Cederqvist committed
207 208 209 210 211
TEXT-STAT is the current text.
CONF-STAT the current conference
PRIORITY the priority of the reading.
If REVIEW-TREE is non-nil then build an entry of type 'REVIEW-TREE in the 
lyskom-reading-list."
212 213 214 215
  ;; . Find footnotes and show them.
  ;; . Fix the reading-list
  ;; . Issue cache-filling initiate-calls for everything left comments.
  
David Kågedal's avatar
David Kågedal committed
216
  (let (flist clist)
217 218 219 220 221 222
    (lyskom-traverse misc (text-stat->misc-info-list text-stat)
      (cond
       ((and (eq (misc-info->type misc) 'FOOTN-IN)
	     (> (misc-info->footn-in misc) (text-stat->text-no text-stat))
	     kom-show-footnotes-immediately)
	;; Show the footnote
David Kågedal's avatar
David Kågedal committed
223 224
	(lyskom-view-text (misc-info->footn-in misc)
			  mark-as-read t conf-stat priority review-tree)
225 226
	(lyskom-is-read (misc-info->footn-in misc)))
       ((eq (misc-info->type misc) 'FOOTN-IN)
David Kågedal's avatar
David Kågedal committed
227
	(setq flist (cons (misc-info->footn-in misc) flist)))
228
       ((eq (misc-info->type misc) 'COMM-IN)
229
        (if lyskom-show-comments        ; +++SOJGE
David Kågedal's avatar
David Kågedal committed
230 231 232 233 234 235 236 237 238 239 240
            (setq clist (cons (misc-info->comm-in misc) clist))))))
    
    (let (comments footnotes)
      ;; Find the comments that we should read and enter them into the
      ;; read-list.
      (lyskom-traverse no clist
	(let ((text-stat (blocking-do 'get-text-stat no)))
	  (if (or review-tree
		  (and text-stat
		       (not (lyskom-text-read-p text-stat))))
	      (setq comments (cons no comments)))))
241 242 243 244 245 246 247
      (if comments
	  (read-list-enter-read-info
	   (lyskom-create-read-info (if review-tree 'REVIEW-TREE 'COMM-IN)
				    conf-stat priority
				    (lyskom-create-text-list comments)
				    (text-stat->text-no text-stat))
	   lyskom-reading-list t))
David Kågedal's avatar
David Kågedal committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
      ;; Find the footnotes that we should read and enter them into
      ;; the read-list. A slight trick is to increase the priority so
      ;; that they will be read first.
      (lyskom-traverse no flist
	(let ((text-stat (blocking-do 'get-text-stat no)))
	  (if (or review-tree
		  (and text-stat
		       (not (lyskom-text-read-p text-stat))))
	      (setq footnotes (cons no footnotes)))))
      (if footnotes
	  (read-list-enter-read-info
	   (lyskom-create-read-info (if review-tree 'REVIEW-TREE 'FOOTN-IN)
				    conf-stat (1+ priority)
				    (lyskom-create-text-list footnotes)
				    (text-stat->text-no text-stat))
	   lyskom-reading-list t)))))
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285


(defun lyskom-fetch-text-for-cache (text-stat)
  "Fetches the author and other things of a text and does nothing with it."
  (cond
   (text-stat
    (lyskom-fetch-author-for-cache text-stat)
    (initiate-get-text 'fill-cache nil (text-stat->text-no text-stat))
    (lyskom-traverse misc (text-stat->misc-info-list text-stat)
      (cond
       ((eq (misc-info->type misc) 'FOOTN-IN)
	(initiate-get-text-stat 'fill-cache 'lyskom-fetch-author-for-cache
				(misc-info->footn-in misc)))
       ((eq (misc-info->type misc) 'FOOTN-TO)
	(initiate-get-text-stat 'fill-cache 'lyskom-fetch-author-for-cache
				(misc-info->footn-to misc)))
       ((eq (misc-info->type misc) 'COMM-IN)
	(initiate-get-text-stat 'fill-cache 'lyskom-fetch-author-for-cache
				(misc-info->comm-in misc)))
       ((eq (misc-info->type misc) 'COMM-TO)
	(initiate-get-text-stat 'fill-cache 'lyskom-fetch-author-for-cache
				(misc-info->comm-to misc))))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
286 287


288 289 290 291 292 293

(defun lyskom-fetch-author-for-cache (text-stat)
  "Fetches the author of a text and does nothing with it."
  (if text-stat				;Error check.
      (initiate-get-conf-stat 'fill-cache nil (text-stat->author text-stat))))

Per Cederqvist's avatar
.  
Per Cederqvist committed
294 295 296 297 298 299 300


(defun lyskom-text-read-p (text-stat)
  "Return t if TEXT-STAT has been marked as read in all
recipients to it that the user is a member in."
  (let* ((misc-info-list (text-stat->misc-info-list text-stat))
	 (i (length misc-info-list))
301
	 (res 'not-member))
Per Cederqvist's avatar
.  
Per Cederqvist committed
302 303 304 305 306 307
    (while (and res (not (zerop i)))
      (setq i (1- i))
      (let* ((misc-info (elt misc-info-list i))
	     (type (misc-info->type misc-info)))
	(cond
	 ((or (eq type 'RECPT) (eq type 'CC-RECPT))
308 309 310
	  ;; Is this function ever called asynchronously? If not, we
	  ;; can use lyskom-get-membership istead.
	  (let ((membership (lyskom-try-get-membership
Per Cederqvist's avatar
.  
Per Cederqvist committed
311 312
			     (misc-info->recipient-no misc-info)))
		(loc-no (misc-info->local-no misc-info)))
313 314 315 316 317

	    ;; Make a note that this text really is in a group we are
	    ;; a member of.
	    (if (and res membership) (setq res t))
	    
Per Cederqvist's avatar
.  
Per Cederqvist committed
318 319 320
	    (if (and membership
		     (> loc-no (membership->last-text-read membership))
		     (not (lyskom-vmemq loc-no
321
					(membership->read-texts membership))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
322
		(setq res nil)))))))
323 324 325
    (if (eq res 'not-member)
	(not kom-follow-comments-outside-membership)
      res)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
326 327


David Byers's avatar
David Byers committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
(defun lyskom-text-read-at-least-once-p (text-stat)
  "Return t if TEXT-STAT has been marked as read in any of the recipients
the user is a member of. Uses blocking-do. Returns t if TEXT-STAT is nil."
  (if text-stat
      (let* ((misc-info-list (text-stat->misc-info-list text-stat))
             (misc-item nil)
             (type nil)
             (membership nil)
             (is-member nil)
             (result nil))
        (while misc-info-list
          (setq misc-item (car misc-info-list))
          (setq type (misc-info->type misc-item))
          (setq misc-info-list (cdr misc-info-list))
          (cond ((or (eq type 'RECPT) (eq type 'CC-RECPT))
                 (setq membership (lyskom-get-membership
                                   (misc-info->recipient-no misc-item)))
                 (when membership
                   (setq is-member t)
                   (when (or (<= (misc-info->local-no misc-item)
                                 (membership->last-text-read membership))
                             (lyskom-vmemq (misc-info->local-no misc-item)
                                           (membership->read-texts
                                            membership)))
                     (setq result t)
                     (setq misc-info-list nil))))))
        (cond (result result)
              ((not is-member) (not kom-follow-comments-outside-membership))
              (t nil)))
    t))


360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
(defun lyskom-subtract-one-day (x)
  (let ((high-x (1- (car x)))
        (low-x (car (cdr x))))
    (if (> 20864 low-x)
        (setq high-x (1- high-x)
              low-x (+ low-x 65536)))
    (setq low-x (- low-x 20864))
    (list high-x low-x nil)))

(defun lyskom-calculate-day-diff (time)
  (let* ((now (current-time))
         (yesterday (lyskom-subtract-one-day now))
         (decnow (decode-time now))
         (decthen (decode-time yesterday)))
    (cond ((and (= (time->mday time) (elt decnow 3))
                (= (1+ (time->mon time)) (elt decnow 4))
                (= (+ (time->year time) 1900) (elt decnow 5)))
           'today)
          ((and (= (time->mday time) (elt decthen 3))
                (= (1+ (time->mon time)) (elt decthen 4))
                (= (+ (time->year time) 1900) (elt decthen 5)))
           'yesterday)
          (t nil))))

David Byers's avatar
David Byers committed
384 385
(defun lyskom-return-date-and-time (time &optional fmt)
  "Return date and time as a string. Arg: TIME."
David Byers's avatar
David Byers committed
386 387
  (let* ((diff (and lyskom-print-complex-dates
		    (lyskom-calculate-day-diff time))))
David Byers's avatar
David Byers committed
388
    (lyskom-format
David Byers's avatar
David Byers committed
389
     (if diff
390
         (intern (concat (symbol-name diff) "-time-format-string"))
David Byers's avatar
David Byers committed
391
       (or fmt 'time-yyyy-mm-dd-hh-mm))
392 393 394 395 396 397 398
     (+ (time->year time) 1900)
     (1+ (time->mon  time))
     (time->mday time)
     (time->hour time)
     (time->min  time)
     (and diff (lyskom-get-string diff)))))
                  
David Byers's avatar
David Byers committed
399 400 401
(defun lyskom-print-date-and-time (time &optional fmt)
  "Print date and time. Arg: TIME"
  (lyskom-insert (lyskom-return-date-and-time time fmt)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
402

David Byers's avatar
David Byers committed
403 404 405 406 407 408 409 410 411 412
(defun lyskom-deferred-insert-footer (conf-stat defer-info)
  "Insert the name of a conference at a previously reserved place."
  (let* ((name (cond (conf-stat (conf-stat->name conf-stat))
                      ((= (defer-info->call-par defer-info) 0)
                       (lyskom-get-string 'person-is-anonymous))
                      (t (lyskom-format 'person-does-not-exist
                                        (defer-info->call-par defer-info)))))
         (dashes (if (> 42 (length name))
                     (make-string (- 42 (length name)) ?-)
                   ""))
David Byers's avatar
David Byers committed
413
         (text (lyskom-format "/%[%#3@%#1P%]/%#2s%#4s"
David Byers's avatar
David Byers committed
414
                              (or conf-stat name)
David Byers's avatar
David Byers committed
415 416
                              dashes
                              (text-properties-at
David Byers's avatar
David Byers committed
417 418 419 420 421
                               (defer-info->pos defer-info))
                              (if (defer-info->data defer-info)
                                  (lyskom-get-string
                                   (defer-info->data defer-info))
                                ""))))
David Byers's avatar
David Byers committed
422
    (lyskom-replace-deferred defer-info text)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
423 424 425 426 427 428

(defun lyskom-print-text (text-stat text mark-as-read text-no)
  "Print a text. The header must already be printed.
Print an error message if TEXT-STAT or TEXT is nil.
Mark the text as read if (and only if) MARK-AS-READ is non-nil.
Args: TEXT-STAT TEXT MARK-AS-READ TEXT-NO."
429 430
  (let ((lyskom-current-function 'lyskom-print-text))
    (cond
Per Cederqvist's avatar
.  
Per Cederqvist committed
431
     ((or (null text)
432
          (null text-stat))
Per Cederqvist's avatar
.  
Per Cederqvist committed
433 434 435
      (lyskom-format-insert 'no-such-text-no text-no)
      (setq lyskom-previous-text lyskom-current-text)
      (setq lyskom-current-text text-no))
436
     (t
Per Cederqvist's avatar
.  
Per Cederqvist committed
437
      (let* ((str (text->text-mass text))
438 439
             ;; s1 s2 t1 t2
	     body)
440 441 442 443 444 445 446 447 448 449 450 451
        (cond
         ((string-match "\n" str)
          (setq lyskom-current-subject (substring str 0 (match-beginning 0)))
          (setq body (substring str (match-end 0)))
          (lyskom-insert-string 'head-Subject)
          (let ((lyskom-current-function-phase 'subject))
            (lyskom-format-insert "%#1r\n" 
                                  (copy-sequence lyskom-current-subject)))
          (if kom-dashed-lines
              (lyskom-insert 
               "------------------------------------------------------------\n")
            (lyskom-insert "\n"))
452
          ;; (setq t1 (point-max))
453 454
          (let ((lyskom-current-function-phase 'body))
            (lyskom-format-insert "%#1t" body))
455 456
          ;; (setq t2 (point-max))
	  )
457
         (t                             ;No \n found. Don't print header.
David Byers's avatar
David Byers committed
458 459 460 461
          (if kom-dashed-lines
              (lyskom-insert 
               "------------------------------------------------------------\n")
            (lyskom-insert "\n"))
462 463 464 465 466 467
          (lyskom-format-insert "%#1t" str)
          (setq lyskom-current-subject "")))
        (if (lyskom-text-p (cache-get-text (text->text-no text)))
            (cache-del-text (text->text-no text)))
        (sit-for 0)
        (let ((lyskom-current-function-phase 'footer))
David Byers's avatar
David Byers committed
468 469 470
          (cond (kom-dashed-lines
                 (lyskom-format-insert "\n(%#1n) " (text->text-no text))
                 (if (not kom-show-author-at-end)
David Byers's avatar
David Byers committed
471 472 473 474 475 476
                     (progn
                       (lyskom-format-insert
                        "-----------------------------------%#1s\n"
                        (if lyskom-last-text-format-flags
                            (lyskom-get-string lyskom-last-text-format-flags)
                          "")))
David Byers's avatar
David Byers committed
477 478 479 480 481 482 483 484 485 486 487 488 489 490
                   (if kom-deferred-printing
                       (progn
                         (lyskom-format-insert "%#1s\n" lyskom-defer-indicator)
                         (lyskom-defer-insertion
                          (lyskom-create-defer-info 
                           'get-conf-stat
                           (text-stat->author text-stat)
                           'lyskom-deferred-insert-footer
                           (set-marker
                            (make-marker)
                             (- (point-max)
                                (length lyskom-defer-indicator)
                                1))
                           (length lyskom-defer-indicator)
David Byers's avatar
David Byers committed
491 492
                           "%#1s"
                           lyskom-last-text-format-flags)))
David Byers's avatar
David Byers committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
                     (let* ((conf-stat (blocking-do 
                                        'get-conf-stat
                                        (text-stat->author text-stat)))
                            (name (lyskom-format "%#1P" conf-stat)))
                       (lyskom-format-insert 
                        "/%#1P/%#2s\n"
                        conf-stat
                        (if (> 42 (length name))
                            (make-string (- 42 (length name)) ?-)
                          ""))))))
                (t (lyskom-format-insert
                    (if kom-show-author-at-end 
                        "\n(%#1n) /%#2P/\n"
                      "\n(%#1n)\n")
                    (text->text-no text)
                    (text-stat->author text-stat)))))
509 510 511 512
        (if mark-as-read
            (lyskom-mark-as-read text-stat))
        (setq lyskom-previous-text lyskom-current-text)
        (setq lyskom-current-text (text-stat->text-no text-stat)))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
513 514 515


(defun lyskom-mark-as-read (text-stat)
Per Cederqvist's avatar
Per Cederqvist committed
516
  "Mark a text as read in all conferences that are recipients.
Per Cederqvist's avatar
Per Cederqvist committed
517 518 519 520 521 522
Tell the server that it is read.

Args: TEXT-STAT

This function does not remove the text from the internal structures of
the client. That is done by lyskom-is-read."
Per Cederqvist's avatar
.  
Per Cederqvist committed
523 524 525 526 527
  (let ((misc-info-list (text-stat->misc-info-list text-stat)))
    (lyskom-traverse
     misc-info misc-info-list
     (if (and (or (eq (misc-info->type misc-info) 'RECPT)
		  (eq (misc-info->type misc-info) 'CC-RECPT))
528 529 530 531
	      ;; The whole membership list might not be fetched
	      ;; yet. So we better mark it as read in all conferences.
	      ;; (lyskom-member-p (misc-info->recipient-no misc-info))
	      )
Per Cederqvist's avatar
.  
Per Cederqvist committed
532 533 534 535 536
	 (initiate-mark-as-read 'background nil
				(misc-info->recipient-no misc-info)
				(list (misc-info->local-no misc-info)))))))


David Kågedal's avatar
David Kågedal committed
537
(defun lyskom-print-header-recpt (conf-no misc)
Per Cederqvist's avatar
.  
Per Cederqvist committed
538
  "Print a line of info about a recipient (or cc-recipient) of a text."
539 540 541 542
  (lyskom-format-insert "%#1s: %#2M <%#3d>\n"
			(cond ((eq (misc-info->type misc) 'RECPT)
			       (lyskom-get-string 'Recipient))
			      (t (lyskom-get-string 'Extra-recipient)))
David Kågedal's avatar
David Kågedal committed
543
			conf-no
544
			(misc-info->local-no misc))
Per Cederqvist's avatar
.  
Per Cederqvist committed
545 546
  (if (misc-info->sent-at misc)
      (lyskom-format-insert 'send-at
David Byers's avatar
David Byers committed
547
			    (lyskom-return-date-and-time 
Per Cederqvist's avatar
.  
Per Cederqvist committed
548 549
			     (misc-info->sent-at misc))))
  (if (misc-info->sender misc)
David Kågedal's avatar
David Kågedal committed
550
      (lyskom-format-insert 'sent-by (misc-info->sender misc)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
551
  (if (misc-info->rec-time misc)
David Kågedal's avatar
David Kågedal committed
552 553 554 555 556
      (lyskom-format-insert
       'recieved-at
       (lyskom-return-date-and-time (misc-info->rec-time misc)))))


Per Cederqvist's avatar
.  
Per Cederqvist committed
557 558


559
(defun lyskom-view-text-handle-saved-comments (text-stat)
Per Cederqvist's avatar
.  
Per Cederqvist committed
560 561
  "Ask server for what is needed to print the references to commenting texts 
and prints the references. Used at the bottom of the text.
562 563 564 565 566 567
Args: TEXT-STAT of the text being read."
  (lyskom-traverse misc
      (text-stat->misc-info-list text-stat)
    (let ((type (misc-info->type misc)))
      (cond
       ((eq type 'COMM-IN)
568 569
        (if lyskom-show-comments        ;+++SOJGE
            (lyskom-print-header-comm (misc-info->comm-in misc) misc)))
570 571 572 573
       ((eq type 'FOOTN-IN)
	(lyskom-print-header-comm (misc-info->footn-in misc) misc))))))


574

575 576
(defun lyskom-print-header-comm (text misc)
  "Get author of TEXT-NO and print a header line."
577
  (let ((text-stat (if kom-deferred-printing
578
		       (cache-get-text-stat text)
579
		     (blocking-do 'get-text-stat text))))
580 581

    ;; Print information about the link
582 583
    (if text-stat
	(progn
584
	  (lyskom-insert-header-comm text-stat misc))
585
      (let ((defer-info (lyskom-create-defer-info
586
			 'get-text-stat
587 588 589
			 text
			 'lyskom-insert-deferred-header-comm
			 (point-max-marker)
590 591
			 (length lyskom-defer-indicator)
			 nil		; Filled in later
592 593
			 misc)))
	(lyskom-format-insert "%#1s\n" lyskom-defer-indicator)
594 595 596 597 598 599 600 601
	(lyskom-defer-insertion defer-info)))

    ;; Print information about who added the link
    (if (misc-info->sent-at misc)
	(lyskom-format-insert 'send-at (lyskom-return-date-and-time 
					(misc-info->sent-at misc))))
    (if (misc-info->sender misc)
	(lyskom-format-insert 'sent-by (misc-info->sender misc)))))
602 603 604


(defun lyskom-insert-deferred-header-comm (text-stat defer-info)
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
  (let* ((author (if text-stat (text-stat->author text-stat) nil))
	 (misc (defer-info->data defer-info))
	 (type (misc-info->type misc))
	 fmt data)
    (cond
     ((eq type 'COMM-TO)
      (setq fmt (if author 'comment-to-text-by 'comment-to-text)
	    data (misc-info->comm-to misc)))
     ((eq type 'FOOTN-TO)
      (setq fmt (if author 'footnote-to-text-by 'footnote-to-text)
	    data (misc-info->footn-to misc)))
     ((eq type 'COMM-IN)
      (setq fmt (if author 'comment-in-text-by 'comment-in-text)
	    data (misc-info->comm-in misc)))
     ((eq type 'FOOTN-IN)
      (setq fmt (if author 'footnote-in-text-by 'footnote-in-text)
	    data(misc-info->footn-in misc)))) 
    (set-defer-info->format defer-info fmt)
    ; Note: author is ignored if fmt is not *-by
    (lyskom-replace-deferred defer-info data author)))
625

626 627


628
(defun lyskom-insert-header-comm (text-stat misc)
629 630
  "Get author of TEXT-NO and print a header line."
  ;;+++ error kommer att se annorlunda ut.
631 632 633 634 635 636
  (let ((author (if text-stat
		    (text-stat->author text-stat)
		  nil))
	(type (misc-info->type misc)))
    (cond
     ((eq type 'COMM-TO)
637
      (lyskom-format-insert 'comment-to-text (misc-info->comm-to misc)))
638
     ((eq type 'FOOTN-TO)
639
      (lyskom-format-insert 'footnote-to-text (misc-info->footn-to misc)))
640
     ((eq type 'COMM-IN)
641
      (lyskom-format-insert 'comment-in-text (misc-info->comm-in misc)))
642
     ((eq type 'FOOTN-IN)
643
      (lyskom-format-insert 'footnote-in-text (misc-info->footn-in misc))))
644
    (if author
645 646
	(lyskom-format-insert 'written-by author)
      (lyskom-insert-at-point "\n"))))
647 648 649 650 651 652



;;; Local Variables: 
;;; eval: (put 'lyskom-traverse 'lisp-indent-hook 2)
;;; end: