Allow all messages silent in support mode.

This commit is contained in:
John Preston 2020-11-19 16:23:51 +03:00
parent 1affb8172f
commit 00504b61cd
8 changed files with 70 additions and 38 deletions

View file

@ -86,8 +86,7 @@ void SendExistingMedia(
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
}
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = message.action.options.silent
|| (peer->isBroadcast() && session->data().notifySilentPosts(peer));
const auto silentPost = ShouldSendSilent(peer, message.action.options);
InnerFillMessagePostFlags(message.action.options, peer, flags);
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
@ -261,8 +260,7 @@ bool SendDice(Api::MessageToSend &message) {
}
const auto replyHeader = NewMessageReplyHeader(message.action);
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = message.action.options.silent
|| (peer->isBroadcast() && session->data().notifySilentPosts(peer));
const auto silentPost = ShouldSendSilent(peer, message.action.options);
InnerFillMessagePostFlags(message.action.options, peer, flags);
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
@ -403,7 +401,7 @@ void SendConfirmedFile(
}
const auto replyHeader = NewMessageReplyHeader(action);
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = file->to.options.silent;
const auto silentPost = ShouldSendSilent(peer, file->to.options);
Api::FillMessagePostFlags(action, peer, flags);
if (silentPost) {
flags |= MTPDmessage::Flag::f_silent;

View file

@ -3955,8 +3955,7 @@ void ApiWrap::forwardMessages(
histories.readInbox(history);
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = action.options.silent
|| (peer->isBroadcast() && _session->data().notifySilentPosts(peer));
const auto silentPost = ShouldSendSilent(peer, action.options);
auto flags = MTPDmessage::Flags(0);
auto clientFlags = MTPDmessage_ClientFlags();
@ -4155,11 +4154,7 @@ void ApiWrap::sendSharedContact(
MTP_string(firstName),
MTP_string(lastName),
MTP_string(vcard));
auto options = action.options;
if (_session->data().notifySilentPosts(peer)) {
options.silent = true;
}
sendMedia(item, media, options);
sendMedia(item, media, action.options);
_session->data().sendHistoryChangeNotifications();
_session->changes().historyUpdated(
@ -4374,8 +4369,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
flags |= MTPDmessage::Flag::f_media;
}
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = action.options.silent
|| (peer->isBroadcast() && _session->data().notifySilentPosts(peer));
const auto silentPost = ShouldSendSilent(peer, action.options);
FillMessagePostFlags(action, peer, flags);
if (silentPost) {
sendFlags |= MTPmessages_SendMessage::Flag::f_silent;
@ -4516,8 +4510,7 @@ void ApiWrap::sendInlineResult(
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id;
}
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = action.options.silent
|| (peer->isBroadcast() && _session->data().notifySilentPosts(peer));
const auto silentPost = ShouldSendSilent(peer, action.options);
FillMessagePostFlags(action, peer, flags);
if (silentPost) {
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_silent;
@ -4683,7 +4676,7 @@ void ApiWrap::sendMediaWithRandomId(
| (replyTo
? MTPmessages_SendMedia::Flag::f_reply_to_msg_id
: MTPmessages_SendMedia::Flag(0))
| (options.silent
| (ShouldSendSilent(history->peer, options)
? MTPmessages_SendMedia::Flag::f_silent
: MTPmessages_SendMedia::Flag(0))
| (!sentEntities.v.isEmpty()
@ -4790,7 +4783,7 @@ void ApiWrap::sendAlbumIfReady(not_null<SendingAlbum*> album) {
| (replyTo
? MTPmessages_SendMultiMedia::Flag::f_reply_to_msg_id
: MTPmessages_SendMultiMedia::Flag(0))
| (album->options.silent
| (ShouldSendSilent(history->peer, album->options)
? MTPmessages_SendMultiMedia::Flag::f_silent
: MTPmessages_SendMultiMedia::Flag(0))
| (album->options.scheduled
@ -4828,10 +4821,6 @@ void ApiWrap::sendAlbumIfReady(not_null<SendingAlbum*> album) {
FileLoadTo ApiWrap::fileLoadTaskOptions(const SendAction &action) const {
const auto peer = action.history->peer;
auto options = action.options;
if (_session->data().notifySilentPosts(peer)) {
options.silent = true;
}
return FileLoadTo(peer->id, action.options, action.replyTo);
}
@ -5261,8 +5250,7 @@ void ApiWrap::createPoll(
history->clearLocalDraft();
history->clearCloudDraft();
}
const auto silentPost = action.options.silent
|| (peer->isBroadcast() && _session->data().notifySilentPosts(peer));
const auto silentPost = ShouldSendSilent(peer, action.options);
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
}

View file

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/media/history_view_media.h" // AddTimestampLinks.
#include "chat_helpers/stickers_emoji_pack.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
#include "api/api_updates.h"
#include "boxes/share_box.h"
#include "boxes/confirm_box.h"
@ -277,11 +278,8 @@ void FastShareMessage(not_null<HistoryItem*> item) {
return;
}
const auto sendFlags = MTPmessages_ForwardMessages::Flag(0)
const auto commonSendFlags = MTPmessages_ForwardMessages::Flag(0)
| MTPmessages_ForwardMessages::Flag::f_with_my_score
| (options.silent
? MTPmessages_ForwardMessages::Flag::f_silent
: MTPmessages_ForwardMessages::Flag(0))
| (options.scheduled
? MTPmessages_ForwardMessages::Flag::f_schedule_date
: MTPmessages_ForwardMessages::Flag(0));
@ -311,13 +309,17 @@ void FastShareMessage(not_null<HistoryItem*> item) {
}
histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
auto &api = history->session().api();
const auto sendFlags = commonSendFlags
| (ShouldSendSilent(peer, options)
? MTPmessages_ForwardMessages::Flag::f_silent
: MTPmessages_ForwardMessages::Flag(0));
history->sendRequestId = api.request(MTPmessages_ForwardMessages(
MTP_flags(sendFlags),
data->peer->input,
MTP_vector<MTPint>(msgIds),
MTP_vector<MTPlong>(generateRandom()),
peer->input,
MTP_int(options.scheduled)
MTP_flags(sendFlags),
data->peer->input,
MTP_vector<MTPint>(msgIds),
MTP_vector<MTPlong>(generateRandom()),
peer->input,
MTP_int(options.scheduled)
)).done([=](const MTPUpdates &updates, mtpRequestId requestId) {
history->session().api().applyUpdates(updates);
data->requests.remove(requestId);
@ -375,6 +377,15 @@ MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer) {
return result;
}
bool ShouldSendSilent(
not_null<PeerData*> peer,
const Api::SendOptions &options) {
return options.silent
|| (peer->isBroadcast() && peer->owner().notifySilentPosts(peer))
|| (peer->session().supportMode()
&& peer->session().settings().supportAllSilent());
}
MsgId LookupReplyToTop(not_null<History*> history, MsgId replyToId) {
const auto &owner = history->owner();
if (const auto item = owner.message(history->channelId(), replyToId)) {

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Api {
struct SendAction;
struct SendOptions;
} // namespace Api
namespace HistoryView {
@ -24,6 +25,9 @@ struct HistoryMessageViews;
[[nodiscard]] Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
not_null<HistoryItem*> item);
[[nodiscard]] MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer);
[[nodiscard]] bool ShouldSendSilent(
not_null<PeerData*> peer,
const Api::SendOptions &options);
[[nodiscard]] MTPDmessage_ClientFlags NewMessageClientFlags();
[[nodiscard]] MsgId LookupReplyToTop(
not_null<History*> history,

View file

@ -69,6 +69,7 @@ QByteArray SessionSettings::serialize() const {
stream << quint64(key) << qint32(value);
}
stream << qint32(_dialogsFiltersEnabled ? 1 : 0);
stream << qint32(_supportAllSilent ? 1 : 0);
}
return result;
}
@ -127,6 +128,7 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
qint32 appAutoDownloadDictionaries = app.autoDownloadDictionaries() ? 1 : 0;
base::flat_map<PeerId, MsgId> hiddenPinnedMessages;
qint32 dialogsFiltersEnabled = _dialogsFiltersEnabled ? 1 : 0;
qint32 supportAllSilent = _supportAllSilent ? 1 : 0;
stream >> versionTag;
if (versionTag == kVersionTag) {
@ -321,6 +323,9 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
if (!stream.atEnd()) {
stream >> dialogsFiltersEnabled;
}
if (!stream.atEnd()) {
stream >> supportAllSilent;
}
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for SessionSettings::addFromSerialized()"));
@ -362,6 +367,7 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) {
_mediaLastPlaybackPosition = std::move(mediaLastPlaybackPosition);
_hiddenPinnedMessages = std::move(hiddenPinnedMessages);
_dialogsFiltersEnabled = (dialogsFiltersEnabled == 1);
_supportAllSilent = (supportAllSilent == 1);
if (version < 2) {
app.setLastSeenWarningSeen(appLastSeenWarningSeen == 1);

View file

@ -51,6 +51,12 @@ public:
void setSupportAllSearchResults(bool all);
[[nodiscard]] bool supportAllSearchResults() const;
[[nodiscard]] rpl::producer<bool> supportAllSearchResultsValue() const;
void setSupportAllSilent(bool enabled) {
_supportAllSilent = enabled;
}
[[nodiscard]] bool supportAllSilent() const {
return _supportAllSilent;
}
[[nodiscard]] ChatHelpers::SelectorTab selectorTab() const {
return _selectorTab;
@ -131,6 +137,7 @@ private:
Support::SwitchSettings _supportSwitch;
bool _supportFixChatsOrder = true;
bool _supportTemplatesAutocomplete = true;
bool _supportAllSilent = false;
rpl::variable<int> _supportChatsTimeSlice
= kDefaultSupportChatsLimitSlice;
rpl::variable<bool> _supportAllSearchResults = false;

View file

@ -158,11 +158,15 @@ ApplicationDelegate *_sharedDelegate = nil;
if (!Core::IsAppLaunched()) {
return;
}
Core::App().checkLocalTime();
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
Core::App().checkLocalTime();
LOG(("Audio Info: "
"-receiveWakeNote: received, scheduling detach from audio device"));
Media::Audio::ScheduleDetachFromDeviceSafe();
LOG(("Audio Info: "
"-receiveWakeNote: received, scheduling detach from audio device"));
Media::Audio::ScheduleDetachFromDeviceSafe();
Core::App().settings().setSystemDarkMode(Platform::IsDarkMode());
});
}
- (void) setWatchingMediaKeys:(bool)watching {

View file

@ -1419,6 +1419,20 @@ void SetupSupport(
controller->session().saveSettingsDelayed();
}, inner->lifetime());
inner->add(
object_ptr<Ui::Checkbox>(
inner,
"Send all messages without sound",
controller->session().settings().supportAllSilent(),
st::settingsCheckbox),
st::settingsSendTypePadding
)->checkedChanges(
) | rpl::start_with_next([=](bool checked) {
controller->session().settings().setSupportAllSilent(
checked);
controller->session().saveSettingsDelayed();
}, inner->lifetime());
AddSkip(inner, st::settingsCheckboxesSkip);
AddSubsectionTitle(inner, rpl::single(qsl("Load chats for a period")));