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"
|
2018-12-20 16:02:44 +00:00
|
|
|
#include "boxes/create_poll_box.h"
|
2017-11-07 13:13:41 +00:00
|
|
|
#include "boxes/peer_list_controllers.h"
|
2017-11-08 16:45:30 +00:00
|
|
|
#include "boxes/peers/manage_peer_box.h"
|
2017-12-02 12:04:22 +00:00
|
|
|
#include "boxes/peers/edit_peer_info_box.h"
|
2017-12-06 10:13:38 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2017-11-20 19:54:05 +00:00
|
|
|
#include "core/tl_help.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"
|
|
|
|
#include "styles/style_boxes.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2017-11-07 11:53:05 +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"
|
2018-02-13 16:11:00 +00:00
|
|
|
#include "info/feed/info_feed_channels_controllers.h"
|
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"
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "data/data_feed.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"
|
|
|
|
#include "data/data_user.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2017-11-06 18:03:20 +00:00
|
|
|
|
|
|
|
namespace Window {
|
2017-11-07 13:13:41 +00:00
|
|
|
namespace {
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
class Filler {
|
|
|
|
public:
|
|
|
|
Filler(
|
2017-11-07 11:53:05 +00:00
|
|
|
not_null<Controller*> 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();
|
2017-11-06 18:03:20 +00:00
|
|
|
void addPinToggle();
|
|
|
|
void addInfo();
|
|
|
|
void addSearch();
|
2018-06-26 18:03:45 +00:00
|
|
|
void addToggleUnreadMark();
|
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);
|
|
|
|
|
2017-11-07 11:53:05 +00:00
|
|
|
not_null<Controller*> _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
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
class FeedFiller {
|
|
|
|
public:
|
|
|
|
FeedFiller(
|
|
|
|
not_null<Controller*> controller,
|
|
|
|
not_null<Data::Feed*> feed,
|
|
|
|
const PeerMenuCallback &addAction,
|
|
|
|
PeerMenuSource source);
|
|
|
|
void fill();
|
|
|
|
|
|
|
|
private:
|
2018-02-16 15:46:24 +00:00
|
|
|
bool showInfo();
|
2018-01-05 15:57:18 +00:00
|
|
|
void addPinToggle();
|
2018-02-16 15:46:24 +00:00
|
|
|
void addInfo();
|
|
|
|
void addSearch();
|
2018-02-13 16:11:00 +00:00
|
|
|
void addNotifications();
|
2018-02-18 14:00:14 +00:00
|
|
|
void addUngroup();
|
2018-01-05 15:57:18 +00:00
|
|
|
|
|
|
|
not_null<Controller*> _controller;
|
|
|
|
not_null<Data::Feed*> _feed;
|
|
|
|
const PeerMenuCallback &_addAction;
|
|
|
|
PeerMenuSource _source;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
History *FindWastedPin() {
|
2018-01-04 19:54:35 +00:00
|
|
|
const auto &order = Auth().data().pinnedDialogsOrder();
|
|
|
|
for (const auto pinned : order) {
|
|
|
|
if (const auto history = pinned.history()) {
|
|
|
|
if (history->peer->isChat()
|
|
|
|
&& history->peer->asChat()->isDeactivated()
|
|
|
|
&& !history->inChatList(Dialogs::Mode::All)) {
|
|
|
|
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) {
|
|
|
|
if (chat->count >= Global::ChatSizeMax() && chat->amCreator()) {
|
2019-01-08 13:57:22 +00:00
|
|
|
// #TODO convert and add inside AddParticipantsBoxController?
|
2018-01-05 15:57:18 +00:00
|
|
|
} else {
|
|
|
|
AddParticipantsBoxController::Start(chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinnedLimitReached(Dialogs::Key key) {
|
|
|
|
const auto pinnedCount = Auth().data().pinnedDialogsCount();
|
|
|
|
const auto pinnedMax = Global::PinnedDialogsCountMax();
|
|
|
|
if (pinnedCount < pinnedMax) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Some old chat, that was converted, maybe is still pinned.
|
2019-01-08 13:57:22 +00:00
|
|
|
if (const auto wasted = FindWastedPin()) {
|
2018-01-05 15:57:18 +00:00
|
|
|
Auth().data().setPinnedDialog(wasted, false);
|
|
|
|
Auth().data().setPinnedDialog(key, true);
|
|
|
|
Auth().api().savePinnedOrder();
|
|
|
|
} else {
|
|
|
|
auto errorText = lng_error_pinned_max(
|
|
|
|
lt_count,
|
|
|
|
pinnedMax);
|
|
|
|
Ui::show(Box<InformBox>(errorText));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TogglePinnedDialog(Dialogs::Key key) {
|
|
|
|
const auto isPinned = !key.entry()->isPinnedDialog();
|
|
|
|
if (isPinned && PinnedLimitReached(key)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Auth().data().setPinnedDialog(key, isPinned);
|
|
|
|
auto flags = MTPmessages_ToggleDialogPin::Flags(0);
|
|
|
|
if (isPinned) {
|
|
|
|
flags |= MTPmessages_ToggleDialogPin::Flag::f_pinned;
|
|
|
|
}
|
2018-03-06 17:07:42 +00:00
|
|
|
//MTP::send(MTPmessages_ToggleDialogPin( // #feed
|
|
|
|
// MTP_flags(flags),
|
|
|
|
// key.history()
|
|
|
|
// ? MTP_inputDialogPeer(key.history()->peer->input)
|
|
|
|
// : MTP_inputDialogPeerFeed(MTP_int(key.feed()->id()))));
|
|
|
|
if (key.history()) {
|
|
|
|
MTP::send(MTPmessages_ToggleDialogPin(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_inputDialogPeer(key.history()->peer->input)));
|
|
|
|
}
|
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(
|
2017-11-07 11:53:05 +00:00
|
|
|
not_null<Controller*> 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() {
|
2017-12-05 14:07:01 +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
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addPinToggle() {
|
|
|
|
auto peer = _peer;
|
|
|
|
auto isPinned = false;
|
|
|
|
if (auto history = App::historyLoaded(peer)) {
|
|
|
|
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 = [=] {
|
|
|
|
TogglePinnedDialog(App::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] {
|
|
|
|
auto isPinned = App::history(peer)->isPinnedDialog();
|
|
|
|
pinAction->setText(pinText(isPinned));
|
2018-11-21 10:09:46 +00:00
|
|
|
}, *lifetime);
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addInfo() {
|
2017-11-07 11:53:05 +00:00
|
|
|
auto controller = _controller;
|
|
|
|
auto peer = _peer;
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addSearch() {
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(lang(lng_profile_search_messages), [peer = _peer] {
|
2018-01-22 17:39:20 +00:00
|
|
|
App::main()->searchInChat(App::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) {
|
|
|
|
if (const auto history = App::historyLoaded(peer)) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const auto history = App::history(peer);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
void Filler::addBlockUser(not_null<UserData*> user) {
|
|
|
|
auto blockText = [](not_null<UserData*> user) {
|
|
|
|
return lang(user->isBlocked()
|
|
|
|
? (user->botInfo
|
2018-12-04 11:46:07 +00:00
|
|
|
? lng_profile_restart_bot
|
2017-11-06 18:03:20 +00:00
|
|
|
: lng_profile_unblock_user)
|
|
|
|
: (user->botInfo
|
|
|
|
? lng_profile_block_bot
|
|
|
|
: lng_profile_block_user));
|
|
|
|
};
|
2018-12-04 11:46:07 +00:00
|
|
|
auto blockAction = _addAction(blockText(user), [=] {
|
|
|
|
if (user->isBlocked()) {
|
|
|
|
Auth().api().unblockUser(user);
|
2017-11-06 18:03:20 +00:00
|
|
|
} else {
|
2018-12-04 11:46:07 +00:00
|
|
|
Auth().api().blockUser(user);
|
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);
|
|
|
|
});
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
if (user->isContact()) {
|
2017-12-05 14:07:01 +00:00
|
|
|
if (!user->isSelf()) {
|
2017-12-06 14:41:37 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_info_share_contact),
|
|
|
|
[user] { PeerMenuShareContactBox(user); });
|
2017-12-05 14:07:01 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_info_edit_contact),
|
|
|
|
[user] { Ui::show(Box<AddContactBox>(user)); });
|
|
|
|
_addAction(
|
|
|
|
lang(lng_info_delete_contact),
|
|
|
|
[user] { PeerMenuDeleteContact(user); });
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
} else if (user->canShareThisContact()) {
|
2017-12-05 14:07:01 +00:00
|
|
|
if (!user->isSelf()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_info_add_as_contact),
|
|
|
|
[user] { PeerMenuAddContact(user); });
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_info_share_contact),
|
|
|
|
[user] { PeerMenuShareContactBox(user); });
|
|
|
|
} else if (user->botInfo && !user->botInfo->cantJoinGroups) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_profile_invite_to_group),
|
|
|
|
[user] { AddBotToGroupBoxController::Start(user); });
|
|
|
|
}
|
2018-07-23 13:11:56 +00:00
|
|
|
_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));
|
2018-09-11 12:50:40 +00:00
|
|
|
if (!user->isInaccessible() && user != Auth().user()) {
|
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-01-07 12:55:49 +00:00
|
|
|
if (ManagePeerBox::Available(chat)) {
|
|
|
|
const auto text = lang(lng_manage_group_title);
|
|
|
|
_addAction(text, [=] {
|
|
|
|
Ui::show(Box<ManagePeerBox>(chat));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (chat->canAddMembers()) {
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
|
|
|
lang(lng_profile_add_participant),
|
|
|
|
[chat] { AddChatMembers(chat); });
|
|
|
|
}
|
2018-12-20 16:02:44 +00:00
|
|
|
if (chat->canWrite()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_polls_create),
|
|
|
|
[=] { PeerMenuCreatePoll(chat); });
|
|
|
|
}
|
2018-07-23 13:11:56 +00:00
|
|
|
_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();
|
2018-01-26 15:40:11 +00:00
|
|
|
if (!isGroup) {
|
2018-01-29 17:13:24 +00:00
|
|
|
const auto feed = channel->feed();
|
|
|
|
const auto grouped = (feed != nullptr);
|
|
|
|
if (!grouped || feed->channels().size() > 1) {
|
2018-03-06 17:07:42 +00:00
|
|
|
//_addAction( // #feed
|
|
|
|
// lang(grouped ? lng_feed_ungroup : lng_feed_group),
|
|
|
|
// [=] { ToggleChannelGrouping(channel, !grouped); });
|
2018-01-29 17:13:24 +00:00
|
|
|
}
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
2017-11-07 15:12:54 +00:00
|
|
|
if (_source != PeerMenuSource::ChatsList) {
|
2017-11-08 16:45:30 +00:00
|
|
|
if (ManagePeerBox::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);
|
|
|
|
_addAction(text, [channel] {
|
|
|
|
Ui::show(Box<ManagePeerBox>(channel));
|
|
|
|
});
|
|
|
|
}
|
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
|
|
|
}
|
2018-12-20 16:02:44 +00:00
|
|
|
if (channel->canWrite()) {
|
|
|
|
_addAction(
|
|
|
|
lang(lng_polls_create),
|
|
|
|
[=] { PeerMenuCreatePoll(channel); });
|
|
|
|
}
|
2018-07-23 13:11:56 +00:00
|
|
|
_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() {
|
2017-11-07 15:12:54 +00:00
|
|
|
if (_source == PeerMenuSource::ChatsList) {
|
2018-05-11 14:03:53 +00:00
|
|
|
if (const auto history = App::historyLoaded(_peer)) {
|
|
|
|
if (!history->useProxyPromotion()) {
|
|
|
|
addPinToggle();
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2017-11-06 18:03:20 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
FeedFiller::FeedFiller(
|
|
|
|
not_null<Controller*> controller,
|
|
|
|
not_null<Data::Feed*> feed,
|
|
|
|
const PeerMenuCallback &addAction,
|
|
|
|
PeerMenuSource source)
|
|
|
|
: _controller(controller)
|
|
|
|
, _feed(feed)
|
|
|
|
, _addAction(addAction)
|
|
|
|
, _source(source) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedFiller::fill() {
|
|
|
|
if (_source == PeerMenuSource::ChatsList) {
|
|
|
|
addPinToggle();
|
|
|
|
}
|
2018-02-16 15:46:24 +00:00
|
|
|
if (showInfo()) {
|
|
|
|
addInfo();
|
|
|
|
}
|
2018-02-13 16:11:00 +00:00
|
|
|
addNotifications();
|
2018-02-16 15:46:24 +00:00
|
|
|
if (_source == PeerMenuSource::ChatsList) {
|
|
|
|
addSearch();
|
|
|
|
}
|
2018-02-18 14:00:14 +00:00
|
|
|
addUngroup();
|
2018-02-16 15:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedFiller::showInfo() {
|
|
|
|
if (_source == PeerMenuSource::Profile) {
|
|
|
|
return false;
|
|
|
|
} else if (_controller->activeChatCurrent().feed() != _feed) {
|
|
|
|
return true;
|
|
|
|
} else if (!Adaptive::ThreeColumn()) {
|
|
|
|
return true;
|
|
|
|
} else if (
|
|
|
|
!Auth().settings().thirdSectionInfoEnabled() &&
|
|
|
|
!Auth().settings().tabbedReplacedWithInfo()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FeedFiller::addPinToggle() {
|
2018-02-13 16:11:00 +00:00
|
|
|
const auto feed = _feed;
|
|
|
|
const auto isPinned = feed->isPinnedDialog();
|
|
|
|
const auto pinText = [](bool isPinned) {
|
2018-01-05 15:57:18 +00:00
|
|
|
return lang(isPinned
|
|
|
|
? lng_context_unpin_from_top
|
|
|
|
: lng_context_pin_to_top);
|
|
|
|
};
|
2018-02-13 16:11:00 +00:00
|
|
|
_addAction(pinText(isPinned), [=] {
|
2018-01-05 15:57:18 +00:00
|
|
|
TogglePinnedDialog(feed);
|
2018-02-13 16:11:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-16 15:46:24 +00:00
|
|
|
void FeedFiller::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)));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-13 16:11:00 +00:00
|
|
|
void FeedFiller::addNotifications() {
|
|
|
|
const auto feed = _feed;
|
|
|
|
_addAction(lang(lng_feed_notifications), [=] {
|
2018-02-20 16:56:41 +00:00
|
|
|
Info::FeedProfile::NotificationsController::Start(feed);
|
2018-02-13 16:11:00 +00:00
|
|
|
});
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 15:46:24 +00:00
|
|
|
void FeedFiller::addSearch() {
|
|
|
|
const auto feed = _feed;
|
|
|
|
_addAction(lang(lng_profile_search_messages), [=] {
|
|
|
|
App::main()->searchInChat(feed);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-18 14:00:14 +00:00
|
|
|
void FeedFiller::addUngroup() {
|
|
|
|
const auto feed = _feed;
|
2018-03-06 17:07:42 +00:00
|
|
|
//_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) {
|
|
|
|
auto text = lng_sure_delete_contact(
|
|
|
|
lt_contact,
|
|
|
|
App::peerName(user));
|
|
|
|
auto deleteSure = [=] {
|
|
|
|
Ui::hideLayer();
|
|
|
|
MTP::send(
|
|
|
|
MTPcontacts_DeleteContact(user->inputUser),
|
|
|
|
App::main()->rpcDone(
|
|
|
|
&MainWidget::deletedContact,
|
|
|
|
user.get()));
|
|
|
|
};
|
|
|
|
auto box = Box<ConfirmBox>(
|
|
|
|
text,
|
|
|
|
lang(lng_box_delete),
|
|
|
|
std::move(deleteSure));
|
|
|
|
Ui::show(std::move(box));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerMenuAddContact(not_null<UserData*> user) {
|
2018-01-17 16:21:01 +00:00
|
|
|
Ui::show(Box<AddContactBox>(
|
|
|
|
user->firstName,
|
|
|
|
user->lastName,
|
|
|
|
Auth().data().findContactPhone(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()) {
|
2017-12-07 13:02:24 +00:00
|
|
|
auto options = ApiWrap::SendOptions(App::history(peer));
|
|
|
|
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] {
|
2017-12-07 13:02:24 +00:00
|
|
|
const auto history = App::history(peer);
|
|
|
|
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;
|
|
|
|
}
|
2018-12-20 16:02:44 +00:00
|
|
|
const auto options = ApiWrap::SendOptions(App::history(peer));
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
auto options = ApiWrap::SendOptions(App::history(peer));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
auto callback = [channel](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
|
|
|
|
) | ranges::view::transform([&](auto &&p) {
|
|
|
|
return TLHelp::ReadChannelParticipantUserId(p);
|
|
|
|
}) | ranges::view::transform([](UserId userId) {
|
|
|
|
return App::userLoaded(userId);
|
|
|
|
}) | 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); }));
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void ToggleChannelGrouping(not_null<ChannelData*> channel, bool group) {
|
|
|
|
// const auto callback = [=] {
|
|
|
|
// Ui::Toast::Show(lang(group
|
|
|
|
// ? lng_feed_channel_added
|
|
|
|
// : lng_feed_channel_removed));
|
|
|
|
// };
|
|
|
|
// if (group) {
|
|
|
|
// const auto feed = Auth().data().feed(Data::Feed::kId);
|
|
|
|
// if (feed->channels().size() < 2) {
|
|
|
|
// Info::FeedProfile::EditController::Start(feed, channel);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// Auth().api().toggleChannelGrouping(
|
|
|
|
// channel,
|
|
|
|
// group,
|
|
|
|
// callback);
|
|
|
|
//}
|
2018-01-23 16:51:12 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> ClearHistoryHandler(not_null<PeerData*> peer) {
|
2017-12-06 14:39:27 +00:00
|
|
|
return [peer] {
|
|
|
|
const auto weak = std::make_shared<QPointer<ConfirmBox>>();
|
|
|
|
const auto text = peer->isSelf()
|
|
|
|
? lang(lng_sure_delete_saved_messages)
|
|
|
|
: peer->isUser()
|
|
|
|
? lng_sure_delete_history(lt_contact, peer->name)
|
|
|
|
: lng_sure_delete_group_history(lt_group, peer->name);
|
|
|
|
auto callback = [=] {
|
|
|
|
if (auto strong = *weak) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
Auth().api().clearHistory(peer);
|
|
|
|
};
|
|
|
|
*weak = Ui::show(
|
|
|
|
Box<ConfirmBox>(
|
|
|
|
text,
|
|
|
|
lang(lng_box_delete),
|
|
|
|
st::attentionBoxButton,
|
|
|
|
std::move(callback)),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> DeleteAndLeaveHandler(not_null<PeerData*> peer) {
|
2017-12-06 14:39:27 +00:00
|
|
|
return [peer] {
|
|
|
|
const auto warningText = peer->isSelf()
|
|
|
|
? lang(lng_sure_delete_saved_messages)
|
|
|
|
: peer->isUser()
|
|
|
|
? lng_sure_delete_history(lt_contact, peer->name)
|
|
|
|
: peer->isChat()
|
|
|
|
? lng_sure_delete_and_exit(lt_group, peer->name)
|
|
|
|
: lang(peer->isMegagroup()
|
|
|
|
? lng_sure_leave_group
|
|
|
|
: lng_sure_leave_channel);
|
|
|
|
const auto confirmText = lang(peer->isUser()
|
|
|
|
? lng_box_delete
|
|
|
|
: lng_box_leave);
|
|
|
|
const auto &confirmStyle = peer->isChannel()
|
|
|
|
? st::defaultBoxButton
|
|
|
|
: st::attentionBoxButton;
|
|
|
|
auto callback = [peer] {
|
|
|
|
Ui::hideLayer();
|
2018-01-22 16:42:25 +00:00
|
|
|
const auto controller = App::wnd()->controller();
|
|
|
|
if (controller->activeChatCurrent().peer() == peer) {
|
2017-12-06 14:39:27 +00:00
|
|
|
Ui::showChatsList();
|
|
|
|
}
|
|
|
|
if (peer->isUser()) {
|
|
|
|
App::main()->deleteConversation(peer);
|
2018-01-22 16:42:25 +00:00
|
|
|
} else if (const auto chat = peer->asChat()) {
|
2017-12-06 14:39:27 +00:00
|
|
|
App::main()->deleteAndExit(chat);
|
2018-01-22 16:42:25 +00:00
|
|
|
} else if (const auto channel = peer->asChannel()) {
|
2017-12-06 14:39:27 +00:00
|
|
|
// Don't delete old history by default,
|
|
|
|
// because Android app doesn't.
|
|
|
|
//
|
|
|
|
//if (auto migrateFrom = channel->migrateFrom()) {
|
|
|
|
// App::main()->deleteConversation(migrateFrom);
|
|
|
|
//}
|
|
|
|
Auth().api().leaveChannel(channel);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Ui::show(
|
|
|
|
Box<ConfirmBox>(
|
|
|
|
warningText,
|
|
|
|
confirmText,
|
|
|
|
confirmStyle,
|
|
|
|
std::move(callback)),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
void FillPeerMenu(
|
2017-11-07 11:53:05 +00:00
|
|
|
not_null<Controller*> 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();
|
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
void FillFeedMenu(
|
|
|
|
not_null<Controller*> controller,
|
|
|
|
not_null<Data::Feed*> feed,
|
|
|
|
const PeerMenuCallback &callback,
|
|
|
|
PeerMenuSource source) {
|
|
|
|
FeedFiller filler(controller, feed, callback, source);
|
|
|
|
filler.fill();
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
} // namespace Window
|