2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-03 16:15:13 +00:00

Merge remote-tracking branch 'tdesktop/dev' into dev

This commit is contained in:
RadRussianRus
2020-03-28 05:05:42 +03:00
334 changed files with 6707 additions and 1120 deletions

View File

@@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h"
#include "observer_peer.h"
#include "api/api_common.h"
#include "api/api_chat_filters.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_message.h" // GetErrorTextForSending.
@@ -46,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "data/data_scheduled_messages.h"
#include "data/data_histories.h"
#include "data/data_chat_filters.h"
#include "dialogs/dialogs_key.h"
#include "boxes/peers/edit_peer_info_box.h"
#include "facades.h"
@@ -65,6 +67,7 @@ public:
Filler(
not_null<SessionController*> controller,
not_null<PeerData*> peer,
FilterId filterId,
const PeerMenuCallback &addAction,
PeerMenuSource source);
void fill();
@@ -85,6 +88,7 @@ private:
not_null<SessionController*> _controller;
not_null<PeerData*> _peer;
FilterId _filterId = 0;
const PeerMenuCallback &_addAction;
PeerMenuSource _source;
@@ -116,7 +120,7 @@ private:
};
History *FindWastedPin(not_null<Data::Session*> data, Data::Folder *folder) {
const auto &order = data->pinnedChatsOrder(folder);
const auto &order = data->pinnedChatsOrder(folder, FilterId());
for (const auto &pinned : order) {
if (const auto history = pinned.history()) {
if (history->peer->isChat()
@@ -135,27 +139,30 @@ void AddChatMembers(
AddParticipantsBoxController::Start(navigation, chat);
}
bool PinnedLimitReached(Dialogs::Key key) {
bool PinnedLimitReached(Dialogs::Key key, FilterId filterId) {
Expects(key.entry()->folderKnown());
const auto entry = key.entry();
const auto owner = &entry->owner();
const auto folder = entry->folder();
const auto pinnedCount = owner->pinnedChatsCount(folder);
const auto pinnedMax = owner->pinnedChatsLimit(folder);
const auto pinnedCount = owner->pinnedChatsCount(folder, filterId);
const auto pinnedMax = owner->pinnedChatsLimit(folder, filterId);
if (pinnedCount < pinnedMax) {
return false;
}
// Some old chat, that was converted, maybe is still pinned.
if (const auto wasted = FindWastedPin(owner, folder)) {
owner->setChatPinned(wasted, false);
owner->setChatPinned(key, true);
const auto wasted = filterId ? nullptr : FindWastedPin(owner, folder);
if (wasted) {
owner->setChatPinned(wasted, FilterId(), false);
owner->setChatPinned(key, FilterId(), true);
entry->session().api().savePinnedOrder(folder);
} else {
auto errorText = tr::lng_error_pinned_max(
tr::now,
lt_count,
pinnedMax);
const auto errorText = filterId
? tr::lng_filters_error_pinned_max(tr::now)
: tr::lng_error_pinned_max(
tr::now,
lt_count,
pinnedMax);
Ui::show(Box<InformBox>(errorText));
}
return true;
@@ -166,12 +173,12 @@ void TogglePinnedDialog(Dialogs::Key key) {
return;
}
const auto owner = &key.entry()->owner();
const auto isPinned = !key.entry()->isPinnedDialog();
if (isPinned && PinnedLimitReached(key)) {
const auto isPinned = !key.entry()->isPinnedDialog(0);
if (isPinned && PinnedLimitReached(key, 0)) {
return;
}
owner->setChatPinned(key, isPinned);
owner->setChatPinned(key, FilterId(), isPinned);
const auto flags = isPinned
? MTPmessages_ToggleDialogPin::Flag::f_pinned
: MTPmessages_ToggleDialogPin::Flag(0);
@@ -195,13 +202,34 @@ void TogglePinnedDialog(Dialogs::Key key) {
}
}
void TogglePinnedDialog(Dialogs::Key key, FilterId filterId) {
if (!filterId) {
return TogglePinnedDialog(key);
}
const auto owner = &key.entry()->owner();
const auto isPinned = !key.entry()->isPinnedDialog(filterId);
if (isPinned && PinnedLimitReached(key, filterId)) {
return;
}
owner->setChatPinned(key, filterId, isPinned);
Api::SaveNewFilterPinned(&owner->session(), filterId);
if (isPinned) {
if (const auto main = App::main()) {
main->dialogsToUp();
}
}
}
Filler::Filler(
not_null<SessionController*> controller,
not_null<PeerData*> peer,
FilterId filterId,
const PeerMenuCallback &addAction,
PeerMenuSource source)
: _controller(controller)
, _peer(peer)
, _filterId(filterId)
, _addAction(addAction)
, _source(source) {
}
@@ -243,27 +271,29 @@ bool Filler::showTogglePin() {
}
void Filler::addTogglePin() {
auto peer = _peer;
const auto filterId = _filterId;
const auto peer = _peer;
auto isPinned = false;
if (auto history = peer->owner().historyLoaded(peer)) {
isPinned = history->isPinnedDialog();
if (const auto history = peer->owner().historyLoaded(peer)) {
isPinned = history->isPinnedDialog(filterId);
}
auto pinText = [](bool isPinned) {
const auto pinText = [](bool isPinned) {
return isPinned
? tr::lng_context_unpin_from_top(tr::now)
: tr::lng_context_pin_to_top(tr::now);
};
auto pinToggle = [=] {
TogglePinnedDialog(peer->owner().history(peer));
const auto pinToggle = [=] {
TogglePinnedDialog(peer->owner().history(peer), filterId);
};
auto pinAction = _addAction(pinText(isPinned), pinToggle);
const auto pinAction = _addAction(pinText(isPinned), pinToggle);
const auto lifetime = Ui::CreateChild<rpl::lifetime>(pinAction);
Notify::PeerUpdateViewer(
peer,
Notify::PeerUpdate::Flag::ChatPinnedChanged
) | rpl::start_with_next([peer, pinAction, pinText] {
auto isPinned = peer->owner().history(peer)->isPinnedDialog();
) | rpl::start_with_next([=] {
const auto history = peer->owner().history(peer);
const auto isPinned = history->isPinnedDialog(filterId);
pinAction->setText(pinText(isPinned));
}, *lifetime);
}
@@ -1098,9 +1128,10 @@ Fn<void()> DeleteAndLeaveHandler(not_null<PeerData*> peer) {
void FillPeerMenu(
not_null<SessionController*> controller,
not_null<PeerData*> peer,
FilterId filterId,
const PeerMenuCallback &callback,
PeerMenuSource source) {
Filler filler(controller, peer, callback, source);
Filler filler(controller, peer, filterId, callback, source);
filler.fill();
}