add_comment = function(data, username) { console.log('Adding comment ' + data.comment_added); var field = $('#comments'); var edit_btn = ' \ \ '; var inline = false; if (data.commit_id){ inline = true; edit_btn = ''; } if (data.notification){ var _data = '
\
\
\ ' + emojione.toImage(data.comment_added) + '\
\ \ Just now
\
\
\
'; } else if (inline) { var _data = ' \ \
\
\ \
\
\ ' + emojione.toImage(data.comment_added) + ' \
\
\
\ \
\ '; } else { var _data = '
\
\ \ ' + data.comment_user + '\ \ \ seconds ago \ \
\
\
\
\ \ ' + emojione.toImage(data.comment_added) + '\
\
\
\
\
\ \ \ '; if ( data.comment_user == username) { _data += edit_btn + ''; } _data += '
\
\
'; } if (inline){ // Inline comment console.log('Inline'); var field = $('[data-commit="' + data.commit_id + '"]').parent(); var id = field.children().children().attr('id').split('_')[0]; var row = $('#' + id + '_' + (parseInt(data.line) + 1)).parent().parent(); row.before(_data); } else { // Generic comment console.log('generic'); var field = $('#request_comment'); field.html(field.html() + _data); } } update_comment = function(data) { console.log('Updating comment ' + data.comment_id); var field = $('#comment-' + data.comment_id).parent(); var edited = field.find('.text-muted'); if (edited.length == 0) { $(field.find('aside')).before( 'Edited a just now by ' + data.comment_editor + ''); } else { edited.html('Edited a just now by ' + data.comment_editor) } field.find('.comment_body').html(data.comment_updated); field.find('.issue_actions').show(); field.find('.issue_comment').show(); } process_event = function(data, requestid, username){ console.log(data); var category = null; var originalTitle = document.title; if (data.comment_added){ add_comment(data, username); category = 'comment'; } else if (data.comment_updated){ update_comment(data); category = 'Comment updated'; } else { console.log('Unknown data'); } if (category && !document.hasFocus()) { var int = setInterval(function(){ var title = document.title; document.title = (title === originalTitle) ? category : originalTitle; }, 750); $(window).focus(function () { clearInterval(int); document.title = originalTitle; }); } }