// update the local timeline from a Comet server // var updater = function() { var _server; var _timeline; var _userid; var _replyurl; var _favorurl; var _deleteurl; var _cometd; return { init: function(server, timeline, userid, replyurl, favorurl, deleteurl) { _cometd = $.cometd; // Uses the default Comet object _cometd.setLogLevel('debug'); _cometd.init(server); _server = server; _timeline = timeline; _userid = userid; _favorurl = favorurl; _replyurl = replyurl; _deleteurl = deleteurl; _cometd.subscribe(timeline, receive); $(window).unload(leave); } } function leave() { _cometd.disconnect(); } function receive(message) { id = message.data.id; // Don't add it if it already exists if ($("#notice-"+id).length > 0) { return; } var noticeItem = makeNoticeItem(message.data); $("#notices_primary .notices").prepend(noticeItem, true); $("#notices_primary .notice:first").css({display:"none"}); $("#notices_primary .notice:first").fadeIn(1000); NoticeHover(); NoticeReply(); } function makeNoticeItem(data) { user = data['user']; html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); ni = "
  • "+ "
    "+ ""+ ""+ "\""+user['screen_name']+"\"/"+ ""+user['screen_name']+""+ ""+ ""+ "

    "+html+"

    "+ "
    "+ "
    "+ "
    "+ "
    Published
    "+ "
    "+ ""+ "a few seconds ago"+ " "+ "
    "+ "
    "+ "
    "+ "
    From
    "+ "
    "+source+"
    "+ // may have a link, I think "
    "; if (data['in_reply_to_status_id']) { ni = ni+"
    "+ "
    To
    "+ "
    "+ "in reply to"+ "
    "+ "
    "; } ni = ni+"
    "+ "
    "; if (_userid != 0) { var input = $("form#form_notice fieldset input#token"); var session_key = input.val(); ni = ni+makeFavoriteForm(data['id'], session_key); ni = ni+makeReplyLink(data['id'], data['user']['screen_name']); if (_userid == data['user']['id']) { ni = ni+makeDeleteLink(data['id']); } } ni = ni+"
    "+ "
  • "; return ni; } function makeFavoriteForm(id, session_key) { var ff; ff = "
    "+ "
    "+ "Favor this notice"+ // XXX: i18n ""+ ""+ ""+ "
    "+ "
    "; return ff; } function makeReplyLink(id, nickname) { var rl; rl = "
    "+ "
    Reply to this notice
    "+ "
    "+ "Reply "+id+""+ ""+ "
    "+ "
    "; return rl; } function makeDeleteLink(id) { var dl, delurl; delurl = _deleteurl.replace("0000000000", id); dl = "
    "+ "
    Delete this notice
    "+ "
    "+ "Delete"+ "
    "+ "
    "; return dl; } }();