mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-04 00:25:17 +00:00
New notifications API, defaults for users/chats.
This commit is contained in:
@@ -228,7 +228,6 @@ MainWidget::MainWidget(
|
||||
connect(&_byPtsTimer, SIGNAL(timeout()), this, SLOT(onGetDifferenceTimeByPts()));
|
||||
connect(&_byMinChannelTimer, SIGNAL(timeout()), this, SLOT(getDifference()));
|
||||
connect(&_failDifferenceTimer, SIGNAL(timeout()), this, SLOT(onGetDifferenceTimeAfterFail()));
|
||||
connect(&updateNotifySettingTimer, SIGNAL(timeout()), this, SLOT(onUpdateNotifySettings()));
|
||||
subscribe(Media::Player::Updated(), [this](const AudioMsgId &audioId) {
|
||||
if (audioId.type() != AudioMsgId::Type::Video) {
|
||||
handleAudioUpdate(audioId);
|
||||
@@ -268,7 +267,6 @@ MainWidget::MainWidget(
|
||||
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
|
||||
connect(&_updateMutedTimer, SIGNAL(timeout()), this, SLOT(onUpdateMuted()));
|
||||
connect(&_viewsIncrementTimer, SIGNAL(timeout()), this, SLOT(onViewsIncrement()));
|
||||
|
||||
using Update = Window::Theme::BackgroundUpdate;
|
||||
@@ -715,20 +713,9 @@ void MainWidget::finishForwarding(not_null<History*> history) {
|
||||
dialogsToUp();
|
||||
}
|
||||
|
||||
void MainWidget::updateMutedIn(TimeMs delay) {
|
||||
accumulate_min(delay, 24 * 3600 * 1000LL);
|
||||
if (!_updateMutedTimer.isActive()
|
||||
|| _updateMutedTimer.remainingTime() > delay) {
|
||||
_updateMutedTimer.start(delay);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::onUpdateMuted() {
|
||||
App::updateMuted();
|
||||
}
|
||||
|
||||
bool MainWidget::onSendPaths(const PeerId &peerId) {
|
||||
Expects(peerId != 0);
|
||||
|
||||
auto peer = App::peer(peerId);
|
||||
if (!peer->canWrite()) {
|
||||
Ui::show(Box<InformBox>(lang(lng_forward_send_files_cant)));
|
||||
@@ -1296,7 +1283,8 @@ void MainWidget::sendMessage(const MessageToSend &message) {
|
||||
flags |= MTPDmessage::Flag::f_media;
|
||||
}
|
||||
bool channelPost = peer->isChannel() && !peer->isMegagroup();
|
||||
bool silentPost = channelPost && peer->notifySilentPosts();
|
||||
bool silentPost = channelPost
|
||||
&& Auth().data().notifySilentPosts(peer);
|
||||
if (channelPost) {
|
||||
flags |= MTPDmessage::Flag::f_views;
|
||||
flags |= MTPDmessage::Flag::f_post;
|
||||
@@ -1319,7 +1307,9 @@ void MainWidget::sendMessage(const MessageToSend &message) {
|
||||
history->clearCloudDraft();
|
||||
}
|
||||
auto messageFromId = channelPost ? 0 : Auth().userId();
|
||||
auto messagePostAuthor = channelPost ? (Auth().user()->firstName + ' ' + Auth().user()->lastName) : QString();
|
||||
auto messagePostAuthor = channelPost
|
||||
? App::peerName(Auth().user())
|
||||
: QString();
|
||||
lastMessage = history->addNewMessage(
|
||||
MTP_message(
|
||||
MTP_flags(flags),
|
||||
@@ -3307,22 +3297,6 @@ void MainWidget::searchInChat(Dialogs::Key chat) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::onUpdateNotifySettings() {
|
||||
if (this != App::main()) return;
|
||||
|
||||
while (!updateNotifySettingPeers.empty()) {
|
||||
auto peer = *updateNotifySettingPeers.begin();
|
||||
updateNotifySettingPeers.erase(updateNotifySettingPeers.begin());
|
||||
MTP::send(
|
||||
MTPaccount_UpdateNotifySettings(
|
||||
MTP_inputNotifyPeer(peer->input),
|
||||
peer->notifySerialize()),
|
||||
RPCResponseHandler(),
|
||||
0,
|
||||
updateNotifySettingPeers.empty() ? 0 : 10);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::feedUpdateVector(
|
||||
const MTPVector<MTPUpdate> &updates,
|
||||
bool skipMessageIds) {
|
||||
@@ -3996,62 +3970,6 @@ void MainWidget::startWithSelf(const MTPUserFull &result) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::applyNotifySetting(
|
||||
const MTPNotifyPeer ¬ifyPeer,
|
||||
const MTPPeerNotifySettings &settings,
|
||||
History *history) {
|
||||
if (notifyPeer.type() != mtpc_notifyPeer) {
|
||||
// Ignore those for now, they were not ever used.
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &data = notifyPeer.c_notifyPeer();
|
||||
const auto peer = App::peerLoaded(peerFromMTP(data.vpeer));
|
||||
if (!peer || !peer->notifyChange(settings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateNotifySettingsLocal(peer, history);
|
||||
}
|
||||
|
||||
void MainWidget::updateNotifySettings(
|
||||
not_null<PeerData*> peer,
|
||||
Data::NotifySettings::MuteChange mute,
|
||||
Data::NotifySettings::SilentPostsChange silent,
|
||||
int muteForSeconds) {
|
||||
if (peer->notifyChange(mute, silent, muteForSeconds)) {
|
||||
updateNotifySettingsLocal(peer);
|
||||
updateNotifySettingPeers.insert(peer);
|
||||
updateNotifySettingTimer.start(NotifySettingSaveTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::updateNotifySettingsLocal(
|
||||
not_null<PeerData*> peer,
|
||||
History *history) {
|
||||
if (!history) {
|
||||
history = App::historyLoaded(peer->id);
|
||||
}
|
||||
|
||||
const auto muteFinishesIn = peer->notifyMuteFinishesIn();
|
||||
const auto muted = (muteFinishesIn > 0);
|
||||
if (history && history->changeMute(muted)) {
|
||||
// Notification already sent.
|
||||
} else {
|
||||
Notify::peerUpdatedDelayed(
|
||||
peer,
|
||||
Notify::PeerUpdate::Flag::NotificationsEnabled);
|
||||
}
|
||||
if (muted) {
|
||||
App::regMuted(peer, muteFinishesIn);
|
||||
if (history) {
|
||||
Auth().notifications().clearFromHistory(history);
|
||||
}
|
||||
} else {
|
||||
App::unregMuted(peer);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::incrementSticker(DocumentData *sticker) {
|
||||
if (!sticker || !sticker->sticker()) return;
|
||||
if (sticker->sticker()->set.type() == mtpc_inputStickerSetEmpty) return;
|
||||
@@ -4940,7 +4858,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||
|
||||
case mtpc_updateNotifySettings: {
|
||||
auto &d = update.c_updateNotifySettings();
|
||||
applyNotifySetting(d.vpeer, d.vnotify_settings);
|
||||
Auth().data().applyNotifySetting(d.vpeer, d.vnotify_settings);
|
||||
} break;
|
||||
|
||||
case mtpc_updateDcOptions: {
|
||||
|
Reference in New Issue
Block a user