Read silent flag from PeerData, not SilentToggle.

This commit is contained in:
John Preston 2017-12-08 15:52:12 +04:00
parent c79d16a0d6
commit f8963d7e4b
9 changed files with 258 additions and 150 deletions

View file

@ -2432,12 +2432,12 @@ void ApiWrap::forwardMessages(
const auto count = int(items.size());
const auto genClientSideMessage = options.generateLocal && (count < 2);
const auto history = options.history;
const auto peer = history->peer;
readServerHistory(history);
const auto channelPost = history->peer->isChannel()
&& !history->peer->isMegagroup();
const auto silentPost = channelPost && options.silent;
const auto channelPost = peer->isChannel() && !peer->isMegagroup();
const auto silentPost = channelPost && peer->notifySilentPosts();
auto flags = MTPDmessage::Flags(0);
auto sendFlags = MTPmessages_ForwardMessages::Flags(0);
@ -2447,7 +2447,7 @@ void ApiWrap::forwardMessages(
}
if (!channelPost) {
flags |= MTPDmessage::Flag::f_from_id;
} else if (history->peer->asChannel()->addsSignature()) {
} else if (peer->asChannel()->addsSignature()) {
flags |= MTPDmessage::Flag::f_post_author;
}
if (silentPost) {
@ -2467,7 +2467,7 @@ void ApiWrap::forwardMessages(
forwardFrom->input,
MTP_vector<MTPint>(ids),
MTP_vector<MTPlong>(randomIds),
history->peer->input
peer->input
)).done([=, callback = std::move(successCallback)](
const MTPUpdates &updates) {
applyUpdates(updates);
@ -2489,7 +2489,7 @@ void ApiWrap::forwardMessages(
if (genClientSideMessage) {
if (auto message = item->toHistoryMessage()) {
const auto newId = FullMsgId(
peerToChannel(history->peer->id),
peerToChannel(peer->id),
clientMsgId());
const auto self = Auth().user();
const auto messageFromId = channelPost
@ -2559,7 +2559,7 @@ void ApiWrap::sendSharedContact(
const auto randomId = rand_value<uint64>();
const auto newId = FullMsgId(history->channelId(), clientMsgId());
const auto channelPost = peer->isChannel() && !peer->isMegagroup();
const auto silentPost = channelPost && options.silent;
const auto silentPost = channelPost && peer->notifySilentPosts();
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media;

View file

@ -165,7 +165,6 @@ public:
not_null<History*> history;
MsgId replyTo = 0;
bool silent = false;
WebPageId webPageId = 0;
bool clearDraft = false;
bool generateLocal = true;

View file

@ -422,79 +422,6 @@ HistoryHider::~HistoryHider() {
parent()->noHider(this);
}
class SilentToggle : public Ui::IconButton, public Ui::AbstractTooltipShower {
public:
SilentToggle(QWidget *parent);
void setChecked(bool checked);
bool checked() const {
return _checked;
}
// AbstractTooltipShower interface
QString tooltipText() const override;
QPoint tooltipPos() const override;
protected:
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void leaveEventHook(QEvent *e) override;
private:
bool _checked = false;
};
SilentToggle::SilentToggle(QWidget *parent) : IconButton(parent, st::historySilentToggle) {
setMouseTracking(true);
}
void SilentToggle::mouseMoveEvent(QMouseEvent *e) {
IconButton::mouseMoveEvent(e);
if (rect().contains(e->pos())) {
Ui::Tooltip::Show(1000, this);
} else {
Ui::Tooltip::Hide();
}
}
void SilentToggle::setChecked(bool checked) {
if (_checked != checked) {
_checked = checked;
setIconOverride(_checked ? &st::historySilentToggleOn : nullptr, _checked ? &st::historySilentToggleOnOver : nullptr);
}
}
void SilentToggle::leaveEventHook(QEvent *e) {
IconButton::leaveEventHook(e);
Ui::Tooltip::Hide();
}
void SilentToggle::mouseReleaseEvent(QMouseEvent *e) {
setChecked(!_checked);
IconButton::mouseReleaseEvent(e);
Ui::Tooltip::Show(0, this);
if (const auto peer = App::main() ? App::main()->peer() : nullptr) {
if (peer->isChannel() && !peer->notifySettingsUnknown()) {
const auto silentState = _checked
? Data::NotifySettings::SilentPostsChange::Silent
: Data::NotifySettings::SilentPostsChange::Notify;
App::main()->updateNotifySettings(
peer,
Data::NotifySettings::MuteChange::Ignore,
silentState);
}
}
}
QString SilentToggle::tooltipText() const {
return lang(_checked ? lng_wont_be_notified : lng_will_be_notified);
}
QPoint SilentToggle::tooltipPos() const {
return QCursor::pos();
}
HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> controller) : Window::AbstractSectionWidget(parent, controller)
, _fieldBarCancel(this, st::historyReplyCancel)
, _topBar(this, controller)
@ -512,7 +439,6 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
, _botKeyboardShow(this, st::historyBotKeyboardShow)
, _botKeyboardHide(this, st::historyBotKeyboardHide)
, _botCommandStart(this, st::historyBotCommandStart)
, _silent(this)
, _field(this, controller, st::historyComposeField, langFactory(lng_message_ph))
, _recordCancelWidth(st::historyRecordFont->width(lang(lng_record_cancel)))
, _a_recording(animation(this, &HistoryWidget::step_recording))
@ -535,7 +461,6 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
connect(_botStart, SIGNAL(clicked()), this, SLOT(onBotStart()));
connect(_joinChannel, SIGNAL(clicked()), this, SLOT(onJoinChannel()));
connect(_muteUnmute, SIGNAL(clicked()), this, SLOT(onMuteUnmute()));
connect(_silent, SIGNAL(clicked()), this, SLOT(onBroadcastSilentChange()));
connect(_field, SIGNAL(submitted(bool)), this, SLOT(onSend(bool)));
connect(_field, SIGNAL(cancelled()), this, SLOT(onCancel()));
connect(_field, SIGNAL(tabbed()), this, SLOT(onFieldTabbed()));
@ -622,7 +547,6 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
_tabbedSelectorToggle->hide();
_botKeyboardShow->hide();
_botKeyboardHide->hide();
_silent->hide();
_botCommandStart->hide();
_tabbedSelectorToggle->installEventFilter(_tabbedPanel);
@ -1000,11 +924,17 @@ void HistoryWidget::onMentionInsert(UserData *user) {
_field->insertTag(replacement, entityTag);
}
void HistoryWidget::onHashtagOrBotCommandInsert(QString str, FieldAutocomplete::ChooseMethod method) {
void HistoryWidget::onHashtagOrBotCommandInsert(
QString str,
FieldAutocomplete::ChooseMethod method) {
if (!_peer) {
return;
}
// Send bot command at once, if it was not inserted by pressing Tab.
if (str.at(0) == '/' && method != FieldAutocomplete::ChooseMethod::ByTab) {
App::sendBotCommand(_peer, nullptr, str, replyToId());
App::main()->finishForwarding(_history, _silent->checked());
App::main()->finishForwarding(_history);
setFieldText(_field->getTextWithTagsPart(_field->textCursor().position()));
} else {
_field->insertTag(str);
@ -1351,7 +1281,7 @@ void HistoryWidget::onRecordDone(QByteArray result, VoiceWaveform waveform, qint
App::wnd()->activateWindow();
auto duration = samples / Media::Player::kDefaultFrequency;
auto to = FileLoadTo(_peer->id, _silent->checked(), replyToId());
auto to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId());
auto caption = QString();
_fileLoader.addTask(MakeShared<FileLoadTask>(result, duration, waveform, to, caption));
}
@ -1723,6 +1653,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
_peer = nullptr;
_channel = NoChannel;
_canSendMessages = false;
_silent.destroy();
updateBotKeyboard();
}
@ -1791,6 +1722,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
if (_peer->notifySettingsUnknown()) {
Auth().api().requestNotifySetting(_peer);
}
refreshSilentToggle();
}
if (_showAtMsgId == ShowAtUnreadMsgId) {
@ -1896,13 +1828,24 @@ void HistoryWidget::updateNotifySettings() {
? lng_channel_unmute
: lng_channel_mute).toUpper());
if (!_peer->notifySettingsUnknown()) {
_silent->setChecked(_peer->notifySilentPosts());
if (_silent->isHidden() && hasSilentToggle()) {
if (_silent) {
_silent->setChecked(_peer->notifySilentPosts());
} else if (hasSilentToggle()) {
refreshSilentToggle();
updateControlsGeometry();
updateControlsVisibility();
}
}
}
void HistoryWidget::refreshSilentToggle() {
if (!_silent && hasSilentToggle()) {
_silent.create(this, _peer->asChannel());
} else if (_silent && !hasSilentToggle()) {
_silent.destroy();
}
}
bool HistoryWidget::contentOverlapped(const QRect &globalRect) {
return (_attachDragDocument->overlaps(globalRect)
|| _attachDragPhoto->overlaps(globalRect)
@ -2086,7 +2029,9 @@ void HistoryWidget::updateControlsVisibility() {
_kbShown = false;
_fieldAutocomplete->hide();
_send->hide();
_silent->hide();
if (_silent) {
_silent->hide();
}
_kbScroll->hide();
_fieldBarCancel->hide();
_attachToggle->hide();
@ -2120,7 +2065,9 @@ void HistoryWidget::updateControlsVisibility() {
_botKeyboardHide->hide();
_botCommandStart->hide();
_attachToggle->hide();
_silent->hide();
if (_silent) {
_silent->hide();
}
if (_kbShown) {
_kbScroll->show();
} else {
@ -2157,10 +2104,8 @@ void HistoryWidget::updateControlsVisibility() {
}
}
_attachToggle->show();
if (hasSilentToggle()) {
if (_silent) {
_silent->show();
} else {
_silent->hide();
}
updateFieldPlaceholder();
}
@ -2181,7 +2126,9 @@ void HistoryWidget::updateControlsVisibility() {
_joinChannel->hide();
_muteUnmute->hide();
_attachToggle->hide();
_silent->hide();
if (_silent) {
_silent->hide();
}
_kbScroll->hide();
_fieldBarCancel->hide();
_attachToggle->hide();
@ -2923,7 +2870,6 @@ void HistoryWidget::onSend(bool ctrlShiftEnter) {
auto message = MainWidget::MessageToSend(_history);
message.textWithTags = _field->getTextWithTags();
message.replyTo = replyToId();
message.silent = _silent->checked();
message.webPageId = webPageId;
App::main()->sendMessage(message);
@ -3331,7 +3277,6 @@ void HistoryWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString
? replyTo
: replyToId())
: 0;
message.silent = false;
App::main()->sendMessage(message);
if (replyTo) {
if (_replyToId == replyTo) {
@ -3588,7 +3533,7 @@ bool HistoryWidget::hasSilentToggle() const {
return _peer
&& _peer->isChannel()
&& !_peer->isMegagroup()
&& _peer->asChannel()->canPublish()
&& _peer->canWrite()
&& !_peer->notifySettingsUnknown();
}
@ -3931,7 +3876,9 @@ void HistoryWidget::moveFieldControls() {
_botKeyboardHide->moveToRight(right, buttonsBottom); right += _botKeyboardHide->width();
_botKeyboardShow->moveToRight(right, buttonsBottom);
_botCommandStart->moveToRight(right, buttonsBottom);
_silent->moveToRight(right, buttonsBottom);
if (_silent) {
_silent->moveToRight(right, buttonsBottom);
}
_fieldBarCancel->moveToRight(0, _field->y() - st::historySendPadding - _fieldBarCancel->height());
if (_inlineResults) {
@ -3968,7 +3915,7 @@ void HistoryWidget::updateFieldSize() {
fieldWidth -= _tabbedSelectorToggle->width();
if (kbShowShown) fieldWidth -= _botKeyboardShow->width();
if (_cmdStartShown) fieldWidth -= _botCommandStart->width();
if (hasSilentToggle()) fieldWidth -= _silent->width();
if (_silent) fieldWidth -= _silent->width();
if (_field->width() != fieldWidth) {
_field->resize(fieldWidth, _field->height());
@ -4031,7 +3978,13 @@ void HistoryWidget::updateFieldPlaceholder() {
auto text = _inlineBot->botInfo->inlinePlaceholder.mid(1);
_field->setPlaceholder([text] { return text; }, _inlineBot->username.size() + 2);
} else {
_field->setPlaceholder(langFactory((_history && _history->isChannel() && !_history->isMegagroup()) ? (_silent->checked() ? lng_broadcast_silent_ph : lng_broadcast_ph) : lng_message_ph));
const auto peer = _history->peer;
_field->setPlaceholder(langFactory(
(peer && peer->isChannel() && !peer->isMegagroup())
? (peer->notifySilentPosts()
? lng_broadcast_silent_ph
: lng_broadcast_ph)
: lng_message_ph));
}
}
updateSendButtonType();
@ -4251,12 +4204,11 @@ void HistoryWidget::uploadFilesAfterConfirmation(
QString caption) {
Assert(canWriteMessage());
auto to = FileLoadTo(_peer->id, _silent->checked(), replyToId());
auto to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId());
if (files.size() > 1 && !caption.isEmpty()) {
auto message = MainWidget::MessageToSend(_history);
message.textWithTags = { caption, TextWithTags::Tags() };
message.replyTo = to.replyTo;
message.silent = to.silent;
message.clearDraft = false;
App::main()->sendMessage(message);
caption = QString();
@ -4276,7 +4228,7 @@ void HistoryWidget::uploadFilesAfterConfirmation(
void HistoryWidget::uploadFile(const QByteArray &fileContent, SendMediaType type) {
if (!canWriteMessage()) return;
auto to = FileLoadTo(_peer->id, _silent->checked(), replyToId());
auto to = FileLoadTo(_peer->id, _peer->notifySilentPosts(), replyToId());
auto caption = QString();
_fileLoader.addTask(MakeShared<FileLoadTask>(fileContent, QImage(), type, to, caption));
}
@ -4303,7 +4255,6 @@ void HistoryWidget::sendFileConfirmed(const FileLoadResultPtr &file) {
options.clearDraft = false;
options.replyTo = file->to.replyTo;
options.generateLocal = true;
options.silent = file->to.silent;
Auth().api().sendAction(options);
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media;
@ -4423,7 +4374,10 @@ void HistoryWidget::sendFileConfirmed(const FileLoadResultPtr &file) {
peerMessagesUpdated(file->to.peer);
}
void HistoryWidget::onPhotoUploaded(const FullMsgId &newId, bool silent, const MTPInputFile &file) {
void HistoryWidget::onPhotoUploaded(
const FullMsgId &newId,
bool silent,
const MTPInputFile &file) {
if (auto item = App::histItemById(newId)) {
uint64 randomId = rand_value<uint64>();
App::historyRegRandom(randomId, newId);
@ -4462,7 +4416,10 @@ void HistoryWidget::onPhotoUploaded(const FullMsgId &newId, bool silent, const M
}
}
void HistoryWidget::onDocumentUploaded(const FullMsgId &newId, bool silent, const MTPInputFile &file) {
void HistoryWidget::onDocumentUploaded(
const FullMsgId &newId,
bool silent,
const MTPInputFile &file) {
if (auto item = dynamic_cast<HistoryMessage*>(App::histItemById(newId))) {
auto media = item->getMedia();
if (auto document = media ? media->getDocument() : nullptr) {
@ -4507,7 +4464,11 @@ void HistoryWidget::onDocumentUploaded(const FullMsgId &newId, bool silent, cons
}
}
void HistoryWidget::onThumbDocumentUploaded(const FullMsgId &newId, bool silent, const MTPInputFile &file, const MTPInputFile &thumb) {
void HistoryWidget::onThumbDocumentUploaded(
const FullMsgId &newId,
bool silent,
const MTPInputFile &file,
const MTPInputFile &thumb) {
if (auto item = dynamic_cast<HistoryMessage*>(App::histItemById(newId))) {
auto media = item->getMedia();
if (auto document = media ? media->getDocument() : nullptr) {
@ -5291,7 +5252,9 @@ void HistoryWidget::onPhotoSend(PhotoData *photo) {
sendExistingPhoto(photo, QString());
}
void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot) {
void HistoryWidget::onInlineResultSend(
InlineBots::Result *result,
UserData *bot) {
if (!_peer || !_peer->canWrite() || !result) {
return;
}
@ -5306,7 +5269,6 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot
options.clearDraft = true;
options.replyTo = replyToId();
options.generateLocal = true;
options.silent = _silent->checked();
Auth().api().sendAction(options);
uint64 randomId = rand_value<uint64>();
@ -5319,7 +5281,7 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id;
}
bool channelPost = _peer->isChannel() && !_peer->isMegagroup();
bool silentPost = channelPost && options.silent;
bool silentPost = channelPost && _peer->notifySilentPosts();
if (channelPost) {
flags |= MTPDmessage::Flag::f_views;
flags |= MTPDmessage::Flag::f_post;
@ -5345,7 +5307,7 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot
result->addToHistory(_history, flags, messageId, messageFromId, messageDate, messageViaBotId, replyToId(), messagePostAuthor);
_history->sendRequestId = MTP::send(MTPmessages_SendInlineBotResult(MTP_flags(sendFlags), _peer->input, MTP_int(replyToId()), MTP_long(randomId), MTP_long(result->getQueryId()), MTP_string(result->getId())), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId);
App::main()->finishForwarding(_history, _silent->checked());
App::main()->finishForwarding(_history);
App::historyRegRandom(randomId, newId);
@ -5475,7 +5437,9 @@ void HistoryWidget::destroyPinnedBar() {
_inPinnedMsg = false;
}
bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &caption) {
bool HistoryWidget::sendExistingDocument(
DocumentData *doc,
const QString &caption) {
if (!_peer || !_peer->canWrite() || !doc) {
return false;
}
@ -5489,7 +5453,6 @@ bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti
options.clearDraft = false;
options.replyTo = replyToId();
options.generateLocal = true;
options.silent = _silent->checked();
Auth().api().sendAction(options);
uint64 randomId = rand_value<uint64>();
@ -5502,7 +5465,7 @@ bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
}
bool channelPost = _peer->isChannel() && !_peer->isMegagroup();
bool silentPost = channelPost && options.silent;
bool silentPost = channelPost && _peer->notifySilentPosts();
if (channelPost) {
flags |= MTPDmessage::Flag::f_views;
flags |= MTPDmessage::Flag::f_post;
@ -5517,10 +5480,36 @@ bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti
}
auto messageFromId = channelPost ? 0 : Auth().userId();
auto messagePostAuthor = channelPost ? (Auth().user()->firstName + ' ' + Auth().user()->lastName) : QString();
_history->addNewDocument(newId.msg, flags, 0, replyToId(), date(MTP_int(unixtime())), messageFromId, messagePostAuthor, doc, caption, MTPnullMarkup);
_history->addNewDocument(
newId.msg,
flags,
0,
replyToId(),
date(MTP_int(unixtime())),
messageFromId,
messagePostAuthor,
doc,
caption,
MTPnullMarkup);
_history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaDocument(MTP_flags(0), mtpInput, MTP_string(caption), MTPint()), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId);
App::main()->finishForwarding(_history, _silent->checked());
_history->sendRequestId = MTP::send(
MTPmessages_SendMedia(
MTP_flags(sendFlags),
_peer->input,
MTP_int(replyToId()),
MTP_inputMediaDocument(
MTP_flags(0),
mtpInput,
MTP_string(caption),
MTPint()),
MTP_long(randomId),
MTPnullMarkup),
App::main()->rpcDone(&MainWidget::sentUpdatesReceived),
App::main()->rpcFail(&MainWidget::sendMessageFail),
0,
0,
_history->sendRequestId);
App::main()->finishForwarding(_history);
if (doc->sticker()) App::main()->incrementSticker(doc);
@ -5540,7 +5529,9 @@ bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti
return true;
}
void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption) {
void HistoryWidget::sendExistingPhoto(
PhotoData *photo,
const QString &caption) {
if (!_peer || !_peer->canWrite() || !photo) {
return;
}
@ -5549,7 +5540,6 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption)
options.clearDraft = false;
options.replyTo = replyToId();
options.generateLocal = true;
options.silent = _silent->checked();
Auth().api().sendAction(options);
uint64 randomId = rand_value<uint64>();
@ -5562,7 +5552,7 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption)
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
}
bool channelPost = _peer->isChannel() && !_peer->isMegagroup();
bool silentPost = channelPost && _silent->checked();
bool silentPost = channelPost && _peer->notifySilentPosts();
if (channelPost) {
flags |= MTPDmessage::Flag::f_views;
flags |= MTPDmessage::Flag::f_post;
@ -5577,10 +5567,36 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption)
}
auto messageFromId = channelPost ? 0 : Auth().userId();
auto messagePostAuthor = channelPost ? (Auth().user()->firstName + ' ' + Auth().user()->lastName) : QString();
_history->addNewPhoto(newId.msg, flags, 0, replyToId(), date(MTP_int(unixtime())), messageFromId, messagePostAuthor, photo, caption, MTPnullMarkup);
_history->addNewPhoto(
newId.msg,
flags,
0,
replyToId(),
date(MTP_int(unixtime())),
messageFromId,
messagePostAuthor,
photo,
caption,
MTPnullMarkup);
_history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaPhoto(MTP_flags(0), MTP_inputPhoto(MTP_long(photo->id), MTP_long(photo->access)), MTP_string(caption), MTPint()), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId);
App::main()->finishForwarding(_history, _silent->checked());
_history->sendRequestId = MTP::send(
MTPmessages_SendMedia(
MTP_flags(sendFlags),
_peer->input,
MTP_int(replyToId()),
MTP_inputMediaPhoto(
MTP_flags(0),
MTP_inputPhoto(MTP_long(photo->id), MTP_long(photo->access)),
MTP_string(caption),
MTPint()),
MTP_long(randomId),
MTPnullMarkup),
App::main()->rpcDone(&MainWidget::sentUpdatesReceived),
App::main()->rpcFail(&MainWidget::sendMessageFail),
0,
0,
_history->sendRequestId);
App::main()->finishForwarding(_history);
App::historyRegRandom(randomId, newId);
@ -6071,6 +6087,7 @@ void HistoryWidget::onCancel() {
}
void HistoryWidget::fullPeerUpdated(PeerData *peer) {
auto refresh = false;
if (_list && peer == _peer) {
auto newCanSendMessages = _peer->canWrite();
if (newCanSendMessages != _canSendMessages) {
@ -6078,7 +6095,8 @@ void HistoryWidget::fullPeerUpdated(PeerData *peer) {
if (!_canSendMessages) {
cancelReply();
}
updateControlsVisibility();
refreshSilentToggle();
refresh = true;
}
onCheckFieldAutocomplete();
updateReportSpamStatus();
@ -6087,9 +6105,11 @@ void HistoryWidget::fullPeerUpdated(PeerData *peer) {
handlePeerUpdate();
}
if (updateCmdStartShown()) {
updateControlsVisibility();
updateControlsGeometry();
refresh = true;
} else if (!_scroll->isHidden() && _unblock->isHidden() == isBlocked()) {
refresh = true;
}
if (refresh) {
updateControlsVisibility();
updateControlsGeometry();
}
@ -6121,6 +6141,7 @@ void HistoryWidget::handlePeerUpdate() {
if (!_canSendMessages) {
cancelReply();
}
refreshSilentToggle();
resize = true;
}
updateControlsVisibility();

View file

@ -48,6 +48,7 @@ class IconButton;
class HistoryDownButton;
class EmojiButton;
class SendButton;
class SilentToggle;
class FlatButton;
class LinkButton;
class RoundButton;
@ -67,7 +68,6 @@ class TabbedSelector;
} // namespace ChatHelpers
class DragArea;
class SilentToggle;
class SendFilesBox;
class BotKeyboard;
class MessageField;
@ -779,6 +779,7 @@ private:
void updateSendButtonType();
bool showRecordButton() const;
bool showInlineBotCancel() const;
void refreshSilentToggle();
object_ptr<ReportSpamPanel> _reportSpamPanel = { nullptr };
@ -796,7 +797,7 @@ private:
object_ptr<Ui::IconButton> _botKeyboardShow;
object_ptr<Ui::IconButton> _botKeyboardHide;
object_ptr<Ui::IconButton> _botCommandStart;
object_ptr<SilentToggle> _silent;
object_ptr<Ui::SilentToggle> _silent = { nullptr };
bool _cmdStartShown = false;
object_ptr<MessageField> _field;
bool _recording = false;

View file

@ -715,18 +715,15 @@ bool MainWidget::onInlineSwitchChosen(const PeerId &peer, const QString &botAndQ
return true;
}
void MainWidget::cancelForwarding(History *history) {
void MainWidget::cancelForwarding(not_null<History*> history) {
history->setForwardDraft({});
_history->updateForwarding();
}
void MainWidget::finishForwarding(History *history, bool silent) {
if (!history) return;
void MainWidget::finishForwarding(not_null<History*> history) {
auto toForward = history->validateForwardDraft();
if (!toForward.empty()) {
auto options = ApiWrap::SendOptions(history);
options.silent = silent;
Auth().api().forwardMessages(std::move(toForward), options);
if (_history->peer() == history->peer) {
@ -1462,17 +1459,17 @@ Dialogs::IndexedList *MainWidget::contactsNoDialogsList() {
void MainWidget::sendMessage(const MessageToSend &message) {
const auto history = message.history;
const auto peer = history->peer;
auto &textWithTags = message.textWithTags;
auto options = ApiWrap::SendOptions(message.history);
auto options = ApiWrap::SendOptions(history);
options.clearDraft = message.clearDraft;
options.replyTo = message.replyTo;
options.generateLocal = true;
options.silent = message.silent;
options.webPageId = message.webPageId;
Auth().api().sendAction(options);
if (!history->peer->canWrite()) {
if (!peer->canWrite()) {
return;
}
saveRecentHashtags(textWithTags.text);
@ -1485,16 +1482,16 @@ void MainWidget::sendMessage(const MessageToSend &message) {
HistoryItem *lastMessage = nullptr;
while (TextUtilities::CutPart(sending, left, MaxMessageSize)) {
auto newId = FullMsgId(peerToChannel(history->peer->id), clientMsgId());
auto newId = FullMsgId(peerToChannel(peer->id), clientMsgId());
auto randomId = rand_value<uint64>();
TextUtilities::Trim(sending);
App::historyRegRandom(randomId, newId);
App::historyRegSentData(randomId, history->peer->id, sending.text);
App::historyRegSentData(randomId, peer->id, sending.text);
MTPstring msgText(MTP_string(sending.text));
auto flags = NewMessageFlags(history->peer) | MTPDmessage::Flag::f_entities; // unread, out
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_entities;
auto sendFlags = MTPmessages_SendMessage::Flags(0);
if (message.replyTo) {
flags |= MTPDmessage::Flag::f_reply_to_msg_id;
@ -1508,15 +1505,15 @@ void MainWidget::sendMessage(const MessageToSend &message) {
media = MTP_messageMediaWebPage(MTP_webPagePending(MTP_long(page->id), MTP_int(page->pendingTill)));
flags |= MTPDmessage::Flag::f_media;
}
bool channelPost = history->peer->isChannel() && !history->peer->isMegagroup();
bool silentPost = channelPost && message.silent;
bool channelPost = peer->isChannel() && !peer->isMegagroup();
bool silentPost = channelPost && peer->notifySilentPosts();
if (channelPost) {
flags |= MTPDmessage::Flag::f_views;
flags |= MTPDmessage::Flag::f_post;
}
if (!channelPost) {
flags |= MTPDmessage::Flag::f_from_id;
} else if (history->peer->asChannel()->addsSignature()) {
} else if (peer->asChannel()->addsSignature()) {
flags |= MTPDmessage::Flag::f_post_author;
}
if (silentPost) {
@ -1538,7 +1535,7 @@ void MainWidget::sendMessage(const MessageToSend &message) {
MTP_flags(flags),
MTP_int(newId.msg),
MTP_int(messageFromId),
peerToMTP(history->peer->id),
peerToMTP(peer->id),
MTPnullFwdHeader,
MTPint(),
MTP_int(message.replyTo),
@ -1555,7 +1552,7 @@ void MainWidget::sendMessage(const MessageToSend &message) {
history->sendRequestId = MTP::send(
MTPmessages_SendMessage(
MTP_flags(sendFlags),
history->peer->input,
peer->input,
MTP_int(message.replyTo),
msgText,
MTP_long(randomId),
@ -1570,7 +1567,7 @@ void MainWidget::sendMessage(const MessageToSend &message) {
history->lastSentMsg = lastMessage;
finishForwarding(history, message.silent);
finishForwarding(history);
}
void MainWidget::saveRecentHashtags(const QString &text) {

View file

@ -256,7 +256,6 @@ public:
not_null<History*> history;
TextWithTags textWithTags;
MsgId replyTo = 0;
bool silent = false;
WebPageId webPageId = 0;
bool clearDraft = true;
};
@ -300,8 +299,8 @@ public:
void pushReplyReturn(HistoryItem *item);
void cancelForwarding(History *history);
void finishForwarding(History *history, bool silent); // send them
void cancelForwarding(not_null<History*> history);
void finishForwarding(not_null<History*> history);
void mediaMarkRead(not_null<DocumentData*> data);
void mediaMarkRead(const base::flat_set<not_null<HistoryItem*>> &items);

View file

@ -32,6 +32,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "window/window_controller.h"
#include "lang/lang_keys.h"
#include "auth_session.h"
#include "mainwidget.h"
#include "messenger.h"
#include "observer_peer.h"
@ -831,4 +832,68 @@ void UserpicButton::prepareUserpicPixmap() {
: StorageKey();
}
SilentToggle::SilentToggle(QWidget *parent, not_null<ChannelData*> channel)
: IconButton(parent, st::historySilentToggle)
, _channel(channel)
, _checked(_channel->notifySilentPosts()) {
Expects(!_channel->notifySettingsUnknown());
if (_checked) {
refreshIconOverrides();
}
setMouseTracking(true);
}
void SilentToggle::mouseMoveEvent(QMouseEvent *e) {
IconButton::mouseMoveEvent(e);
if (rect().contains(e->pos())) {
Ui::Tooltip::Show(1000, this);
} else {
Ui::Tooltip::Hide();
}
}
void SilentToggle::setChecked(bool checked) {
if (_checked != checked) {
_checked = checked;
refreshIconOverrides();
}
}
void SilentToggle::refreshIconOverrides() {
const auto iconOverride = _checked
? &st::historySilentToggleOn
: nullptr;
const auto iconOverOverride = _checked
? &st::historySilentToggleOnOver
: nullptr;
setIconOverride(iconOverride, iconOverOverride);
}
void SilentToggle::leaveEventHook(QEvent *e) {
IconButton::leaveEventHook(e);
Ui::Tooltip::Hide();
}
void SilentToggle::mouseReleaseEvent(QMouseEvent *e) {
setChecked(!_checked);
IconButton::mouseReleaseEvent(e);
Ui::Tooltip::Show(0, this);
const auto silentState = _checked
? Data::NotifySettings::SilentPostsChange::Silent
: Data::NotifySettings::SilentPostsChange::Notify;
App::main()->updateNotifySettings(
_channel,
Data::NotifySettings::MuteChange::Ignore,
silentState);
}
QString SilentToggle::tooltipText() const {
return lang(_checked ? lng_wont_be_notified : lng_will_be_notified);
}
QPoint SilentToggle::tooltipPos() const {
return QCursor::pos();
}
} // namespace Ui

View file

@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#pragma once
#include "ui/widgets/buttons.h"
#include "ui/widgets/tooltip.h"
#include "styles/style_window.h"
#include "styles/style_widgets.h"
@ -230,4 +231,30 @@ private:
};
class SilentToggle : public Ui::IconButton, public Ui::AbstractTooltipShower {
public:
SilentToggle(QWidget *parent, not_null<ChannelData*> channel);
void setChecked(bool checked);
bool checked() const {
return _checked;
}
// AbstractTooltipShower interface
QString tooltipText() const override;
QPoint tooltipPos() const override;
protected:
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void leaveEventHook(QEvent *e) override;
private:
void refreshIconOverrides();
not_null<ChannelData*> _channel;
bool _checked = false;
};
} // namespace Ui

View file

@ -428,7 +428,6 @@ void Manager::notificationReplied(
auto message = MainWidget::MessageToSend(history);
message.textWithTags = { reply, TextWithTags::Tags() };
message.replyTo = (msgId > 0 && !history->peer->isUser()) ? msgId : 0;
message.silent = false;
message.clearDraft = false;
if (auto main = App::main()) {
main->sendMessage(message);