Browse Source

fixed notification handling, added localization lines

master
Simon Grim 9 years ago
parent
commit
028492166f
  1. 41
      js/interface_common.js
  2. 41
      js/interface_localization.js
  3. 11
      js/mobile_abstract.js
  4. 20
      js/notify.js
  5. 17
      js/options.js
  6. 20
      js/twister_newmsgs.js

41
js/interface_common.js

@ -202,17 +202,10 @@ function updateHashtagModal(postboard,hashtag,timeoutArgs) { @@ -202,17 +202,10 @@ function updateHashtagModal(postboard,hashtag,timeoutArgs) {
requestHashtag(postboard,hashtag,resource,timeoutArgs);
if( _hashtagPendingPostsUpdated ) {
var desktopNotification = new Notify(polyglot.t('notify_desktop_title'), {
body: 'You got '+polyglot.t("new_posts", _hashtagPendingPostsUpdated)+' in search result.',
icon: '../img/twister_mini.png',
tag: 'twister_notification_new_posts_modal',
timeout: _desktopNotificationTimeout,
notifyClick: function() {
showDesktopNotification(false, polyglot.t('You got')+' '+polyglot.t("new_posts", _hashtagPendingPostsUpdated)+' '+polyglot.t('in search result')+'.', false,'twister_notification_new_posts_modal', function() {
$(".postboard-news").hide();
displayHashtagPending($(".hashtag-modal .postboard-posts"));
}
});
desktopNotification.show();
}, false)
_hashtagPendingPostsUpdated = 0;
}
@ -826,6 +819,36 @@ function replyTextKeypress(e) { @@ -826,6 +819,36 @@ function replyTextKeypress(e) {
}
}
function showDesktopNotification(notifyTitle, notifyBody, notifyIcon, notifyTag, actionOnClick, actionOnPermDenied) {
function doNotification(notifyTitle, notifyBody, notifyIcon, notifyTag, actionOnClick) {
if (!notifyTitle) {
notifyTitle = polyglot.t('notify_desktop_title');
}
if (!notifyIcon) {
notifyIcon = '../img/twister_mini.png';
}
if (!notifyTag) {
notifyTag = 'twister_notification';
}
var desktopNotification = new Notify(notifyTitle, {
body: notifyBody,
icon: notifyIcon,
tag: notifyTag,
timeout: _desktopNotificationTimeout,
notifyClick: actionOnClick,
notifyError: function() { alert(polyglot.t('notify_desktop_error')) }
});
desktopNotification.show();
}
if (Notify.needsPermission) {
Notify.requestPermission(false, actionOnPermDenied);
} else {
doNotification(notifyTitle, notifyBody, notifyIcon, notifyTag, actionOnClick);
}
}
/*
* unicode convertion list
* k: original string to be replaced

41
js/interface_localization.js

@ -91,6 +91,9 @@ if(preferredLanguage == "en"){ @@ -91,6 +91,9 @@ if(preferredLanguage == "en"){
"Network status": "Network status",
"New direct message...": "New direct message...",
"New Post...": "New Post...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} new post |||| %{smart_count} new posts",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -329,6 +332,9 @@ if(preferredLanguage == "es"){ @@ -329,6 +332,9 @@ if(preferredLanguage == "es"){
"Network status": "Estado de la red",
"New direct message...": "Nuevo mensaje directo...",
"New Post...": "Nuevo Post...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} nuevo post |||| %{smart_count} nuevos posts",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -565,6 +571,9 @@ if(preferredLanguage == "uk"){ @@ -565,6 +571,9 @@ if(preferredLanguage == "uk"){
"Network status": "Статус мережі",
"New direct message...": "Нове особисте повідомлення...",
"New Post...": "Нове повідомлення...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} нове повідомлення |||| %{smart_count} нових повідомлень",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -799,6 +808,9 @@ if(preferredLanguage == "zh"){ @@ -799,6 +808,9 @@ if(preferredLanguage == "zh"){
"Network status": "网络状态",
"New direct message...": "新的即时信息...",
"New Post...": "新推文...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} 新推文",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -1033,6 +1045,9 @@ if(preferredLanguage == "nl"){ @@ -1033,6 +1045,9 @@ if(preferredLanguage == "nl"){
"Network status": "Netwerkstatus",
"New direct message...": "Nieuw privébericht...",
"New Post...": "Nieuw bericht...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} nieuw bericht |||| %{smart_count} nieuwe berichten",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -1268,6 +1283,9 @@ if(preferredLanguage == "it"){ @@ -1268,6 +1283,9 @@ if(preferredLanguage == "it"){
"Network status": "Status della rete",
"New direct message...": "Nuovo messaggio diretto...",
"New Post...": "Nuovo messaggio...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} nuovo messaggio |||| %{smart_count} nuovi messaggi",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -1501,6 +1519,9 @@ if(preferredLanguage == "fr"){ @@ -1501,6 +1519,9 @@ if(preferredLanguage == "fr"){
"Network status": "État du réseau",
"New direct message...": "Nouveau message privé...",
"New Post...": "Nouveau billets...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} nouveau billet |||| %{smart_count} nouveaux billets",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -1740,6 +1761,9 @@ if(preferredLanguage == "ru"){ @@ -1740,6 +1761,9 @@ if(preferredLanguage == "ru"){
"Network status": "Состояние сети",
"New direct message...": "Новое личное сообщение...",
"New Post...": "Новый пост...",
"You got": "У вас там",
"in postboard": "в ленте",
"in search result": "в результатах поиска",
"new_posts": "%{smart_count} новый пост |||| %{smart_count} новых постов",
"new_mentions": "%{smart_count} новое упоминание |||| %{smart_count} новых упоминаний",
"new_direct_messages": "%{smart_count} новое личное сообщение |||| %{smart_count} новых личных сообщений",
@ -1747,7 +1771,7 @@ if(preferredLanguage == "ru"){ @@ -1747,7 +1771,7 @@ if(preferredLanguage == "ru"){
"Not available": "Недоступно",
"notify_desktop_error": "Твистер не может выполнить уведомление: произошла неизвестная ошибка.",
"notify_desktop_perm_denied": "Твистер не может выполниь уведомление: разрешение не получено.\n\nЧтобы получать уведомления, разрешите их для этого домена в настройках вашего браузера.",
"notify_desktop_test": "All the twisters gonna twist. Now you are welcome too.",
"notify_desktop_test": "Лягушка сказала: 'если не буду квакать — лопну'. Вы нужны нам, берегите себя.",
"notify_desktop_title": "Watch out, it's twister over here!",
"Number of blocks in block chain:": "Количество блоков в цепочке: ",
"Number of CPUs to use": "Сколько использовать ядер процессора",
@ -1980,6 +2004,9 @@ if(preferredLanguage == "de"){ @@ -1980,6 +2004,9 @@ if(preferredLanguage == "de"){
"Network status": "Netzwerkstatus",
"New direct message...": "Neue Direktnachricht...",
"New Post...": "Neuer Post...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} neuer Post |||| %{smart_count} neue Posts",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -2216,6 +2243,9 @@ if(preferredLanguage == "ja"){ @@ -2216,6 +2243,9 @@ if(preferredLanguage == "ja"){
"Network status": "ネットワークステータス",
"New direct message...": "ダイレクトメッセージ...",
"New Post...": "投稿する",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} 新投稿 |||| %{smart_count} 新投稿",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -2449,6 +2479,9 @@ if(preferredLanguage == "pt-BR"){ @@ -2449,6 +2479,9 @@ if(preferredLanguage == "pt-BR"){
"Network status": "Estado da rede",
"New direct message...": "Nova mensagem direta...",
"New Post...": "Nova Postagem...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} nova postagem |||| %{smart_count} novas postagens",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -2686,6 +2719,9 @@ if(preferredLanguage == "tr"){ @@ -2686,6 +2719,9 @@ if(preferredLanguage == "tr"){
"Network status": "Ağ durumu",
"New direct message...": "Yeni direk mesaj...",
"New Post...": "Yeni gönderi...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} yeni gönederi |||| %{smart_count} yeni gönderi",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",
@ -2920,6 +2956,9 @@ if(preferredLanguage == "cs"){ @@ -2920,6 +2956,9 @@ if(preferredLanguage == "cs"){
"Network status": "Stav sítě",
"New direct message...": "Nová přímá zpráva...",
"New Post...": "Nový příspěvek...",
"You got": "You got",
"in postboard": "in postboard",
"in search result": "in search result",
"new_posts": "%{smart_count} nový příspěvek |||| %{smart_count} nové příspěvky |||| %{smart_count} nových příspěvků",
"new_mentions": "%{smart_count} new mention |||| %{smart_count} new mentions",
"new_direct_messages": "%{smart_count} new direct message |||| %{smart_count} new direct messages",

11
js/mobile_abstract.js

@ -103,16 +103,9 @@ var MAL = function() @@ -103,16 +103,9 @@ var MAL = function()
newTweetsBarMenu.text(String(newPosts));
newTweetsBarMenu.addClass("show");
var desktopNotification = new Notify(polyglot.t('notify_desktop_title'), {
body: 'You got '+polyglot.t("new_posts", newPosts)+' in postboard.',
icon: '../img/twister_mini.png',
tag: 'twister_notification_new_postboard',
timeout: _desktopNotificationTimeout,
notifyClick: function() {
showDesktopNotification(false, polyglot.t('You got')+' '+polyglot.t("new_posts", newPosts)+' '+polyglot.t('in postboard')+'.', false,'twister_notification_new_posts', function() {
requestTimelineUpdate("latest",postsPerRefresh,followingUsers,promotedPostsOnly);
}
});
desktopNotification.show();
}, false)
} else {
newTweetsBar.hide();
newTweetsBar.text("");

20
js/notify.js

@ -41,8 +41,6 @@ @@ -41,8 +41,6 @@
notifyClose: null,
notifyClick: null,
notifyError: null,
permissionGranted: null,
permissionDenied: null,
timeout: null
};
@ -80,16 +78,6 @@ @@ -80,16 +78,6 @@
if (isFunction(this.options.notifyError)) {
this.onErrorCallback = this.options.notifyError;
}
//callback when permission granted after request
if (isFunction(this.options.permissionGranted)) {
this.onPermissionGrantedCallback = this.options.permissionGranted;
}
//callback when permission denied after request
if (isFunction(this.options.permissionDenied)) {
this.onPermissionDeniedCallback = this.options.permissionDenied;
}
}
}
@ -131,14 +119,6 @@ @@ -131,14 +119,6 @@
return;
}
if (Notify.permissionLevel === 'default' ) {
Notify.requestPermission(this.onPermissionGrantedCallback, this.onPermissionDeniedCallback);
}
if (Notify.needsPermission) {
return;
}
this.myNotify = new Notification(this.title, {
'body': this.options.body,
'tag' : this.options.tag,

17
js/options.js

@ -2,7 +2,7 @@ $(function() { @@ -2,7 +2,7 @@ $(function() {
});
var _desktopNotificationTimeout = 40; // it should be an option
var _desktopNotificationTimeout = 10; // it should be an option
var TwisterOptions = function()
{
@ -91,19 +91,8 @@ var TwisterOptions = function() @@ -91,19 +91,8 @@ var TwisterOptions = function()
}
this.notificationDesktopTest = function() {
$('#notifications-desktop-test').on('click', function(){
var desktopNotification = new Notify(polyglot.t('notify_desktop_title'), {
body: polyglot.t('notify_desktop_test'),
icon: '../img/twister_mini.png',
tag: 'twister_notification_test',
timeout: _desktopNotificationTimeout,
notifyError: function() { alert(polyglot.t('notify_desktop_error')); }
});
if (Notify.permissionLevel === 'denied') {
alert(polyglot.t('notify_desktop_perm_denied'));
} else {
desktopNotification.show();
}
$('#notifications-desktop-test').on('click', function() {
showDesktopNotification(false, polyglot.t('notify_desktop_test'), false,'twister_notification_test', false, function() { alert(polyglot.t('notify_desktop_perm_denied')) })
})
}

20
js/twister_newmsgs.js

@ -100,14 +100,7 @@ function requestMentionsCount() { @@ -100,14 +100,7 @@ function requestMentionsCount() {
$.MAL.soundNotifyMentions();
var desktopNotification = new Notify(polyglot.t('notify_desktop_title'), {
body: 'You got '+polyglot.t('new_mentions', _newMentions)+'.',
icon: '../img/twister_mini.png',
tag: 'twister_notification_new_mentions',
timeout: _desktopNotificationTimeout,
notifyClick: openMentionsModal
});
desktopNotification.show();
showDesktopNotification(false, polyglot.t('You got')+' '+polyglot.t('new_mentions', _newMentions)+'.', false,'twister_notification_new_mentions', openMentionsModal, false)
}
// was moved here from requestDMsCount() because that is not ticking right
@ -119,16 +112,9 @@ function requestMentionsCount() { @@ -119,16 +112,9 @@ function requestMentionsCount() {
if ( newDMs ) {
$.MAL.soundNotifyDM();
var desktopNotification = new Notify(polyglot.t('notify_desktop_title'), {
body: 'You got '+polyglot.t('new_direct_messages', newDMs)+'.',
icon: '../img/twister_mini.png',
tag: 'twister_notification_new_DMs',
timeout: _desktopNotificationTimeout,
notifyClick: function() {
showDesktopNotification(false, polyglot.t('You got')+' '+polyglot.t('new_direct_messages', newDMs)+'.', false, 'twister_notification_new_DMs', function() {
window.location.hash = '#directmessages';
}
});
desktopNotification.show();
}, false)
}
}
}

Loading…
Cancel
Save