mirror of
https://bitbucket.org/skobkin/chrome_point_plus.git
synced 2024-11-23 18:56:04 +00:00
Fix bug #11. WebSocket recommendation comments.
This commit is contained in:
parent
6a951ea8d3
commit
d818c7dc66
|
@ -348,17 +348,26 @@ function PointPlus(ppVersion) {
|
||||||
ws.onmessage = function(evt) {
|
ws.onmessage = function(evt) {
|
||||||
try {
|
try {
|
||||||
// ping :)
|
// ping :)
|
||||||
if (evt.data == 'ping') {
|
if (evt.data === 'ping') {
|
||||||
console.info('ws-ping');
|
console.info('ws-ping');
|
||||||
} else {
|
} else {
|
||||||
var wsMessage = JSON.parse(evt.data);
|
var wsMessage = JSON.parse(evt.data);
|
||||||
|
|
||||||
if (wsMessage.hasOwnProperty('a') && wsMessage.a != '') {
|
if (wsMessage.hasOwnProperty('a') && wsMessage.a !== '') {
|
||||||
|
console.log(wsMessage);
|
||||||
|
|
||||||
switch (wsMessage.a) {
|
switch (wsMessage.a) {
|
||||||
|
// Recommendation comment
|
||||||
|
case 'ok':
|
||||||
|
// Do not break here. Using next case for this message
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
case 'comment':
|
case 'comment':
|
||||||
console.groupCollapsed('ws-comment #%s/%s', wsMessage.post_id, wsMessage.comment_id);
|
if (wsMessage.a === 'comment') {
|
||||||
console.debug(wsMessage);
|
console.groupCollapsed('WS comment #%s/%s', wsMessage.post_id, wsMessage.comment_id);
|
||||||
|
} else if (wsMessage.a === 'ok') {
|
||||||
|
console.groupCollapsed('WS comment rec #%s/%s', wsMessage.post_id, wsMessage.comment_id);
|
||||||
|
}
|
||||||
|
|
||||||
// Check option
|
// Check option
|
||||||
if ( ! options.is('option_ws_comments')) {
|
if ( ! options.is('option_ws_comments')) {
|
||||||
|
@ -383,12 +392,13 @@ function PointPlus(ppVersion) {
|
||||||
|
|
||||||
// Generating comment from websocket message
|
// Generating comment from websocket message
|
||||||
create_comment_elements({
|
create_comment_elements({
|
||||||
id: wsMessage.comment_id,
|
id: (wsMessage.a === 'ok') ? wsMessage.rcid : wsMessage.comment_id,
|
||||||
toId: wsMessage.to_comment_id,
|
toId: wsMessage.to_comment_id,
|
||||||
postId: wsMessage.post_id,
|
postId: wsMessage.post_id,
|
||||||
author: wsMessage.author,
|
author: wsMessage.author,
|
||||||
text: wsMessage.text,
|
text: wsMessage.text,
|
||||||
fadeOut: options.is('option_ws_comments_color_fadeout')
|
fadeOut: options.is('option_ws_comments_color_fadeout'),
|
||||||
|
isRec: (wsMessage.a === 'ok') ? true : false
|
||||||
}, function($comment) {
|
}, function($comment) {
|
||||||
// It's time to DOM
|
// It's time to DOM
|
||||||
console.info('Inserting comment');
|
console.info('Inserting comment');
|
||||||
|
@ -434,9 +444,8 @@ function PointPlus(ppVersion) {
|
||||||
|
|
||||||
// Posts
|
// Posts
|
||||||
case 'post':
|
case 'post':
|
||||||
console.groupCollapsed('ws-post #%s', wsMessage.post_id);
|
console.groupCollapsed('WS post #%s', wsMessage.post_id);
|
||||||
|
|
||||||
console.debug(wsMessage);
|
|
||||||
if (options.is('option_ws_posts')) {
|
if (options.is('option_ws_posts')) {
|
||||||
if (options.is('option_ws_posts_notifications')) {
|
if (options.is('option_ws_posts_notifications')) {
|
||||||
console.log('Showing desktop notification');
|
console.log('Showing desktop notification');
|
||||||
|
@ -452,20 +461,16 @@ function PointPlus(ppVersion) {
|
||||||
|
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Recommendation
|
// Recommendation
|
||||||
case 'ok':
|
case 'rec':
|
||||||
console.groupCollapsed('ws-recommendation #%s/%s', wsMessage.post_id, wsMessage.comment_id);
|
console.groupCollapsed('WS recommendation');
|
||||||
|
|
||||||
console.debug(wsMessage);
|
|
||||||
|
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.groupCollapsed('ws-other');
|
console.groupCollapsed('WS other');
|
||||||
|
|
||||||
console.log(wsMessage);
|
|
||||||
|
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
break;
|
break;
|
||||||
|
@ -636,6 +641,7 @@ var months = [
|
||||||
* @param {string} commentData.author Author of the comment
|
* @param {string} commentData.author Author of the comment
|
||||||
* @param {string} commentData.text Text of the comment
|
* @param {string} commentData.text Text of the comment
|
||||||
* @param {boolean} commentData.fadeOut Is fadeout enabled or not
|
* @param {boolean} commentData.fadeOut Is fadeout enabled or not
|
||||||
|
* @param {boolean|null} commentData.isRec Is comment also a recommendation
|
||||||
* @param {function} onCommentCreated Callback which is called when comment is ready
|
* @param {function} onCommentCreated Callback which is called when comment is ready
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -649,6 +655,11 @@ function create_comment_elements(commentData, onCommentCreated) {
|
||||||
'data-comment-id': commentData.id,
|
'data-comment-id': commentData.id,
|
||||||
'data-to-comment-id': commentData.id || ''
|
'data-to-comment-id': commentData.id || ''
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If comment is also a recommendation
|
||||||
|
if (commentData.isRec || false) {
|
||||||
|
$commentTemplate.addClass('recommendation');
|
||||||
|
}
|
||||||
|
|
||||||
// Loading HTML template
|
// Loading HTML template
|
||||||
$commentTemplate.load(chrome.extension.getURL('includes/comment.html'), function() {
|
$commentTemplate.load(chrome.extension.getURL('includes/comment.html'), function() {
|
||||||
|
@ -665,7 +676,7 @@ function create_comment_elements(commentData, onCommentCreated) {
|
||||||
// Filling template
|
// Filling template
|
||||||
// Date and time
|
// Date and time
|
||||||
$commentTemplate.find('.info .created')
|
$commentTemplate.find('.info .created')
|
||||||
.append($('<span>').html(((date.getDate().toString.length < 2) ? ('0' + date.getDate().toString()) : (date.getDate().toString())) + ' ' + months[date.getMonth()]))
|
.append($('<span>').html((date.getDate().toString()) + ' ' + months[date.getMonth()]))
|
||||||
// Crutchy fix
|
// Crutchy fix
|
||||||
.append($('<br>'))
|
.append($('<br>'))
|
||||||
///Crutchy fix
|
///Crutchy fix
|
||||||
|
@ -679,7 +690,8 @@ function create_comment_elements(commentData, onCommentCreated) {
|
||||||
// Post and comment ID's link
|
// Post and comment ID's link
|
||||||
$commentTemplate.find('.clearfix .post-id a').attr('href', '//point.im/' + commentData.postId + '#' + commentData.id).text('#' + commentData.postId + '/' + commentData.id)
|
$commentTemplate.find('.clearfix .post-id a').attr('href', '//point.im/' + commentData.postId + '#' + commentData.id).text('#' + commentData.postId + '/' + commentData.id)
|
||||||
// Adding answer label
|
// Adding answer label
|
||||||
.after((commentData.toId !== null) ? (' в ответ на <a href="#' + commentData.toId + '">/' + commentData.toId + '</a>') : (''));
|
// @todo i18n
|
||||||
|
.after((commentData.toId != null) ? (' в ответ на <a href="#' + commentData.toId + '">/' + commentData.toId + '</a>') : '');
|
||||||
// Setting action labels and other attributes
|
// Setting action labels and other attributes
|
||||||
$commentTemplate.find('.action-labels .reply-label').attr('for', 'reply-' + commentData.postId + '_' + commentData.id);
|
$commentTemplate.find('.action-labels .reply-label').attr('for', 'reply-' + commentData.postId + '_' + commentData.id);
|
||||||
$commentTemplate.find('.action-labels .more-label').attr('for', 'action-' + commentData.postId + '_' + commentData.id);
|
$commentTemplate.find('.action-labels .more-label').attr('for', 'action-' + commentData.postId + '_' + commentData.id);
|
||||||
|
|
Loading…
Reference in a new issue