Notification click bugfix.

This commit is contained in:
Alexey Skobkin 2015-01-14 15:42:20 +04:00
parent 26b5da4e93
commit dcb1dcf529
2 changed files with 29 additions and 32 deletions

View File

@ -8,6 +8,23 @@ chrome.storage.sync.get('options_version', function(data) {
}
});
// Adding notification click event listener
chrome.notifications.onClicked.addListener(function(notificationId) {
// Detecting notification type
if (notificationId.indexOf('comment_') === 0) {
tab_url = 'https://point.im/' + notificationId.replace(/comment_/g, '');
} else if (notificationId.indexOf('post_') === 0) {
tab_url = 'https://point.im/' + notificationId.replace(/post_/g, '');
}
console.log('Notification %s clicked! Opening new tab: %s', notificationId, tab_url);
if (tab_url !== undefined) {
chrome.tabs.create({
url: tab_url
});
}
});
// Crutches and bikes
/**
* Inject several JS files
@ -79,30 +96,6 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
return true;
break;
case 'listenNotificationClicks':
// Adding notification click event listener
chrome.notifications.onClicked.addListener(function(notificationId) {
// Detecting notification type
if (notificationId.indexOf('comment_') === 0) {
tab_url = message.protocol + '//' + 'point.im/' + notificationId.replace(/comment_/g, '');
} else if (notificationId.indexOf('post_') === 0) {
tab_url = message.protocol + '//' + 'point.im/' + notificationId.replace(/post_/g, '');
}
console.log('Notification %s clicked! Opening new tab: %s', notificationId, tab_url);
if (tab_url !== undefined) {
chrome.tabs.create({
url: tab_url
});
}
});
sendResponse(true);
// Fuck You, Chrome API documentation!
return true;
break;
/**
* @deprecated since 1.19.1
*/

View File

@ -381,13 +381,6 @@ $(document).ready(function() {
ws = new WebSocket(((location.protocol == 'https:') ? 'wss' : 'ws') + '://point.im/ws');
console.log('WebSocket created: %O', ws);
// @todo: унести в опцию
// Adding event listener for notification click
chrome.runtime.sendMessage({
type: 'listenNotificationClicks',
protocol: getProtocol()
});
// Detecting post id if presented
var postId = $('#top-post').attr('data-id');
console.debug('Current post id detected as #%s', postId);
@ -477,7 +470,7 @@ $(document).ready(function() {
type: 'showNotification',
notificationId: 'comment_' + wsMessage.post_id + '#' + wsMessage.comment_id,
avatarUrl: getProtocol() + '//point.im/avatar/' + wsMessage.author + '/80',
title: '@' + wsMessage.author + ' #' + wsMessage.post_id + '/' + wsMessage.comment_id + '',
title: '@' + wsMessage.author + ' #' + wsMessage.post_id + '/' + wsMessage.comment_id,
text: wsMessage.text
}, function(response) {});
}
@ -493,6 +486,17 @@ $(document).ready(function() {
console.groupCollapsed('ws-post #%s', wsMessage.post_id);
console.debug(wsMessage);
if (true /*options.is('option_ws_posts_notifications')*/) {
console.log('Showing desktop notification');
chrome.runtime.sendMessage({
type: 'showNotification',
notificationId: 'post_' + wsMessage.post_id,
avatarUrl: getProtocol() + '//point.im/avatar/' + wsMessage.author + '/80',
title: 'Post by @' + wsMessage.author + ' #' + wsMessage.post_id,
text: wsMessage.text
}, function(response) {});
}
console.groupEnd();
break;