]> code.citadel.org Git - citadel.git/blob - shaggy/message.java
* summary.c: summary screen is now updated using ajax instead of refreshing
[citadel.git] / shaggy / message.java
1 import java.util.*;
2
3 public class message {
4     String      blurb;
5     String      message;
6
7     public message( roomInfo ri, int count, int cur_pos, citReply r ) {
8         Vector  msg = r.listing;
9
10         String  s, from="", time="", room="", node="", rcpt="";
11         do {
12             s = (String)msg.firstElement();
13             msg.removeElementAt( 0 );
14             from = begin( from, s, "from=" );
15             time = begin( time, s, "time=" );
16             room = begin( room, s, "room=" );
17             node = begin( node, s, "hnod=" );
18             rcpt = begin( rcpt, s, "rcpt=" );
19         } while( (msg.size() > 0) && (!s.equals( "text" )) );
20
21         time = makeDate( time );
22
23         blurb = (cur_pos+1) + "/" + count + " " + time + " from " + from;
24         //      if( !node.equals( citadel.me.serverInfo.human_name ) )
25         if( ri.net )
26             blurb = blurb + " (@"+node+")";
27         if( !rcpt.equals( "" ) )
28             blurb = blurb + " to " + rcpt;
29         if( !room.equals( ri.name) )
30           blurb = blurb + " in " + room;
31    
32         /* this relies on the fact that we've removed
33            the header lines above.  probably a messy way 
34            to deal with references. */
35         message = r.getData(); 
36     }
37
38     public String makeDate( String time ) {
39         long    t=0;
40         try {
41             t = Long.parseLong( time );
42         } catch( NumberFormatException nfe ) {
43         };
44
45         Date    d = new Date( t*1000 );
46         return d.toLocaleString();
47     }
48
49     public String begin( String def, String data, String key ) {
50         if( data.indexOf( key ) == 0 )
51             return data.substring( key.length() );
52         return def;
53     }
54
55     public String getBlurb() { return blurb; }
56     public String getText() { return message; }
57 }
58
59