Support [inputN|n]otifyBroadcasts setting.

This commit is contained in:
John Preston 2018-11-06 15:10:20 +04:00
parent 75db59a8bb
commit 36b702702b
7 changed files with 58 additions and 11 deletions

View File

@ -1898,6 +1898,7 @@ void ApiWrap::requestNotifySettings(const MTPInputNotifyPeer &peer) {
switch (peer.type()) { switch (peer.type()) {
case mtpc_inputNotifyUsers: return peerFromUser(0); case mtpc_inputNotifyUsers: return peerFromUser(0);
case mtpc_inputNotifyChats: return peerFromChat(0); case mtpc_inputNotifyChats: return peerFromChat(0);
case mtpc_inputNotifyBroadcasts: return peerFromChannel(0);
case mtpc_inputNotifyPeer: { case mtpc_inputNotifyPeer: {
const auto &inner = peer.c_inputNotifyPeer().vpeer; const auto &inner = peer.c_inputNotifyPeer().vpeer;
switch (inner.type()) { switch (inner.type()) {
@ -2274,6 +2275,11 @@ void ApiWrap::notifySettingReceived(
case mtpc_inputNotifyChats: case mtpc_inputNotifyChats:
_session->data().applyNotifySetting(MTP_notifyChats(), settings); _session->data().applyNotifySetting(MTP_notifyChats(), settings);
break; break;
case mtpc_inputNotifyBroadcasts:
_session->data().applyNotifySetting(
MTP_notifyBroadcasts(),
settings);
break;
case mtpc_inputNotifyPeer: { case mtpc_inputNotifyPeer: {
auto &peer = notifyPeer.c_inputNotifyPeer().vpeer; auto &peer = notifyPeer.c_inputNotifyPeer().vpeer;
const auto apply = [&](PeerId peerId) { const auto apply = [&](PeerId peerId) {

View File

@ -1134,15 +1134,24 @@ namespace App {
} }
} }
void enumerateChatsChannels( void enumerateGroups(Fn<void(not_null<PeerData*>)> action) {
Fn<void(not_null<PeerData*>)> action) {
for (const auto &[peerId, peer] : peersData) { for (const auto &[peerId, peer] : peersData) {
if (!peer->isUser()) { if (peer->isChat() || peer->isMegagroup()) {
action(peer.get()); action(peer.get());
} }
} }
} }
void enumerateChannels(Fn<void(not_null<ChannelData*>)> action) {
for (const auto &[peerId, peer] : peersData) {
if (const auto channel = peer->asChannel()) {
if (!channel->isMegagroup()) {
action(channel);
}
}
}
}
PeerData *peerByName(const QString &username) { PeerData *peerByName(const QString &username) {
const auto uname = username.trimmed(); const auto uname = username.trimmed();
for (const auto &[peerId, peer] : peersData) { for (const auto &[peerId, peer] : peersData) {

View File

@ -131,8 +131,8 @@ namespace App {
return channel(channelId, PeerData::FullLoaded); return channel(channelId, PeerData::FullLoaded);
} }
void enumerateUsers(Fn<void(not_null<UserData*>)> action); void enumerateUsers(Fn<void(not_null<UserData*>)> action);
void enumerateChatsChannels( void enumerateGroups(Fn<void(not_null<PeerData*>)> action);
Fn<void(not_null<PeerData*>)> action); void enumerateChannels(Fn<void(not_null<ChannelData*>)> action);
PeerData *peerByName(const QString &username); PeerData *peerByName(const QString &username);
QString peerName(const PeerData *peer, bool forDialogs = false); QString peerName(const PeerData *peer, bool forDialogs = false);

View File

@ -1813,7 +1813,9 @@ void Session::requestNotifySettings(not_null<PeerData*> peer) {
if (defaultNotifySettings(peer).settingsUnknown()) { if (defaultNotifySettings(peer).settingsUnknown()) {
_session->api().requestNotifySettings(peer->isUser() _session->api().requestNotifySettings(peer->isUser()
? MTP_inputNotifyUsers() ? MTP_inputNotifyUsers()
: MTP_inputNotifyChats()); : (peer->isChat() || peer->isMegagroup())
? MTP_inputNotifyChats()
: MTP_inputNotifyBroadcasts());
} }
} }
@ -1840,7 +1842,7 @@ void Session::applyNotifySetting(
if (_defaultChatNotifySettings.change(settings)) { if (_defaultChatNotifySettings.change(settings)) {
_defaultChatNotifyUpdates.fire({}); _defaultChatNotifyUpdates.fire({});
App::enumerateChatsChannels([&](not_null<PeerData*> peer) { App::enumerateGroups([&](not_null<PeerData*> peer) {
if (!peer->notifySettingsUnknown() if (!peer->notifySettingsUnknown()
&& ((!peer->notifyMuteUntil() && ((!peer->notifyMuteUntil()
&& _defaultChatNotifySettings.muteUntil()) && _defaultChatNotifySettings.muteUntil())
@ -1851,6 +1853,21 @@ void Session::applyNotifySetting(
}); });
} }
} break; } break;
case mtpc_notifyBroadcasts: {
if (_defaultBroadcastNotifySettings.change(settings)) {
_defaultBroadcastNotifyUpdates.fire({});
App::enumerateChannels([&](not_null<ChannelData*> channel) {
if (!channel->notifySettingsUnknown()
&& ((!channel->notifyMuteUntil()
&& _defaultBroadcastNotifySettings.muteUntil())
|| (!channel->notifySilentPosts()
&& _defaultBroadcastNotifySettings.silentPosts()))) {
updateNotifySettingsLocal(channel);
}
});
}
} break;
case mtpc_notifyPeer: { case mtpc_notifyPeer: {
const auto &data = notifyPeer.c_notifyPeer(); const auto &data = notifyPeer.c_notifyPeer();
if (const auto peer = App::peerLoaded(peerFromMTP(data.vpeer))) { if (const auto peer = App::peerLoaded(peerFromMTP(data.vpeer))) {
@ -1937,11 +1954,17 @@ rpl::producer<> Session::defaultChatNotifyUpdates() const {
return _defaultChatNotifyUpdates.events(); return _defaultChatNotifyUpdates.events();
} }
rpl::producer<> Session::defaultBroadcastNotifyUpdates() const {
return _defaultBroadcastNotifyUpdates.events();
}
rpl::producer<> Session::defaultNotifyUpdates( rpl::producer<> Session::defaultNotifyUpdates(
not_null<const PeerData*> peer) const { not_null<const PeerData*> peer) const {
return peer->isUser() return peer->isUser()
? defaultUserNotifyUpdates() ? defaultUserNotifyUpdates()
: defaultChatNotifyUpdates(); : (peer->isChat() || peer->isMegagroup())
? defaultChatNotifyUpdates()
: defaultBroadcastNotifyUpdates();
} }
void Session::serviceNotification( void Session::serviceNotification(

View File

@ -416,6 +416,7 @@ public:
bool notifySettingsUnknown(not_null<const PeerData*> peer) const; bool notifySettingsUnknown(not_null<const PeerData*> peer) const;
rpl::producer<> defaultUserNotifyUpdates() const; rpl::producer<> defaultUserNotifyUpdates() const;
rpl::producer<> defaultChatNotifyUpdates() const; rpl::producer<> defaultChatNotifyUpdates() const;
rpl::producer<> defaultBroadcastNotifyUpdates() const;
rpl::producer<> defaultNotifyUpdates( rpl::producer<> defaultNotifyUpdates(
not_null<const PeerData*> peer) const; not_null<const PeerData*> peer) const;
@ -641,8 +642,10 @@ private:
NotifySettings _defaultUserNotifySettings; NotifySettings _defaultUserNotifySettings;
NotifySettings _defaultChatNotifySettings; NotifySettings _defaultChatNotifySettings;
NotifySettings _defaultBroadcastNotifySettings;
rpl::event_stream<> _defaultUserNotifyUpdates; rpl::event_stream<> _defaultUserNotifyUpdates;
rpl::event_stream<> _defaultChatNotifyUpdates; rpl::event_stream<> _defaultChatNotifyUpdates;
rpl::event_stream<> _defaultBroadcastNotifyUpdates;
std::unordered_set<not_null<const PeerData*>> _mutedPeers; std::unordered_set<not_null<const PeerData*>> _mutedPeers;
base::Timer _unmuteByFinishedTimer; base::Timer _unmuteByFinishedTimer;

View File

@ -719,13 +719,17 @@ HistoryWidget::HistoryWidget(
} }
} }
})); }));
rpl::merge( rpl::merge(
Auth().data().defaultUserNotifyUpdates(), Auth().data().defaultUserNotifyUpdates(),
Auth().data().defaultChatNotifyUpdates() Auth().data().defaultChatNotifyUpdates(),
Auth().data().defaultBroadcastNotifyUpdates()
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
updateNotifyControls(); updateNotifyControls();
}, lifetime()); }, lifetime());
subscribe(Auth().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) {
subscribe(Auth().data().queryItemVisibility(), [=](
const Data::Session::ItemVisibilityQuery &query) {
if (_a_show.animating() if (_a_show.animating()
|| _history != query.item->history() || _history != query.item->history()
|| !query.item->mainView() || !isVisible()) { || !query.item->mainView() || !isVisible()) {
@ -735,7 +739,8 @@ HistoryWidget::HistoryWidget(
auto top = _list->itemTop(view); auto top = _list->itemTop(view);
if (top >= 0) { if (top >= 0) {
auto scrollTop = _scroll->scrollTop(); auto scrollTop = _scroll->scrollTop();
if (top + view->height() > scrollTop && top < scrollTop + _scroll->height()) { if (top + view->height() > scrollTop
&& top < scrollTop + _scroll->height()) {
*query.isVisible = true; *query.isVisible = true;
} }
} }

View File

@ -3345,6 +3345,7 @@ void MainWidget::mtpPing() {
void MainWidget::start() { void MainWidget::start() {
Auth().api().requestNotifySettings(MTP_inputNotifyUsers()); Auth().api().requestNotifySettings(MTP_inputNotifyUsers());
Auth().api().requestNotifySettings(MTP_inputNotifyChats()); Auth().api().requestNotifySettings(MTP_inputNotifyChats());
Auth().api().requestNotifySettings(MTP_inputNotifyBroadcasts());
Local::readSavedPeers(); Local::readSavedPeers();
cSetOtherOnline(0); cSetOtherOnline(0);