Skip "contact joined" toast if disabled in Settings.

The chats still appear (they are server-side), but skip the toast.
This commit is contained in:
John Preston 2021-09-23 17:37:29 +04:00
parent cf76933352
commit 2f5bed2899
5 changed files with 21 additions and 8 deletions

View file

@ -341,6 +341,9 @@ enum class MessageFlag : uint32 {
// Fake message for some UI element.
FakeHistoryItem = (1U << 27),
// Contact sign-up message, notification should be skipped for Silent.
IsContactSignUp = (1U << 28),
};
inline constexpr bool is_flag_type(MessageFlag) { return true; }
using MessageFlags = base::flags<MessageFlag>;

View file

@ -459,6 +459,17 @@ bool HistoryItem::isScheduled() const {
&& (_flags & MessageFlag::IsOrWasScheduled);
}
bool HistoryItem::skipNotification() const {
if (isSilent() && (_flags & MessageFlag::IsContactSignUp)) {
return true;
} else if (const auto forwarded = Get<HistoryMessageForwarded>()) {
if (forwarded->imported) {
return true;
}
}
return false;
}
void HistoryItem::destroy() {
_history->destroyMessage(this);
}

View file

@ -109,6 +109,7 @@ public:
[[nodiscard]] bool isAdminLogEntry() const;
[[nodiscard]] bool isFromScheduled() const;
[[nodiscard]] bool isScheduled() const;
[[nodiscard]] bool skipNotification() const;
void addLogEntryOriginal(
WebPageId localId,

View file

@ -554,6 +554,8 @@ void HistoryService::applyAction(const MTPMessageAction &action) {
_flags |= MessageFlag::IsGroupEssential;
}, [&](const MTPDmessageActionChannelMigrateFrom &) {
_flags |= MessageFlag::IsGroupEssential;
}, [&](const MTPDmessageActionContactSignUp &) {
_flags |= MessageFlag::IsContactSignUp;
}, [](const auto &) {
});
}

View file

@ -98,25 +98,21 @@ System::SkipState System::skipNotification(
not_null<HistoryItem*> item) const {
const auto history = item->history();
const auto notifyBy = item->specialNotificationPeer();
if (App::quitting() || !history->currentNotification()) {
if (App::quitting()
|| !history->currentNotification()
|| item->skipNotification()) {
return { SkipState::Skip };
} else if (!Core::App().settings().notifyFromAll()
&& &history->session().account() != &Core::App().domain().active()) {
return { SkipState::Skip };
}
const auto scheduled = item->out() && item->isFromScheduled();
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
if (forwarded->imported) {
return { SkipState::Skip };
}
}
history->owner().requestNotifySettings(history->peer);
if (notifyBy) {
history->owner().requestNotifySettings(notifyBy);
}
const auto scheduled = item->out() && item->isFromScheduled();
if (history->owner().notifyMuteUnknown(history->peer)) {
return { SkipState::Unknown, item->isSilent() };
} else if (!history->owner().notifyIsMuted(history->peer)) {