2017-11-06 18:03:20 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-11-06 18:03:20 +00:00
|
|
|
*/
|
|
|
|
#include "window/window_peer_menu.h"
|
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/mute_settings_box.h"
|
2017-11-07 13:13:41 +00:00
|
|
|
#include "boxes/add_contact_box.h"
|
2017-11-07 11:53:05 +00:00
|
|
|
#include "boxes/report_box.h"
|
2019-06-12 13:26:04 +00:00
|
|
|
#include "boxes/generic_box.h"
|
2018-12-20 16:02:44 +00:00
|
|
|
#include "boxes/create_poll_box.h"
|
2019-01-10 06:26:08 +00:00
|
|
|
#include "boxes/peers/add_participants_box.h"
|
2019-06-10 15:47:22 +00:00
|
|
|
#include "boxes/peers/add_to_contacts_box.h"
|
2017-12-06 10:13:38 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2019-06-12 13:26:04 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
2017-11-06 18:03:20 +00:00
|
|
|
#include "auth_session.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2017-11-30 17:45:36 +00:00
|
|
|
#include "mainwindow.h"
|
2017-11-06 18:03:20 +00:00
|
|
|
#include "observer_peer.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2019-06-12 13:26:04 +00:00
|
|
|
#include "window/window_controller.h"
|
2018-11-20 15:36:36 +00:00
|
|
|
#include "support/support_helper.h"
|
2018-02-16 15:46:24 +00:00
|
|
|
#include "info/info_memento.h"
|
|
|
|
#include "info/info_controller.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
//#include "info/feed/info_feed_channels_controllers.h" // #feed
|
2018-04-09 17:48:29 +00:00
|
|
|
#include "info/profile/info_profile_values.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2018-12-22 21:31:12 +00:00
|
|
|
#include "data/data_poll.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
2019-02-17 11:43:46 +00:00
|
|
|
#include "data/data_drafts.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2019-03-17 10:06:00 +00:00
|
|
|
#include "boxes/peers/edit_peer_info_box.h"
|
2019-04-18 08:28:43 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_window.h" // st::windowMinWidth
|
2017-11-06 18:03:20 +00:00
|
|
|
|
|
|
|
namespace Window {
|
2017-11-07 13:13:41 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-04-25 09:20:20 +00:00
|
|
|
constexpr auto kArchivedToastDuration = crl::time(3000);
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
class Filler {
|
|
|
|
public:
|
|
|
|
Filler(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2017-11-06 18:03:20 +00:00
|
|
|
not_null<PeerData*> peer,
|
2017-11-07 13:13:41 +00:00
|
|
|
const PeerMenuCallback &addAction,
|
2017-11-07 15:12:54 +00:00
|
|
|
PeerMenuSource source);
|
2017-11-06 18:03:20 +00:00
|
|
|
void fill();
|
|
|
|
|
|
|
|
private:
|
2017-11-07 15:12:54 +00:00
|
|
|
bool showInfo();
|
2019-04-25 09:04:30 +00:00
|
|
|
bool showToggleArchived();
|
2019-05-01 13:10:11 +00:00
|
|
|
bool showTogglePin();
|
|
|
|
void addTogglePin();
|
2017-11-06 18:03:20 +00:00
|
|
|
void addInfo();
|
2019-04-25 08:36:31 +00:00
|
|
|
//void addSearch();
|
2018-06-26 18:03:45 +00:00
|
|
|
void addToggleUnreadMark();
|
2019-04-18 08:28:43 +00:00
|
|
|
void addToggleArchive();
|
2017-11-06 18:03:20 +00:00
|
|
|
void addUserActions(not_null<UserData*> user);
|
|
|
|
void addBlockUser(not_null<UserData*> user);
|
|
|
|
void addChatActions(not_null<ChatData*> chat);
|
|
|
|
void addChannelActions(not_null<ChannelData*> channel);
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> _controller;
|
2017-11-06 18:03:20 +00:00
|
|
|
not_null<PeerData*> _peer;
|
2017-11-07 13:13:41 +00:00
|
|
|
const PeerMenuCallback &_addAction;
|
2017-11-07 15:12:54 +00:00
|
|
|
PeerMenuSource _source;
|
2017-11-06 18:03:20 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
class FolderFiller {
|
2018-01-05 15:57:18 +00:00
|
|
|
public:
|
2019-04-15 11:54:03 +00:00
|
|
|
FolderFiller(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2019-04-15 11:54:03 +00:00
|
|
|
not_null<Data::Folder*> folder,
|
2018-01-05 15:57:18 +00:00
|
|
|
const PeerMenuCallback &addAction,
|
|
|
|
PeerMenuSource source);
|
|
|
|
void fill();
|
|
|
|
|
|
|
|
private:
|
2019-05-16 08:39:45 +00:00
|
|
|
void addTogglesForArchive();
|
2019-04-19 08:47:49 +00:00
|
|
|
//bool showInfo();
|
2019-05-01 13:10:11 +00:00
|
|
|
//void addTogglePin();
|
2019-04-19 08:47:49 +00:00
|
|
|
//void addInfo();
|
|
|
|
//void addSearch();
|
|
|
|
//void addNotifications();
|
|
|
|
//void addUngroup();
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> _controller;
|
2019-05-03 10:55:44 +00:00
|
|
|
not_null<Data::Folder*> _folder;
|
|
|
|
const PeerMenuCallback &_addAction;
|
|
|
|
PeerMenuSource _source;
|
2018-01-05 15:57:18 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
History *FindWastedPin(Data::Folder *folder) {
|
|
|
|
const auto &order = Auth().data().pinnedChatsOrder(folder);
|
2019-04-18 08:28:43 +00:00
|
|
|
for (const auto &pinned : order) {
|
2018-01-04 19:54:35 +00:00
|
|
|
if (const auto history = pinned.history()) {
|
|
|
|
if (history->peer->isChat()
|
|
|
|
&& history->peer->asChat()->isDeactivated()
|
2019-04-22 14:22:39 +00:00
|
|
|
&& !history->inChatList()) {
|
2018-01-04 19:54:35 +00:00
|
|
|
return history;
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
void AddChatMembers(not_null<ChatData*> chat) {
|
2019-01-13 13:28:05 +00:00
|
|
|
AddParticipantsBoxController::Start(chat);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedLimitReached(Dialogs::Key key) {
|
2019-04-19 08:47:49 +00:00
|
|
|
Expects(key.entry()->folderKnown());
|
|
|
|
|
|
|
|
const auto folder = key.entry()->folder();
|
2019-04-22 14:22:39 +00:00
|
|
|
const auto pinnedCount = Auth().data().pinnedChatsCount(folder);
|
|
|
|
const auto pinnedMax = Auth().data().pinnedChatsLimit(folder);
|
2018-01-05 15:57:18 +00:00
|
|
|
if (pinnedCount < pinnedMax) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Some old chat, that was converted, maybe is still pinned.
|
2019-04-22 14:22:39 +00:00
|
|
|
if (const auto wasted = FindWastedPin(folder)) {
|
2019-04-19 08:47:49 +00:00
|
|
|
Auth().data().setChatPinned(wasted, false);
|
|
|
|
Auth().data().setChatPinned(key, true);
|
2019-04-22 14:22:39 +00:00
|
|
|
Auth().api().savePinnedOrder(folder);
|
2018-01-05 15:57:18 +00:00
|
|
|
} else {
|
|
|
|
auto errorText = lng_error_pinned_max(
|
|
|
|
lt_count,
|
|
|
|
pinnedMax);
|
|
|
|
Ui::show(Box<InformBox>(errorText));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TogglePinnedDialog(Dialogs::Key key) {
|
2019-04-19 08:47:49 +00:00
|
|
|
if (!key.entry()->folderKnown()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto isPinned = !key.entry()->isPinnedDialog();
|
|
|
|
if (isPinned && PinnedLimitReached(key)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-19 08:47:49 +00:00
|
|
|
Auth().data().setChatPinned(key, isPinned);
|
|
|
|
const auto flags = isPinned
|
|
|
|
? MTPmessages_ToggleDialogPin::Flag::f_pinned
|
|
|
|
: MTPmessages_ToggleDialogPin::Flag(0);
|
|
|
|
if (const auto history = key.history()) {
|
|
|
|
history->session().api().request(MTPmessages_ToggleDialogPin(
|
2018-03-06 17:07:42 +00:00
|
|
|
MTP_flags(flags),
|
2019-04-19 08:47:49 +00:00
|
|
|
MTP_inputDialogPeer(key.history()->peer->input)
|
2019-05-02 13:26:47 +00:00
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
Auth().data().notifyPinnedDialogsOrderUpdated();
|
|
|
|
}).send();
|
2019-04-19 08:47:49 +00:00
|
|
|
} else if (const auto folder = key.folder()) {
|
|
|
|
folder->session().api().request(MTPmessages_ToggleDialogPin(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_inputDialogPeerFolder(MTP_int(folder->id()))
|
|
|
|
)).send();
|
2018-03-06 17:07:42 +00:00
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
if (isPinned) {
|
|
|
|
if (const auto main = App::main()) {
|
|
|
|
main->dialogsToUp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
Filler::Filler(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2017-11-06 18:03:20 +00:00
|
|
|
not_null<PeerData*> peer,
|
2017-11-07 13:13:41 +00:00
|
|
|
const PeerMenuCallback &addAction,
|
2017-11-07 15:12:54 +00:00
|
|
|
PeerMenuSource source)
|
2017-11-07 11:53:05 +00:00
|
|
|
: _controller(controller)
|
|
|
|
, _peer(peer)
|
2017-11-07 13:13:41 +00:00
|
|
|
, _addAction(addAction)
|
2017-11-07 15:12:54 +00:00
|
|
|
, _source(source) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Filler::showInfo() {
|
2019-06-17 12:28:16 +00:00
|
|
|
if (_source == PeerMenuSource::Profile || _peer->isSelf()) {
|
2017-11-07 15:12:54 +00:00
|
|
|
return false;
|
2018-01-22 16:42:25 +00:00
|
|
|
} else if (_controller->activeChatCurrent().peer() != _peer) {
|
2017-11-07 15:12:54 +00:00
|
|
|
return true;
|
|
|
|
} else if (!Adaptive::ThreeColumn()) {
|
|
|
|
return true;
|
|
|
|
} else if (
|
2018-01-04 10:22:53 +00:00
|
|
|
!Auth().settings().thirdSectionInfoEnabled() &&
|
|
|
|
!Auth().settings().tabbedReplacedWithInfo()) {
|
2017-11-07 15:12:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 09:04:30 +00:00
|
|
|
bool Filler::showToggleArchived() {
|
|
|
|
if (_source != PeerMenuSource::ChatsList) {
|
|
|
|
return false;
|
2019-05-01 09:41:56 +00:00
|
|
|
}
|
|
|
|
const auto history = _peer->owner().historyLoaded(_peer);
|
|
|
|
if (history && history->useProxyPromotion()) {
|
|
|
|
return false;
|
2019-05-01 11:54:26 +00:00
|
|
|
} else if (!_peer->isNotificationsUser() && !_peer->isSelf()) {
|
2019-04-25 09:04:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-05-01 09:41:56 +00:00
|
|
|
return history && (history->folder() != nullptr);
|
2019-04-25 09:04:30 +00:00
|
|
|
}
|
|
|
|
|
2019-05-01 13:10:11 +00:00
|
|
|
bool Filler::showTogglePin() {
|
|
|
|
if (_source != PeerMenuSource::ChatsList) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto history = _peer->owner().historyLoaded(_peer);
|
|
|
|
return history && !history->fixedOnTopIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addTogglePin() {
|
2017-11-06 18:03:20 +00:00
|
|
|
auto peer = _peer;
|
|
|
|
auto isPinned = false;
|
2019-01-18 12:27:37 +00:00
|
|
|
if (auto history = peer->owner().historyLoaded(peer)) {
|
2017-11-06 18:03:20 +00:00
|
|
|
isPinned = history->isPinnedDialog();
|
|
|
|
}
|
|
|
|
auto pinText = [](bool isPinned) {
|
|
|
|
return lang(isPinned
|
|
|
|
? lng_context_unpin_from_top
|
|
|
|
: lng_context_pin_to_top);
|
|
|
|
};
|
2018-01-05 15:57:18 +00:00
|
|
|
auto pinToggle = [=] {
|
2019-01-18 12:27:37 +00:00
|
|
|
TogglePinnedDialog(peer->owner().history(peer));
|
2017-11-06 18:03:20 +00:00
|
|
|
};
|
2017-11-07 13:13:41 +00:00
|
|
|
auto pinAction = _addAction(pinText(isPinned), pinToggle);
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto lifetime = Ui::CreateChild<rpl::lifetime>(pinAction);
|
|
|
|
Notify::PeerUpdateViewer(
|
2017-11-06 18:03:20 +00:00
|
|
|
peer,
|
2018-10-31 11:29:14 +00:00
|
|
|
Notify::PeerUpdate::Flag::ChatPinnedChanged
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::start_with_next([peer, pinAction, pinText] {
|
2019-01-18 12:27:37 +00:00
|
|
|
auto isPinned = peer->owner().history(peer)->isPinnedDialog();
|
2017-12-22 07:05:20 +00:00
|
|
|
pinAction->setText(pinText(isPinned));
|
2018-11-21 10:09:46 +00:00
|
|
|
}, *lifetime);
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addInfo() {
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto controller = _controller;
|
|
|
|
const auto peer = _peer;
|
|
|
|
const auto infoKey = (peer->isChat() || peer->isMegagroup())
|
2017-11-06 18:03:20 +00:00
|
|
|
? lng_context_view_group
|
2017-11-07 11:53:05 +00:00
|
|
|
: (peer->isUser()
|
2017-11-06 18:03:20 +00:00
|
|
|
? lng_context_view_profile
|
|
|
|
: lng_context_view_channel);
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(lang(infoKey), [=] {
|
2017-11-07 11:53:05 +00:00
|
|
|
controller->showPeerInfo(peer);
|
2017-11-06 18:03:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-25 08:36:31 +00:00
|
|
|
//void Filler::addSearch() {
|
|
|
|
// _addAction(lang(lng_profile_search_messages), [peer = _peer] {
|
|
|
|
// App::main()->searchInChat(peer->owner().history(peer));
|
|
|
|
// });
|
|
|
|
//}
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2018-06-26 18:03:45 +00:00
|
|
|
void Filler::addToggleUnreadMark() {
|
|
|
|
const auto peer = _peer;
|
|
|
|
const auto isUnread = [](not_null<PeerData*> peer) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (const auto history = peer->owner().historyLoaded(peer)) {
|
2018-06-26 18:03:45 +00:00
|
|
|
return (history->chatListUnreadCount() > 0)
|
|
|
|
|| (history->chatListUnreadMark());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
const auto label = [=](not_null<PeerData*> peer) {
|
|
|
|
return lang(isUnread(peer)
|
|
|
|
? lng_context_mark_read
|
|
|
|
: lng_context_mark_unread);
|
|
|
|
};
|
|
|
|
auto action = _addAction(label(peer), [=] {
|
|
|
|
const auto markAsRead = isUnread(peer);
|
|
|
|
const auto handle = [&](not_null<History*> history) {
|
|
|
|
if (markAsRead) {
|
|
|
|
Auth().api().readServerHistory(history);
|
|
|
|
} else {
|
|
|
|
Auth().api().changeDialogUnreadMark(history, !markAsRead);
|
|
|
|
}
|
|
|
|
};
|
2019-01-18 12:27:37 +00:00
|
|
|
const auto history = peer->owner().history(peer);
|
2018-06-26 18:03:45 +00:00
|
|
|
handle(history);
|
|
|
|
if (markAsRead) {
|
|
|
|
if (const auto migrated = history->migrateSibling()) {
|
|
|
|
handle(migrated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto lifetime = Ui::CreateChild<rpl::lifetime>(action);
|
|
|
|
Notify::PeerUpdateViewer(
|
2018-06-26 18:03:45 +00:00
|
|
|
_peer,
|
|
|
|
Notify::PeerUpdate::Flag::UnreadViewChanged
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
action->setText(label(peer));
|
2018-11-21 10:09:46 +00:00
|
|
|
}, *lifetime);
|
2018-06-26 18:03:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
void Filler::addToggleArchive() {
|
|
|
|
const auto peer = _peer;
|
|
|
|
const auto archived = [&] {
|
|
|
|
const auto history = peer->owner().historyLoaded(peer);
|
|
|
|
return history && history->folder();
|
|
|
|
}();
|
|
|
|
const auto toggle = [=] {
|
|
|
|
ToggleHistoryArchived(
|
|
|
|
peer->owner().history(peer),
|
|
|
|
!archived);
|
|
|
|
};
|
|
|
|
_addAction(
|
|
|
|
lang(archived ? lng_archived_remove : lng_archived_add),
|
|
|
|
toggle);
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
void Filler::addBlockUser(not_null<UserData*> user) {
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto window = &_controller->window()->controller();
|
|
|
|
const auto blockText = [](not_null<UserData*> user) {
|
2017-11-06 18:03:20 +00:00
|
|
|
return lang(user->isBlocked()
|
2019-03-12 10:36:33 +00:00
|
|
|
? ((user->isBot() && !user->isSupport())
|
2018-12-04 11:46:07 +00:00
|
|
|
? lng_profile_restart_bot
|
2017-11-06 18:03:20 +00:00
|
|
|
: lng_profile_unblock_user)
|
2019-03-12 10:36:33 +00:00
|
|
|
: ((user->isBot() && !user->isSupport())
|
2017-11-06 18:03:20 +00:00
|
|
|
? lng_profile_block_bot
|
|
|
|
: lng_profile_block_user));
|
|
|
|
};
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto blockAction = _addAction(blockText(user), [=] {
|
2018-12-04 11:46:07 +00:00
|
|
|
if (user->isBlocked()) {
|
2019-06-12 13:26:04 +00:00
|
|
|
user->session().api().unblockUser(user);
|
|
|
|
} else if (user->isBot()) {
|
|
|
|
user->session().api().blockUser(user);
|
2017-11-06 18:03:20 +00:00
|
|
|
} else {
|
2019-06-12 13:26:04 +00:00
|
|
|
window->show(Box(PeerMenuBlockUserBox, user, window));
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto lifetime = Ui::CreateChild<rpl::lifetime>(blockAction);
|
|
|
|
Notify::PeerUpdateViewer(
|
2017-11-06 18:03:20 +00:00
|
|
|
_peer,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::UserIsBlocked
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
blockAction->setText(blockText(user));
|
2018-11-21 10:09:46 +00:00
|
|
|
}, *lifetime);
|
2017-11-06 18:03:20 +00:00
|
|
|
|
|
|
|
if (user->blockStatus() == UserData::BlockStatus::Unknown) {
|
|
|
|
Auth().api().requestFullPeer(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addUserActions(not_null<UserData*> user) {
|
2017-11-07 15:12:54 +00:00
|
|
|
if (_source != PeerMenuSource::ChatsList) {
|
2018-11-20 15:36:36 +00:00
|
|
|
if (Auth().supportMode()) {
|
|
|
|
_addAction("Edit support info", [=] {
|
|
|
|
Auth().supportHelper().editInfo(user);
|
|
|
|
});
|
|
|
|
}
|
2019-06-10 14:58:45 +00:00
|
|
|
if (!user->isContact() && !user->isSelf() && !user->isBot()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_info_add_as_contact),
|
|
|
|
[=] { PeerMenuAddContact(user); });
|
|
|
|
}
|
|
|
|
if (user->canShareThisContact()) {
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_info_share_contact),
|
2019-06-10 14:58:45 +00:00
|
|
|
[=] { PeerMenuShareContactBox(user); });
|
|
|
|
}
|
|
|
|
if (user->isContact() && !user->isSelf()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_info_edit_contact),
|
|
|
|
[=] { Ui::show(Box<AddContactBox>(user)); });
|
|
|
|
_addAction(
|
|
|
|
lang(lng_info_delete_contact),
|
|
|
|
[=] { PeerMenuDeleteContact(user); });
|
|
|
|
}
|
|
|
|
if (user->isBot() && !user->botInfo->cantJoinGroups) {
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_profile_invite_to_group),
|
2019-06-10 14:58:45 +00:00
|
|
|
[=] { AddBotToGroupBoxController::Start(user); });
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2019-03-21 18:14:48 +00:00
|
|
|
if (user->canExportChatHistory()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_profile_export_chat),
|
|
|
|
[=] { PeerMenuExportChat(user); });
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2017-11-06 18:03:20 +00:00
|
|
|
lang(lng_profile_delete_conversation),
|
|
|
|
DeleteAndLeaveHandler(user));
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2017-11-06 18:03:20 +00:00
|
|
|
lang(lng_profile_clear_history),
|
|
|
|
ClearHistoryHandler(user));
|
2019-04-25 08:36:31 +00:00
|
|
|
if (!user->isInaccessible()
|
|
|
|
&& user != Auth().user()
|
|
|
|
&& _source != PeerMenuSource::ChatsList) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addBlockUser(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addChatActions(not_null<ChatData*> chat) {
|
2017-11-07 15:12:54 +00:00
|
|
|
if (_source != PeerMenuSource::ChatsList) {
|
2019-03-17 10:06:00 +00:00
|
|
|
if (EditPeerInfoBox::Available(chat)) {
|
2019-01-07 12:55:49 +00:00
|
|
|
const auto text = lang(lng_manage_group_title);
|
|
|
|
_addAction(text, [=] {
|
2019-06-06 10:21:40 +00:00
|
|
|
App::wnd()->sessionController()->showEditPeerBox(chat);
|
2019-01-07 12:55:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (chat->canAddMembers()) {
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_profile_add_participant),
|
|
|
|
[chat] { AddChatMembers(chat); });
|
|
|
|
}
|
2019-01-10 06:26:08 +00:00
|
|
|
if (chat->canSendPolls()) {
|
2018-12-20 16:02:44 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_polls_create),
|
|
|
|
[=] { PeerMenuCreatePoll(chat); });
|
|
|
|
}
|
2019-03-21 18:14:48 +00:00
|
|
|
if (chat->canExportChatHistory()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_profile_export_chat),
|
|
|
|
[=] { PeerMenuExportChat(chat); });
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
_addAction(
|
2017-11-06 18:03:20 +00:00
|
|
|
lang(lng_profile_clear_and_exit),
|
|
|
|
DeleteAndLeaveHandler(_peer));
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2017-11-06 18:03:20 +00:00
|
|
|
lang(lng_profile_clear_history),
|
|
|
|
ClearHistoryHandler(_peer));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addChannelActions(not_null<ChannelData*> channel) {
|
2017-11-21 16:38:17 +00:00
|
|
|
auto isGroup = channel->isMegagroup();
|
2019-04-15 11:54:03 +00:00
|
|
|
//if (!isGroup) { // #feed
|
|
|
|
// const auto feed = channel->feed();
|
|
|
|
// const auto grouped = (feed != nullptr);
|
|
|
|
// if (!grouped || feed->channels().size() > 1) {
|
|
|
|
// _addAction( // #feed
|
|
|
|
// lang(grouped ? lng_feed_ungroup : lng_feed_group),
|
|
|
|
// [=] { ToggleChannelGrouping(channel, !grouped); });
|
|
|
|
// }
|
|
|
|
//}
|
2017-11-07 15:12:54 +00:00
|
|
|
if (_source != PeerMenuSource::ChatsList) {
|
2019-03-17 10:06:00 +00:00
|
|
|
if (EditPeerInfoBox::Available(channel)) {
|
2019-01-07 12:55:49 +00:00
|
|
|
const auto text = lang(isGroup
|
2017-11-08 16:45:30 +00:00
|
|
|
? lng_manage_group_title
|
|
|
|
: lng_manage_channel_title);
|
2019-06-06 10:21:40 +00:00
|
|
|
_addAction(text, [=] {
|
|
|
|
App::wnd()->sessionController()->showEditPeerBox(channel);
|
2017-11-08 16:45:30 +00:00
|
|
|
});
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
if (channel->canAddMembers()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_channel_add_members),
|
2017-11-19 14:41:52 +00:00
|
|
|
[channel] { PeerMenuAddChannelMembers(channel); });
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2019-01-10 06:26:08 +00:00
|
|
|
if (channel->canSendPolls()) {
|
2018-12-20 16:02:44 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_polls_create),
|
|
|
|
[=] { PeerMenuCreatePoll(channel); });
|
|
|
|
}
|
2019-03-21 18:14:48 +00:00
|
|
|
if (channel->canExportChatHistory()) {
|
|
|
|
_addAction(
|
|
|
|
lang(isGroup
|
|
|
|
? lng_profile_export_chat
|
|
|
|
: lng_profile_export_channel),
|
|
|
|
[=] { PeerMenuExportChat(channel); });
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2017-11-07 11:53:05 +00:00
|
|
|
if (channel->amIn()) {
|
2017-11-21 16:38:17 +00:00
|
|
|
if (isGroup && !channel->isPublic()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_profile_clear_history),
|
|
|
|
ClearHistoryHandler(channel));
|
|
|
|
}
|
|
|
|
auto text = lang(isGroup
|
2017-11-06 18:03:20 +00:00
|
|
|
? lng_profile_leave_group
|
|
|
|
: lng_profile_leave_channel);
|
2017-11-21 16:38:17 +00:00
|
|
|
_addAction(text, DeleteAndLeaveHandler(channel));
|
2017-11-07 13:13:41 +00:00
|
|
|
} else {
|
2017-11-21 16:38:17 +00:00
|
|
|
auto text = lang(isGroup
|
2017-11-07 13:13:41 +00:00
|
|
|
? lng_profile_join_group
|
|
|
|
: lng_profile_join_channel);
|
|
|
|
_addAction(
|
2017-11-21 16:38:17 +00:00
|
|
|
text,
|
2017-11-07 13:13:41 +00:00
|
|
|
[channel] { Auth().api().joinChannel(channel); });
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2017-11-07 15:12:54 +00:00
|
|
|
if (_source != PeerMenuSource::ChatsList) {
|
2017-11-07 11:53:05 +00:00
|
|
|
auto needReport = !channel->amCreator()
|
2017-11-21 16:38:17 +00:00
|
|
|
&& (!isGroup || channel->isPublic());
|
2017-11-07 11:53:05 +00:00
|
|
|
if (needReport) {
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(lang(lng_profile_report), [channel] {
|
2017-11-07 11:53:05 +00:00
|
|
|
Ui::show(Box<ReportBox>(channel));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::fill() {
|
2019-05-01 13:10:11 +00:00
|
|
|
if (showToggleArchived()) {
|
|
|
|
addToggleArchive();
|
|
|
|
}
|
|
|
|
if (showTogglePin()) {
|
|
|
|
addTogglePin();
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2017-11-07 15:12:54 +00:00
|
|
|
if (showInfo()) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addInfo();
|
|
|
|
}
|
2017-12-05 14:07:01 +00:00
|
|
|
if (_source != PeerMenuSource::Profile && !_peer->isSelf()) {
|
2018-02-12 11:10:40 +00:00
|
|
|
PeerMenuAddMuteAction(_peer, _addAction);
|
2017-11-07 15:12:54 +00:00
|
|
|
}
|
|
|
|
if (_source == PeerMenuSource::ChatsList) {
|
2019-04-25 08:36:31 +00:00
|
|
|
//addSearch();
|
2018-06-26 18:03:45 +00:00
|
|
|
addToggleUnreadMark();
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 16:11:00 +00:00
|
|
|
if (const auto user = _peer->asUser()) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addUserActions(user);
|
2018-02-13 16:11:00 +00:00
|
|
|
} else if (const auto chat = _peer->asChat()) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addChatActions(chat);
|
2018-02-13 16:11:00 +00:00
|
|
|
} else if (const auto channel = _peer->asChannel()) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addChannelActions(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
FolderFiller::FolderFiller(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2019-04-15 11:54:03 +00:00
|
|
|
not_null<Data::Folder*> folder,
|
2018-01-05 15:57:18 +00:00
|
|
|
const PeerMenuCallback &addAction,
|
2019-05-03 10:55:44 +00:00
|
|
|
PeerMenuSource source)
|
|
|
|
: _controller(controller)
|
|
|
|
, _folder(folder)
|
|
|
|
, _addAction(addAction)
|
|
|
|
, _source(source) {
|
2018-02-16 15:46:24 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 10:55:44 +00:00
|
|
|
void FolderFiller::fill() {
|
|
|
|
if (_source == PeerMenuSource::ChatsList) {
|
2019-05-16 08:39:45 +00:00
|
|
|
addTogglesForArchive();
|
2019-05-03 10:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 08:39:45 +00:00
|
|
|
void FolderFiller::addTogglesForArchive() {
|
2019-05-03 10:55:44 +00:00
|
|
|
if (_folder->id() != Data::Folder::kId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto controller = _controller;
|
|
|
|
const auto hidden = controller->session().settings().archiveCollapsed();
|
|
|
|
const auto text = lang(hidden
|
|
|
|
? lng_context_archive_expand
|
|
|
|
: lng_context_archive_collapse);
|
|
|
|
_addAction(text, [=] {
|
|
|
|
controller->session().settings().setArchiveCollapsed(!hidden);
|
|
|
|
controller->session().saveSettingsDelayed();
|
|
|
|
});
|
2019-05-16 08:39:45 +00:00
|
|
|
|
|
|
|
_addAction(lang(lng_context_archive_to_menu), [=] {
|
|
|
|
Ui::Toast::Config toast;
|
|
|
|
toast.text = lang(lng_context_archive_to_menu_info);
|
|
|
|
toast.maxWidth = st::boxWideWidth;
|
|
|
|
toast.durationMs = kArchivedToastDuration;
|
|
|
|
Ui::Toast::Show(toast);
|
|
|
|
|
|
|
|
controller->session().settings().setArchiveInMainMenu(
|
|
|
|
!controller->session().settings().archiveInMainMenu());
|
|
|
|
controller->session().saveSettingsDelayed();
|
|
|
|
});
|
2018-02-18 14:00:14 +00:00
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//
|
|
|
|
//void FolderFiller::addInfo() {
|
|
|
|
// auto controller = _controller;
|
|
|
|
// auto feed = _feed;
|
|
|
|
// _addAction(lang(lng_context_view_feed_info), [=] {
|
|
|
|
// controller->showSection(Info::Memento(
|
|
|
|
// feed,
|
|
|
|
// Info::Section(Info::Section::Type::Profile)));
|
|
|
|
// });
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void FolderFiller::addNotifications() {
|
|
|
|
// const auto feed = _feed;
|
|
|
|
// _addAction(lang(lng_feed_notifications), [=] {
|
|
|
|
// Info::FeedProfile::NotificationsController::Start(feed);
|
|
|
|
// });
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void FolderFiller::addSearch() {
|
|
|
|
// const auto feed = _feed;
|
|
|
|
// _addAction(lang(lng_profile_search_messages), [=] {
|
|
|
|
// App::main()->searchInChat(feed);
|
|
|
|
// });
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void FolderFiller::addUngroup() {
|
|
|
|
// const auto feed = _feed;
|
|
|
|
// //_addAction(lang(lng_feed_ungroup_all), [=] { // #feed
|
|
|
|
// // PeerMenuUngroupFeed(feed);
|
|
|
|
// //});
|
|
|
|
//}
|
2018-02-18 14:00:14 +00:00
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-07-23 13:11:56 +00:00
|
|
|
void PeerMenuExportChat(not_null<PeerData*> peer) {
|
|
|
|
Auth().data().startExport(peer);
|
|
|
|
}
|
|
|
|
|
2017-11-07 13:13:41 +00:00
|
|
|
void PeerMenuDeleteContact(not_null<UserData*> user) {
|
2019-03-21 12:07:32 +00:00
|
|
|
const auto text = lng_sure_delete_contact(
|
2017-11-07 13:13:41 +00:00
|
|
|
lt_contact,
|
|
|
|
App::peerName(user));
|
2019-03-21 12:07:32 +00:00
|
|
|
const auto deleteSure = [=] {
|
2017-11-07 13:13:41 +00:00
|
|
|
Ui::hideLayer();
|
2019-06-06 15:42:15 +00:00
|
|
|
user->session().api().request(MTPcontacts_DeleteContacts(
|
|
|
|
MTP_vector<MTPInputUser>(1, user->inputUser)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
user->session().api().applyUpdates(result);
|
2019-03-21 12:07:32 +00:00
|
|
|
}).send();
|
2017-11-07 13:13:41 +00:00
|
|
|
};
|
2019-03-21 12:07:32 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(
|
2017-11-07 13:13:41 +00:00
|
|
|
text,
|
|
|
|
lang(lng_box_delete),
|
2019-03-21 12:07:32 +00:00
|
|
|
deleteSure));
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerMenuAddContact(not_null<UserData*> user) {
|
2019-06-10 15:47:22 +00:00
|
|
|
Ui::show(Box<AddToContactsBox>(&App::wnd()->controller(), user));
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerMenuShareContactBox(not_null<UserData*> user) {
|
2017-12-07 13:02:24 +00:00
|
|
|
const auto weak = std::make_shared<QPointer<PeerListBox>>();
|
|
|
|
auto callback = [=](not_null<PeerData*> peer) {
|
2017-11-07 13:13:41 +00:00
|
|
|
if (!peer->canWrite()) {
|
|
|
|
Ui::show(Box<InformBox>(
|
|
|
|
lang(lng_forward_share_cant)),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
return;
|
2017-12-07 08:56:10 +00:00
|
|
|
} else if (peer->isSelf()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
|
2017-12-07 13:02:24 +00:00
|
|
|
Auth().api().shareContact(user, options);
|
2017-12-07 08:56:10 +00:00
|
|
|
Ui::Toast::Show(lang(lng_share_done));
|
2017-12-07 13:02:24 +00:00
|
|
|
if (auto strong = *weak) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
2017-12-07 08:56:10 +00:00
|
|
|
return;
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
auto recipient = peer->isUser()
|
|
|
|
? peer->name
|
|
|
|
: '\xAB' + peer->name + '\xBB';
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
|
|
|
lng_forward_share_contact(lt_recipient, recipient),
|
|
|
|
lang(lng_forward_send),
|
|
|
|
[peer, user] {
|
2019-01-18 12:27:37 +00:00
|
|
|
const auto history = peer->owner().history(peer);
|
2017-12-07 13:02:24 +00:00
|
|
|
Ui::showPeerHistory(history, ShowAtTheEndMsgId);
|
|
|
|
auto options = ApiWrap::SendOptions(history);
|
|
|
|
Auth().api().shareContact(user, options);
|
2017-11-07 13:13:41 +00:00
|
|
|
}), LayerOption::KeepOther);
|
|
|
|
};
|
2017-12-07 13:02:24 +00:00
|
|
|
*weak = Ui::show(Box<PeerListBox>(
|
2017-11-07 13:13:41 +00:00
|
|
|
std::make_unique<ChooseRecipientBoxController>(std::move(callback)),
|
|
|
|
[](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(langFactory(lng_cancel), [box] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2018-12-20 16:02:44 +00:00
|
|
|
void PeerMenuCreatePoll(not_null<PeerData*> peer) {
|
|
|
|
const auto box = Ui::show(Box<CreatePollBox>());
|
2018-12-23 16:47:00 +00:00
|
|
|
const auto lock = box->lifetime().make_state<bool>(false);
|
2018-12-20 16:02:44 +00:00
|
|
|
box->submitRequests(
|
|
|
|
) | rpl::start_with_next([=](const PollData &result) {
|
2018-12-23 16:47:00 +00:00
|
|
|
if (std::exchange(*lock, true)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-17 11:43:46 +00:00
|
|
|
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
|
|
|
|
if (const auto id = App::main()->currentReplyToIdFor(options.history)) {
|
|
|
|
options.replyTo = id;
|
|
|
|
}
|
|
|
|
if (const auto localDraft = options.history->localDraft()) {
|
|
|
|
options.clearDraft = localDraft->textWithTags.text.isEmpty();
|
|
|
|
}
|
|
|
|
|
2018-12-20 16:02:44 +00:00
|
|
|
Auth().api().createPoll(result, options, crl::guard(box, [=] {
|
|
|
|
box->closeBox();
|
|
|
|
}), crl::guard(box, [=](const RPCError &error) {
|
2018-12-23 16:47:00 +00:00
|
|
|
*lock = false;
|
2018-12-20 16:02:44 +00:00
|
|
|
box->submitFailed(lang(lng_attach_failed));
|
|
|
|
}));
|
|
|
|
}, box->lifetime());
|
|
|
|
}
|
|
|
|
|
2019-06-12 13:26:04 +00:00
|
|
|
void PeerMenuBlockUserBox(
|
|
|
|
not_null<GenericBox*> box,
|
|
|
|
not_null<UserData*> user,
|
|
|
|
not_null<Window::Controller*> window) {
|
|
|
|
using Flag = MTPDpeerSettings::Flag;
|
|
|
|
const auto settings = user->settings().value_or(Flag(0));
|
|
|
|
|
|
|
|
const auto name = user->shortName();
|
|
|
|
|
|
|
|
box->addRow(object_ptr<Ui::FlatLabel>(
|
|
|
|
box,
|
|
|
|
rpl::single(
|
|
|
|
lng_blocked_list_confirm_text__generic<TextWithEntities>(
|
|
|
|
lt_name,
|
|
|
|
Ui::Text::Bold(name))),
|
|
|
|
st::blockUserConfirmation));
|
|
|
|
|
|
|
|
box->addSkip(st::boxMediumSkip);
|
|
|
|
|
|
|
|
const auto report = (settings & Flag::f_report_spam)
|
|
|
|
? box->addRow(object_ptr<Ui::Checkbox>(
|
|
|
|
box,
|
|
|
|
lang(lng_report_spam),
|
|
|
|
true,
|
|
|
|
st::defaultBoxCheckbox))
|
|
|
|
: nullptr;
|
|
|
|
|
|
|
|
if (report) {
|
|
|
|
box->addSkip(st::boxMediumSkip);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto clear = box->addRow(object_ptr<Ui::Checkbox>(
|
|
|
|
box,
|
|
|
|
lang(lng_blocked_list_confirm_clear),
|
|
|
|
true,
|
|
|
|
st::defaultBoxCheckbox));
|
|
|
|
|
|
|
|
box->addSkip(st::boxLittleSkip);
|
|
|
|
|
|
|
|
box->setTitle([=] {
|
|
|
|
return lng_blocked_list_confirm_title(lt_name, name);
|
|
|
|
});
|
|
|
|
|
|
|
|
box->addButton(langFactory(lng_blocked_list_confirm_ok), [=] {
|
|
|
|
const auto reportChecked = report && report->checked();
|
|
|
|
const auto clearChecked = clear->checked();
|
|
|
|
|
|
|
|
box->closeBox();
|
|
|
|
|
|
|
|
user->session().api().blockUser(user);
|
|
|
|
if (reportChecked) {
|
|
|
|
user->session().api().request(MTPmessages_ReportSpam(
|
|
|
|
user->input
|
|
|
|
)).send();
|
|
|
|
}
|
|
|
|
if (clearChecked) {
|
|
|
|
crl::on_main(&user->session(), [=] {
|
|
|
|
user->session().api().deleteConversation(user, false);
|
|
|
|
});
|
|
|
|
window->sessionController()->showBackFromStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::Toast::Show(
|
|
|
|
lng_new_contact_block_done(lt_user, user->shortName()));
|
|
|
|
}, st::attentionBoxButton);
|
|
|
|
|
|
|
|
box->addButton(langFactory(lng_cancel), [=] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-09 15:13:06 +00:00
|
|
|
QPointer<Ui::RpWidget> ShowForwardMessagesBox(
|
2017-12-06 10:13:38 +00:00
|
|
|
MessageIdsList &&items,
|
2018-06-04 15:35:11 +00:00
|
|
|
FnMut<void()> &&successCallback) {
|
2017-12-07 13:02:24 +00:00
|
|
|
const auto weak = std::make_shared<QPointer<PeerListBox>>();
|
2017-12-06 10:13:38 +00:00
|
|
|
auto callback = [
|
|
|
|
ids = std::move(items),
|
|
|
|
callback = std::move(successCallback),
|
|
|
|
weak
|
|
|
|
](not_null<PeerData*> peer) mutable {
|
|
|
|
if (peer->isSelf()) {
|
2017-12-06 13:56:40 +00:00
|
|
|
auto items = Auth().data().idsToItems(ids);
|
|
|
|
if (!items.empty()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
|
2017-12-06 13:56:40 +00:00
|
|
|
options.generateLocal = false;
|
|
|
|
Auth().api().forwardMessages(std::move(items), options, [] {
|
|
|
|
Ui::Toast::Show(lang(lng_share_done));
|
|
|
|
});
|
|
|
|
}
|
2017-12-06 10:13:38 +00:00
|
|
|
} else {
|
|
|
|
App::main()->setForwardDraft(peer->id, std::move(ids));
|
|
|
|
}
|
|
|
|
if (const auto strong = *weak) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
auto initBox = [](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(langFactory(lng_cancel), [box] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
*weak = Ui::show(Box<PeerListBox>(
|
|
|
|
std::make_unique<ChooseRecipientBoxController>(std::move(callback)),
|
|
|
|
std::move(initBox)), LayerOption::KeepOther);
|
2017-12-09 15:13:06 +00:00
|
|
|
return weak->data();
|
2017-12-06 10:13:38 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 14:41:52 +00:00
|
|
|
void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) {
|
2017-12-08 14:25:29 +00:00
|
|
|
if (!channel->isMegagroup()
|
|
|
|
&& channel->membersCount() >= Global::ChatSizeMax()) {
|
2017-11-19 14:41:52 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<MaxInviteBox>(channel),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-10 11:15:13 +00:00
|
|
|
auto callback = [=](const MTPchannels_ChannelParticipants &result) {
|
2017-12-01 18:38:44 +00:00
|
|
|
Auth().api().parseChannelParticipants(channel, result, [&](
|
2017-11-28 18:30:01 +00:00
|
|
|
int availableCount,
|
2017-11-20 19:54:05 +00:00
|
|
|
const QVector<MTPChannelParticipant> &list) {
|
|
|
|
auto already = (
|
|
|
|
list
|
2019-01-10 11:15:13 +00:00
|
|
|
) | ranges::view::transform([](const MTPChannelParticipant &p) {
|
|
|
|
return p.match([](const auto &data) {
|
|
|
|
return data.vuser_id.v;
|
|
|
|
});
|
2017-11-20 19:54:05 +00:00
|
|
|
}) | ranges::view::transform([](UserId userId) {
|
2019-01-18 12:27:37 +00:00
|
|
|
return Auth().data().userLoaded(userId);
|
2017-11-20 19:54:05 +00:00
|
|
|
}) | ranges::view::filter([](UserData *user) {
|
|
|
|
return (user != nullptr);
|
2017-11-21 11:59:18 +00:00
|
|
|
}) | ranges::to_vector;
|
2017-11-19 14:41:52 +00:00
|
|
|
|
2017-11-20 19:54:05 +00:00
|
|
|
AddParticipantsBoxController::Start(
|
|
|
|
channel,
|
|
|
|
{ already.begin(), already.end() });
|
|
|
|
});
|
2017-11-19 14:41:52 +00:00
|
|
|
};
|
|
|
|
Auth().api().requestChannelMembersForAdd(channel, callback);
|
|
|
|
}
|
|
|
|
|
2018-02-12 11:10:40 +00:00
|
|
|
void PeerMenuAddMuteAction(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const PeerMenuCallback &addAction) {
|
2018-04-09 17:48:29 +00:00
|
|
|
Auth().data().requestNotifySettings(peer);
|
|
|
|
const auto muteText = [](bool isMuted) {
|
2018-02-12 11:10:40 +00:00
|
|
|
return lang(isMuted
|
|
|
|
? lng_enable_notifications_from_tray
|
|
|
|
: lng_disable_notifications_from_tray);
|
|
|
|
};
|
2018-04-09 17:48:29 +00:00
|
|
|
const auto muteAction = addAction(QString("-"), [=] {
|
|
|
|
if (!Auth().data().notifyIsMuted(peer)) {
|
2018-02-12 11:10:40 +00:00
|
|
|
Ui::show(Box<MuteSettingsBox>(peer));
|
|
|
|
} else {
|
2018-04-09 17:48:29 +00:00
|
|
|
Auth().data().updateNotifySettings(peer, 0);
|
2018-02-12 11:10:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto lifetime = Ui::CreateChild<rpl::lifetime>(muteAction);
|
|
|
|
Info::Profile::NotificationsEnabledValue(
|
2018-04-09 17:48:29 +00:00
|
|
|
peer
|
|
|
|
) | rpl::start_with_next([=](bool enabled) {
|
|
|
|
muteAction->setText(muteText(!enabled));
|
2018-11-21 10:09:46 +00:00
|
|
|
}, *lifetime);
|
2018-02-12 11:10:40 +00:00
|
|
|
}
|
2018-03-06 17:07:42 +00:00
|
|
|
// #feed
|
|
|
|
//void PeerMenuUngroupFeed(not_null<Data::Feed*> feed) {
|
|
|
|
// Ui::show(Box<ConfirmBox>(
|
|
|
|
// lang(lng_feed_sure_ungroup_all),
|
|
|
|
// lang(lng_feed_ungroup_sure),
|
|
|
|
// [=] { Ui::hideLayer(); Auth().api().ungroupAllFromFeed(feed); }));
|
|
|
|
//}
|
|
|
|
//
|
2019-04-18 08:28:43 +00:00
|
|
|
void ToggleHistoryArchived(not_null<History*> history, bool archived) {
|
|
|
|
const auto callback = [=] {
|
2019-04-25 09:20:20 +00:00
|
|
|
Ui::Toast::Config toast;
|
|
|
|
toast.text = lang(archived
|
2019-04-23 12:29:23 +00:00
|
|
|
? lng_archived_added
|
2019-04-25 09:20:20 +00:00
|
|
|
: lng_archived_removed);
|
|
|
|
toast.maxWidth = st::boxWideWidth;
|
|
|
|
if (archived) {
|
|
|
|
toast.durationMs = kArchivedToastDuration;
|
|
|
|
}
|
|
|
|
Ui::Toast::Show(toast);
|
2019-04-18 08:28:43 +00:00
|
|
|
};
|
|
|
|
history->session().api().toggleHistoryArchived(
|
|
|
|
history,
|
|
|
|
archived,
|
|
|
|
callback);
|
|
|
|
}
|
2018-01-23 16:51:12 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> ClearHistoryHandler(not_null<PeerData*> peer) {
|
2019-03-21 12:07:32 +00:00
|
|
|
return [=] {
|
2019-03-21 13:48:40 +00:00
|
|
|
Ui::show(Box<DeleteMessagesBox>(peer, true), LayerOption::KeepOther);
|
2017-12-06 14:39:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> DeleteAndLeaveHandler(not_null<PeerData*> peer) {
|
2019-03-21 12:07:32 +00:00
|
|
|
return [=] {
|
2019-03-21 13:48:40 +00:00
|
|
|
Ui::show(Box<DeleteMessagesBox>(peer, false), LayerOption::KeepOther);
|
2017-12-06 14:39:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
void FillPeerMenu(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2017-11-06 18:03:20 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const PeerMenuCallback &callback,
|
2017-11-07 15:12:54 +00:00
|
|
|
PeerMenuSource source) {
|
|
|
|
Filler filler(controller, peer, callback, source);
|
2017-11-06 18:03:20 +00:00
|
|
|
filler.fill();
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
void FillFolderMenu(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2019-04-15 11:54:03 +00:00
|
|
|
not_null<Data::Folder*> folder,
|
2018-01-05 15:57:18 +00:00
|
|
|
const PeerMenuCallback &callback,
|
|
|
|
PeerMenuSource source) {
|
2019-04-15 11:54:03 +00:00
|
|
|
FolderFiller filler(controller, folder, callback, source);
|
2018-01-05 15:57:18 +00:00
|
|
|
filler.fill();
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
} // namespace Window
|