mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-01-14 08:58:05 +00:00
tune new DMs notification
This commit is contained in:
parent
01283059db
commit
e3c66c9568
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
// --- mentions ---
|
// --- mentions ---
|
||||||
|
|
||||||
var _newDMsUpdated = false;
|
|
||||||
var groupChatAliases = []
|
var groupChatAliases = []
|
||||||
|
|
||||||
function saveMentionsToStorage() {
|
function saveMentionsToStorage() {
|
||||||
@ -90,39 +89,6 @@ function requestMentionsCount() {
|
|||||||
processNewMentions, undefined,
|
processNewMentions, undefined,
|
||||||
twister.res[defaultScreenName + '@mention'].timeoutArgs
|
twister.res[defaultScreenName + '@mention'].timeoutArgs
|
||||||
);
|
);
|
||||||
|
|
||||||
// was moved here from requestDMsCount() because that is not ticking right
|
|
||||||
// we would place it with other notifications into separate notification center
|
|
||||||
if (_newDMsUpdated) {
|
|
||||||
_newDMsUpdated = false;
|
|
||||||
|
|
||||||
var newDMs = getNewDMsCount();
|
|
||||||
if (newDMs) {
|
|
||||||
$.MAL.soundNotifyDM();
|
|
||||||
|
|
||||||
if (!$.hasOwnProperty('mobile') && $.Options.showDesktopNotifDMs.val === 'enable') {
|
|
||||||
$.MAL.showDesktopNotification({
|
|
||||||
body: polyglot.t('You got') + ' ' + polyglot.t('new_direct_messages', newDMs) + '.',
|
|
||||||
tag: 'twister_notification_new_DMs',
|
|
||||||
timeout: $.Options.showDesktopNotifDMsTimer.val,
|
|
||||||
funcClick: function () {$.MAL.showDMchat();}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var newDMs = getNewGroupDMsCount();
|
|
||||||
if (newDMs) {
|
|
||||||
$.MAL.soundNotifyDM();
|
|
||||||
|
|
||||||
if (!$.hasOwnProperty('mobile') && $.Options.showDesktopNotifDMs.val === 'enable') {
|
|
||||||
$.MAL.showDesktopNotification({
|
|
||||||
body: polyglot.t('You got') + ' ' + polyglot.t('new_group_messages', newDMs) + '.',
|
|
||||||
tag: 'twister_notification_new_DMs',
|
|
||||||
timeout: $.Options.showDesktopNotifDMsTimer.val,
|
|
||||||
funcClick: function () {$.MAL.showDMchat({group: true});}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function processNewMentions(req, res) {
|
function processNewMentions(req, res) {
|
||||||
@ -263,25 +229,51 @@ function requestDMsCount() {
|
|||||||
|
|
||||||
twisterRpc('getdirectmsgs', [defaultScreenName, 1, followList],
|
twisterRpc('getdirectmsgs', [defaultScreenName, 1, followList],
|
||||||
function(req, dmUsers) {
|
function(req, dmUsers) {
|
||||||
|
var newDMsUpdated;
|
||||||
|
|
||||||
for (var u in dmUsers) {
|
for (var u in dmUsers) {
|
||||||
if (dmUsers[u]) {
|
if (dmUsers[u]) {
|
||||||
var dmData = dmUsers[u][0];
|
var dmData = dmUsers[u][0];
|
||||||
if (u in _lastDMIdPerUser && u in _newDMsPerUser) {
|
if (u in _lastDMIdPerUser && u in _newDMsPerUser) {
|
||||||
if (dmData.id !== _lastDMIdPerUser[u]) {
|
if (dmData.id !== _lastDMIdPerUser[u]) {
|
||||||
_newDMsPerUser[u] += dmData.id - _lastDMIdPerUser[u];
|
_newDMsPerUser[u] += dmData.id - _lastDMIdPerUser[u];
|
||||||
_newDMsUpdated = true;
|
newDMsUpdated = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_newDMsPerUser[u] = dmData.id + 1;
|
_newDMsPerUser[u] = dmData.id + 1;
|
||||||
_newDMsUpdated = true;
|
newDMsUpdated = true;
|
||||||
}
|
}
|
||||||
_lastDMIdPerUser[u] = dmData.id;
|
_lastDMIdPerUser[u] = dmData.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_newDMsUpdated) {
|
if (newDMsUpdated) {
|
||||||
saveDMsToStorage();
|
saveDMsToStorage();
|
||||||
$.MAL.updateNewDMsUI(getNewDMsCount());
|
var newDMs = getNewDMsCount();
|
||||||
$.MAL.updateNewGroupDMsUI(getNewGroupDMsCount());
|
if (newDMs) {
|
||||||
|
$.MAL.updateNewDMsUI(newDMs);
|
||||||
|
$.MAL.soundNotifyDM();
|
||||||
|
if (!$.mobile && $.Options.showDesktopNotifDMs.val === 'enable') {
|
||||||
|
$.MAL.showDesktopNotification({
|
||||||
|
body: polyglot.t('You got') + ' ' + polyglot.t('new_direct_messages', newDMs) + '.',
|
||||||
|
tag: 'twister_notification_new_DMs',
|
||||||
|
timeout: $.Options.showDesktopNotifDMsTimer.val,
|
||||||
|
funcClick: function () {$.MAL.showDMchat();}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newDMs = getNewGroupDMsCount();
|
||||||
|
if (newDMs) {
|
||||||
|
$.MAL.updateNewGroupDMsUI(newDMs);
|
||||||
|
$.MAL.soundNotifyDM();
|
||||||
|
if (!$.mobile && $.Options.showDesktopNotifDMs.val === 'enable') {
|
||||||
|
$.MAL.showDesktopNotification({
|
||||||
|
body: polyglot.t('You got') + ' ' + polyglot.t('new_group_messages', newDMs) + '.',
|
||||||
|
tag: 'twister_notification_new_DMs',
|
||||||
|
timeout: $.Options.showDesktopNotifDMsTimer.val,
|
||||||
|
funcClick: function () {$.MAL.showDMchat({group: true});}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, null,
|
}, null,
|
||||||
function(req, ret) {console.warn('ajax error:' + ret);}, null
|
function(req, ret) {console.warn('ajax error:' + ret);}, null
|
||||||
|
Loading…
Reference in New Issue
Block a user