mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
New notifications API, defaults for users/chats.
This commit is contained in:
@@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "history/history_item_components.h"
|
||||
#include "history/feed/history_feed_section.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "data/data_session.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
@@ -59,7 +60,7 @@ void System::createManager() {
|
||||
void System::schedule(History *history, HistoryItem *item) {
|
||||
if (App::quitting() || !history->currentNotification() || !AuthSession::Exists()) return;
|
||||
|
||||
auto notifyByFrom = (!history->peer->isUser() && item->mentionsMe())
|
||||
const auto notifyBy = (!history->peer->isUser() && item->mentionsMe())
|
||||
? item->from().get()
|
||||
: nullptr;
|
||||
|
||||
@@ -68,35 +69,31 @@ void System::schedule(History *history, HistoryItem *item) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto haveSetting = !history->peer->notifySettingsUnknown();
|
||||
if (haveSetting) {
|
||||
if (history->peer->isMuted()) {
|
||||
if (notifyByFrom) {
|
||||
haveSetting = !item->from()->notifySettingsUnknown();
|
||||
if (haveSetting) {
|
||||
if (notifyByFrom->isMuted()) {
|
||||
history->popNotification(item);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Auth().api().requestNotifySetting(notifyByFrom);
|
||||
Auth().data().requestNotifySettings(history->peer);
|
||||
if (notifyBy) {
|
||||
Auth().data().requestNotifySettings(notifyBy);
|
||||
}
|
||||
auto haveSetting = !Auth().data().notifyMuteUnknown(history->peer);
|
||||
if (haveSetting && Auth().data().notifyIsMuted(history->peer)) {
|
||||
if (notifyBy) {
|
||||
haveSetting = !Auth().data().notifyMuteUnknown(notifyBy);
|
||||
if (haveSetting) {
|
||||
if (Auth().data().notifyIsMuted(notifyBy)) {
|
||||
history->popNotification(item);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
history->popNotification(item);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
history->popNotification(item);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (notifyByFrom && notifyByFrom->notifySettingsUnknown()) {
|
||||
Auth().api().requestNotifySetting(notifyByFrom);
|
||||
}
|
||||
Auth().api().requestNotifySetting(history->peer);
|
||||
}
|
||||
if (!item->notificationReady()) {
|
||||
haveSetting = false;
|
||||
}
|
||||
|
||||
int delay = item->Has<HistoryMessageForwarded>() ? 500 : 100, t = unixtime();
|
||||
auto delay = item->Has<HistoryMessageForwarded>() ? 500 : 100;
|
||||
auto t = unixtime();
|
||||
auto ms = getms(true);
|
||||
bool isOnline = App::main()->lastWasOnline(), otherNotOld = ((cOtherOnline() * 1000LL) + Global::OnlineCloudTimeout() > t * 1000LL);
|
||||
bool otherLaterThanMe = (cOtherOnline() * 1000LL + (ms - App::main()->lastSetOnline()) > t * 1000LL);
|
||||
@@ -107,7 +104,7 @@ void System::schedule(History *history, HistoryItem *item) {
|
||||
}
|
||||
|
||||
auto when = ms + delay;
|
||||
_whenAlerts[history].insert(when, notifyByFrom);
|
||||
_whenAlerts[history].insert(when, notifyBy);
|
||||
if (Global::DesktopNotify() && !Platform::Notifications::SkipToast()) {
|
||||
auto &whenMap = _whenMaps[history];
|
||||
if (whenMap.constFind(item->id) == whenMap.cend()) {
|
||||
@@ -117,7 +114,7 @@ void System::schedule(History *history, HistoryItem *item) {
|
||||
auto &addTo = haveSetting ? _waiters : _settingWaiters;
|
||||
auto it = addTo.constFind(history);
|
||||
if (it == addTo.cend() || it->when > when) {
|
||||
addTo.insert(history, Waiter(item->id, when, notifyByFrom));
|
||||
addTo.insert(history, Waiter(item->id, when, notifyBy));
|
||||
}
|
||||
}
|
||||
if (haveSetting) {
|
||||
@@ -171,12 +168,12 @@ void System::checkDelayed() {
|
||||
const auto peer = history->peer;
|
||||
auto loaded = false;
|
||||
auto muted = false;
|
||||
if (!peer->notifySettingsUnknown()) {
|
||||
if (!peer->isMuted()) {
|
||||
if (!Auth().data().notifyMuteUnknown(peer)) {
|
||||
if (!Auth().data().notifyIsMuted(peer)) {
|
||||
loaded = true;
|
||||
} else if (const auto from = i.value().notifyByFrom) {
|
||||
if (!from->notifySettingsUnknown()) {
|
||||
if (!from->isMuted()) {
|
||||
} else if (const auto from = i.value().notifyBy) {
|
||||
if (!Auth().data().notifyMuteUnknown(from)) {
|
||||
if (!Auth().data().notifyIsMuted(from)) {
|
||||
loaded = true;
|
||||
} else {
|
||||
loaded = muted = true;
|
||||
@@ -220,11 +217,14 @@ void System::showNext() {
|
||||
for (auto i = _whenAlerts.begin(); i != _whenAlerts.end();) {
|
||||
while (!i.value().isEmpty() && i.value().begin().key() <= ms) {
|
||||
const auto peer = i.key()->peer;
|
||||
const auto peerUnknown = peer->notifySettingsUnknown();
|
||||
const auto peerAlert = peerUnknown ? false : !peer->isMuted();
|
||||
const auto peerUnknown = Auth().data().notifyMuteUnknown(peer);
|
||||
const auto peerAlert = !peerUnknown
|
||||
&& !Auth().data().notifyIsMuted(peer);
|
||||
const auto from = i.value().begin().value();
|
||||
const auto fromUnknown = (!from || from->notifySettingsUnknown());
|
||||
const auto fromAlert = fromUnknown ? false : !from->isMuted();
|
||||
const auto fromUnknown = (!from
|
||||
|| Auth().data().notifyMuteUnknown(from));
|
||||
const auto fromAlert = !fromUnknown
|
||||
&& !Auth().data().notifyIsMuted(from);
|
||||
if (peerAlert || fromAlert) {
|
||||
alert = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user