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"
|
2019-01-10 06:26:08 +00:00
|
|
|
#include "boxes/peers/add_participants_box.h"
|
2017-12-06 10:13:38 +00:00
|
|
|
#include "ui/toast/toast.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"
|
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"
|
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 {
|
|
|
|
|
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();
|
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);
|
|
|
|
|
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
|
|
|
|
|
|
|
};
|
|
|
|
|
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(
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<Controller*> 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-04-19 08:47:49 +00:00
|
|
|
//bool showInfo();
|
|
|
|
//void addPinToggle();
|
|
|
|
//void addInfo();
|
|
|
|
//void addSearch();
|
|
|
|
//void addNotifications();
|
|
|
|
//void addUngroup();
|
2018-01-05 15:57:18 +00:00
|
|
|
|
|
|
|
not_null<Controller*> _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;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-04-19 08:47:49 +00:00
|
|
|
History *FindWastedPin(FolderId folderId) {
|
|
|
|
const auto &order = Auth().data().pinnedChatsOrder(folderId);
|
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()
|
|
|
|
&& !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) {
|
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();
|
|
|
|
const auto folderId = folder ? folder->id() : 0;
|
|
|
|
const auto pinnedCount = Auth().data().pinnedChatsCount(folderId);
|
|
|
|
const auto pinnedMax = Auth().data().pinnedChatsLimit(folderId);
|
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-19 08:47:49 +00:00
|
|
|
if (const auto wasted = FindWastedPin(folderId)) {
|
|
|
|
Auth().data().setChatPinned(wasted, false);
|
|
|
|
Auth().data().setChatPinned(key, true);
|
|
|
|
Auth().api().savePinnedOrder(folderId);
|
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)
|
|
|
|
)).send();
|
|
|
|
} 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(
|
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;
|
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() {
|
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] {
|
2019-01-18 12:27:37 +00:00
|
|
|
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) {
|
|
|
|
auto blockText = [](not_null<UserData*> user) {
|
|
|
|
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));
|
|
|
|
};
|
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); });
|
|
|
|
}
|
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));
|
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-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-03-17 08:14:58 +00:00
|
|
|
App::wnd()->controller()->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);
|
|
|
|
_addAction(text, [channel] {
|
2019-03-17 08:14:58 +00:00
|
|
|
App::wnd()->controller()->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() {
|
2017-11-07 15:12:54 +00:00
|
|
|
if (_source == PeerMenuSource::ChatsList) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (const auto history = _peer->owner().historyLoaded(_peer)) {
|
2019-04-18 11:31:30 +00:00
|
|
|
if (!history->fixedOnTopIndex()) {
|
2018-05-11 14:03:53 +00:00
|
|
|
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);
|
|
|
|
}
|
2019-04-18 08:28:43 +00:00
|
|
|
if (_source == PeerMenuSource::ChatsList) {
|
|
|
|
addToggleArchive();
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
FolderFiller::FolderFiller(
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<Controller*> 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)
|
2019-04-15 11:54:03 +00:00
|
|
|
: _controller(controller)
|
|
|
|
, _folder(folder)
|
|
|
|
, _addAction(addAction)
|
|
|
|
, _source(source) {
|
2018-02-16 15:46:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
void FolderFiller::fill() { // #TODO archive
|
|
|
|
//if (_source == PeerMenuSource::ChatsList) {
|
|
|
|
// addPinToggle();
|
|
|
|
//}
|
|
|
|
//if (showInfo()) {
|
|
|
|
// addInfo();
|
|
|
|
//}
|
|
|
|
//addNotifications();
|
|
|
|
//if (_source == PeerMenuSource::ChatsList) {
|
|
|
|
// addSearch();
|
|
|
|
//}
|
|
|
|
//addUngroup();
|
2018-02-18 14:00:14 +00:00
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//
|
|
|
|
//bool FolderFiller::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;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void FolderFiller::addPinToggle() {
|
|
|
|
// const auto feed = _feed;
|
|
|
|
// const auto isPinned = feed->isPinnedDialog();
|
|
|
|
// const auto pinText = [](bool isPinned) {
|
|
|
|
// return lang(isPinned
|
|
|
|
// ? lng_context_unpin_from_top
|
|
|
|
// : lng_context_pin_to_top);
|
|
|
|
// };
|
|
|
|
// _addAction(pinText(isPinned), [=] {
|
|
|
|
// TogglePinnedDialog(feed);
|
|
|
|
// });
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//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-03-21 12:07:32 +00:00
|
|
|
user->session().api().request(MTPcontacts_DeleteContact(
|
|
|
|
user->inputUser
|
|
|
|
)).done([=](const MTPcontacts_Link &result) {
|
|
|
|
result.match([&](const MTPDcontacts_link &data) {
|
|
|
|
user->owner().processUser(data.vuser);
|
|
|
|
App::feedUserLink(
|
|
|
|
MTP_int(peerToUser(user->id)),
|
|
|
|
data.vmy_link,
|
|
|
|
data.vforeign_link);
|
|
|
|
});
|
|
|
|
}).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) {
|
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()) {
|
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());
|
|
|
|
}
|
|
|
|
|
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 = [=] {
|
|
|
|
Ui::Toast::Show(lang(archived
|
|
|
|
? lng_chat_archived
|
|
|
|
: lng_chat_unarchived));
|
|
|
|
};
|
|
|
|
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(
|
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();
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
void FillFolderMenu(
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<Controller*> 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
|