mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Reaction notifications only from non-blocked contacts.
This commit is contained in:
@@ -68,6 +68,13 @@ QString TextWithPermanentSpoiler(const TextWithEntities &textWithEntities) {
|
||||
|
||||
} // namespace
|
||||
|
||||
struct System::Waiter {
|
||||
NotificationInHistoryKey key;
|
||||
UserData *reactionSender = nullptr;
|
||||
ItemNotificationType type = ItemNotificationType::Message;
|
||||
crl::time when = 0;
|
||||
};
|
||||
|
||||
System::NotificationInHistoryKey::NotificationInHistoryKey(
|
||||
ItemNotification notification)
|
||||
: NotificationInHistoryKey(notification.item->id, notification.type) {
|
||||
@@ -155,24 +162,30 @@ System::SkipState System::skipNotification(
|
||||
&& skipReactionNotification(item))) {
|
||||
return { SkipState::Skip };
|
||||
}
|
||||
const auto showForMuted = messageNotification
|
||||
&& item->out()
|
||||
&& item->isFromScheduled();
|
||||
auto result = computeSkipState(item, showForMuted);
|
||||
if (showForMuted) {
|
||||
result.alsoMuted = true;
|
||||
}
|
||||
if (messageNotification && item->isSilent()) {
|
||||
result.silent = true;
|
||||
}
|
||||
return result;
|
||||
return computeSkipState(notification);
|
||||
}
|
||||
|
||||
System::SkipState System::computeSkipState(
|
||||
not_null<HistoryItem*> item,
|
||||
bool showForMuted) const {
|
||||
ItemNotification notification) const {
|
||||
const auto type = notification.type;
|
||||
const auto item = notification.item;
|
||||
const auto history = item->history();
|
||||
const auto notifyBy = item->specialNotificationPeer();
|
||||
const auto messageNotification = (type == ItemNotificationType::Message);
|
||||
const auto withSilent = [&](
|
||||
SkipState::Value value,
|
||||
bool forceSilent = false) {
|
||||
return SkipState{
|
||||
.value = value,
|
||||
.silent = (forceSilent
|
||||
|| (messageNotification && item->isSilent())),
|
||||
};
|
||||
};
|
||||
const auto showForMuted = messageNotification
|
||||
&& item->out()
|
||||
&& item->isFromScheduled();
|
||||
const auto notifyBy = messageNotification
|
||||
? item->specialNotificationPeer()
|
||||
: notification.reactionSender;
|
||||
if (Core::Quitting()) {
|
||||
return { SkipState::Skip };
|
||||
} else if (!Core::App().settings().notifyFromAll()
|
||||
@@ -180,29 +193,36 @@ System::SkipState System::computeSkipState(
|
||||
return { SkipState::Skip };
|
||||
}
|
||||
|
||||
history->owner().requestNotifySettings(history->peer);
|
||||
if (messageNotification) {
|
||||
history->owner().requestNotifySettings(history->peer);
|
||||
} else if (notifyBy->blockStatus() == PeerData::BlockStatus::Unknown) {
|
||||
notifyBy->updateFull();
|
||||
}
|
||||
if (notifyBy) {
|
||||
history->owner().requestNotifySettings(notifyBy);
|
||||
}
|
||||
|
||||
if (history->owner().notifyMuteUnknown(history->peer)) {
|
||||
if (messageNotification
|
||||
&& history->owner().notifyMuteUnknown(history->peer)) {
|
||||
return { SkipState::Unknown };
|
||||
} else if (!history->owner().notifyIsMuted(history->peer)) {
|
||||
return { SkipState::DontSkip };
|
||||
} else if (messageNotification
|
||||
&& !history->owner().notifyIsMuted(history->peer)) {
|
||||
return withSilent(SkipState::DontSkip);
|
||||
} else if (!notifyBy) {
|
||||
return {
|
||||
return withSilent(
|
||||
showForMuted ? SkipState::DontSkip : SkipState::Skip,
|
||||
showForMuted,
|
||||
};
|
||||
} else if (history->owner().notifyMuteUnknown(notifyBy)) {
|
||||
return { SkipState::Unknown, item->isSilent() };
|
||||
} else if (!history->owner().notifyIsMuted(notifyBy)) {
|
||||
return { SkipState::DontSkip, item->isSilent() };
|
||||
showForMuted);
|
||||
} else if (history->owner().notifyMuteUnknown(notifyBy)
|
||||
|| (!messageNotification
|
||||
&& notifyBy->blockStatus() == PeerData::BlockStatus::Unknown)) {
|
||||
return withSilent(SkipState::Unknown);
|
||||
} else if (!history->owner().notifyIsMuted(notifyBy)
|
||||
&& (messageNotification || !notifyBy->isBlocked())) {
|
||||
return withSilent(SkipState::DontSkip);
|
||||
} else {
|
||||
return {
|
||||
return withSilent(
|
||||
showForMuted ? SkipState::DontSkip : SkipState::Skip,
|
||||
showForMuted,
|
||||
};
|
||||
showForMuted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +268,9 @@ void System::schedule(ItemNotification notification) {
|
||||
? kMinimalForwardDelay
|
||||
: kMinimalDelay;
|
||||
const auto timing = countTiming(history, minimalDelay);
|
||||
const auto notifyBy = item->specialNotificationPeer();
|
||||
const auto notifyBy = (type == ItemNotificationType::Message)
|
||||
? item->specialNotificationPeer()
|
||||
: notification.reactionSender;
|
||||
if (!skip.silent) {
|
||||
_whenAlerts[history].emplace(timing.when, notifyBy);
|
||||
}
|
||||
@@ -265,9 +287,9 @@ void System::schedule(ItemNotification notification) {
|
||||
if (it == addTo.end() || it->second.when > timing.when) {
|
||||
addTo.emplace(history, Waiter{
|
||||
.key = key,
|
||||
.reactionSender = notification.reactionSender,
|
||||
.type = notification.type,
|
||||
.when = timing.when,
|
||||
.notifyBy = notifyBy,
|
||||
.alsoMuted = skip.alsoMuted,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -367,41 +389,29 @@ void System::clearAllFast() {
|
||||
|
||||
void System::checkDelayed() {
|
||||
for (auto i = _settingWaiters.begin(); i != _settingWaiters.end();) {
|
||||
const auto history = i->first;
|
||||
const auto peer = history->peer;
|
||||
auto loaded = false;
|
||||
auto muted = false;
|
||||
if (!peer->owner().notifyMuteUnknown(peer)) {
|
||||
if (!peer->owner().notifyIsMuted(peer)) {
|
||||
loaded = true;
|
||||
} else if (const auto from = i->second.notifyBy) {
|
||||
if (!peer->owner().notifyMuteUnknown(from)) {
|
||||
if (!peer->owner().notifyIsMuted(from)) {
|
||||
loaded = true;
|
||||
} else {
|
||||
loaded = muted = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
loaded = muted = true;
|
||||
const auto remove = [&] {
|
||||
const auto history = i->first;
|
||||
const auto peer = history->peer;
|
||||
const auto fullId = FullMsgId(peer->id, i->second.key.messageId);
|
||||
const auto item = peer->owner().message(fullId);
|
||||
if (!item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (loaded) {
|
||||
const auto fullId = FullMsgId(
|
||||
history->peer->id,
|
||||
i->second.key.messageId);
|
||||
if (const auto item = peer->owner().message(fullId)) {
|
||||
if (!item->notificationReady()) {
|
||||
loaded = false;
|
||||
}
|
||||
} else {
|
||||
muted = true;
|
||||
}
|
||||
}
|
||||
if (loaded) {
|
||||
if (!muted || i->second.alsoMuted) {
|
||||
_waiters.emplace(i->first, i->second);
|
||||
const auto state = computeSkipState({
|
||||
.item = item,
|
||||
.reactionSender = i->second.reactionSender,
|
||||
.type = i->second.type,
|
||||
});
|
||||
if (state.value == SkipState::Skip) {
|
||||
return true;
|
||||
} else if (state.value == SkipState::Unknown
|
||||
|| !item->notificationReady()) {
|
||||
return false;
|
||||
}
|
||||
_waiters.emplace(i->first, i->second);
|
||||
return true;
|
||||
}();
|
||||
if (remove) {
|
||||
i = _settingWaiters.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
@@ -657,14 +667,14 @@ void System::showNext() {
|
||||
const auto reactionNotification
|
||||
= (notify->type == ItemNotificationType::Reaction);
|
||||
const auto reaction = reactionNotification
|
||||
? notify->item->lookupUnreadReaction()
|
||||
: HistoryItemUnreadReaction();
|
||||
if (!reactionNotification || reaction) {
|
||||
? notify->item->lookupUnreadReaction(notify->reactionSender)
|
||||
: QString();
|
||||
if (!reactionNotification || !reaction.isEmpty()) {
|
||||
_manager->showNotification({
|
||||
.item = notify->item,
|
||||
.forwardedCount = forwardedCount,
|
||||
.reactionFrom = reaction.from,
|
||||
.reactionEmoji = reaction.emoji,
|
||||
.reactionFrom = notify->reactionSender,
|
||||
.reactionEmoji = reaction,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user