]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Comet/updatetimeline.js
de750baba333551596e0f3b32af2b8944751f000
[quix0rs-gnu-social.git] / plugins / Comet / updatetimeline.js
1 // update the local timeline from a Comet server
2 //
3
4 var updater = function()
5 {
6      var _cometd;
7
8      return {
9           init: function(server, timeline)
10           {
11                _cometd = $.cometd; // Uses the default Comet object
12                _cometd.setLogLevel('debug');
13                _cometd.init(server);
14                _cometd.subscribe(timeline, receive);
15                $(window).unload(leave);
16           }
17      }
18
19      function leave()
20      {
21           _cometd.disconnect();
22      }
23
24      function receive(message)
25      {
26           id = message.data.id;
27
28           // Don't add it if it already exists
29
30           if ($("#notice-"+id).length > 0) {
31                return;
32           }
33
34           var noticeItem = makeNoticeItem(message.data);
35           $("#notices_primary .notices").prepend(noticeItem, true);
36           $("#notices_primary .notice:first").css({display:"none"});
37           $("#notices_primary .notice:first").fadeIn(2500);
38           NoticeHover();
39           NoticeReply();
40      }
41
42      function makeNoticeItem(data)
43      {
44           user = data['user'];
45           html = data['html'].replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
46
47           ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
48                "<div class=\"entry-title\">"+
49                "<span class=\"vcard author\">"+
50                "<a href=\""+user['profile_url']+"\" class=\"url\">"+
51                "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
52                "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
53                "</a>"+
54                "</span>"+
55                "<p class=\"entry-content\">"+html+"</p>"+
56                "</div>"+
57                "<div class=\"entry-content\">"+
58                "<dl class=\"timestamp\">"+
59                "<dt>Published</dt>"+
60                "<dd>"+
61                "<a rel=\"bookmark\" href=\""+data['url']+"\" >"+
62                "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
63                "</a> "+
64                "</dd>"+
65                "</dl>"+
66                "<dl class=\"device\">"+
67                "<dt>From</dt> "+
68                "<dd>"+data['source']+"</dd>"+
69                "</dl>"+
70                "</div>"+
71                "<div class=\"notice-options\">"+
72                "</div>"+
73                "</li>";
74           return ni;
75      }
76 }();
77