mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-24 10:10:35 +02:00
Allow sharing link to chats.
This commit is contained in:
parent
7132ab5bf4
commit
542abb26b9
4 changed files with 85 additions and 19 deletions
|
@ -1003,7 +1003,7 @@ void Controller::fillManageSection() {
|
|||
});
|
||||
}) | rpl::flatten_latest(
|
||||
) | ToPositiveNumberString(),
|
||||
[=] { ShowEditInviteLinks(_navigation, _peer); },
|
||||
[=] { },
|
||||
st::infoIconInviteLinks);
|
||||
}
|
||||
if (canViewAdmins) {
|
||||
|
|
|
@ -9,7 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_drafts.h"
|
||||
#include "main/main_session.h"
|
||||
#include "data/data_session.h"
|
||||
#include "api/api_invite_links.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
|
@ -19,13 +21,69 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/controls/invite_link_buttons.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "history/view/history_view_group_call_tracker.h" // GenerateUs...
|
||||
#include "history/history.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "boxes/peer_list_box.h"
|
||||
#include "boxes/peer_list_controllers.h"
|
||||
#include "apiwrap.h"
|
||||
#include "api/api_common.h"
|
||||
#include "styles/style_info.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
namespace {
|
||||
|
||||
void ShareLinkBox(not_null<PeerData*> peer, const QString &link) {
|
||||
const auto weak = std::make_shared<QPointer<PeerListBox>>();
|
||||
auto callback = [
|
||||
weak,
|
||||
link
|
||||
](not_null<PeerData*> peer) mutable {
|
||||
const auto history = peer->owner().history(peer);
|
||||
if (peer->isSelf()) {
|
||||
const auto api = &peer->session().api();
|
||||
auto message = Api::MessageToSend(history);
|
||||
message.action.clearDraft = false;
|
||||
message.action.generateLocal = false;
|
||||
message.textWithTags = { link };
|
||||
api->sendMessage(std::move(message));
|
||||
Ui::Toast::Show(tr::lng_share_done(tr::now));
|
||||
} else {
|
||||
auto textWithTags = TextWithTags{
|
||||
link + '\n',
|
||||
TextWithTags::Tags()
|
||||
};
|
||||
auto cursor = MessageCursor{
|
||||
link.size() + 1,
|
||||
link.size() + 1,
|
||||
QFIXED_MAX
|
||||
};
|
||||
history->setLocalDraft(
|
||||
std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
|
||||
history->clearLocalEditDraft();
|
||||
history->session().changes().historyUpdated(
|
||||
history,
|
||||
Data::HistoryUpdate::Flag::LocalDraftSet);
|
||||
}
|
||||
if (const auto strong = *weak) {
|
||||
strong->closeBox();
|
||||
}
|
||||
};
|
||||
auto initBox = [](not_null<PeerListBox*> box) {
|
||||
box->addButton(tr::lng_cancel(), [box] {
|
||||
box->closeBox();
|
||||
});
|
||||
};
|
||||
*weak = Ui::show(Box<PeerListBox>(
|
||||
std::make_unique<ChooseRecipientBoxController>(
|
||||
&peer->session(),
|
||||
std::move(callback)),
|
||||
std::move(initBox)), Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void AddPermanentLinkBlock(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer) {
|
||||
|
@ -55,8 +113,7 @@ void AddPermanentLinkBlock(
|
|||
});
|
||||
const auto shareLink = crl::guard(weak, [=] {
|
||||
if (const auto link = computePermanentLink()) {
|
||||
QGuiApplication::clipboard()->setText(link->link);
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
ShareLinkBox(peer, link->link);
|
||||
}
|
||||
});
|
||||
const auto revokeLink = crl::guard(weak, [=] {
|
||||
|
|
|
@ -116,8 +116,9 @@ struct HistoryUpdate {
|
|||
OutboxRead = (1 << 10),
|
||||
BotKeyboard = (1 << 11),
|
||||
CloudDraft = (1 << 12),
|
||||
LocalDraftSet = (1 << 13),
|
||||
|
||||
LastUsedBit = (1 << 12),
|
||||
LastUsedBit = (1 << 13),
|
||||
};
|
||||
using Flags = base::flags<Flag>;
|
||||
friend inline constexpr auto is_flag_type(Flag) { return true; }
|
||||
|
|
|
@ -301,14 +301,27 @@ MainWidget::MainWidget(
|
|||
|
||||
session().changes().historyUpdates(
|
||||
Data::HistoryUpdate::Flag::MessageSent
|
||||
| Data::HistoryUpdate::Flag::LocalDraftSet
|
||||
) | rpl::start_with_next([=](const Data::HistoryUpdate &update) {
|
||||
const auto history = update.history;
|
||||
history->forgetScrollState();
|
||||
if (const auto from = history->peer->migrateFrom()) {
|
||||
if (const auto migrated = history->owner().historyLoaded(from)) {
|
||||
migrated->forgetScrollState();
|
||||
if (update.flags & Data::HistoryUpdate::Flag::MessageSent) {
|
||||
history->forgetScrollState();
|
||||
if (const auto from = history->peer->migrateFrom()) {
|
||||
auto &owner = history->owner();
|
||||
if (const auto migrated = owner.historyLoaded(from)) {
|
||||
migrated->forgetScrollState();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (update.flags & Data::HistoryUpdate::Flag::LocalDraftSet) {
|
||||
const auto opened = (_history->peer() == history->peer.get());
|
||||
if (opened) {
|
||||
_history->applyDraft();
|
||||
} else {
|
||||
Ui::showPeerHistory(history, ShowAtUnreadMsgId);
|
||||
}
|
||||
Ui::hideLayer();
|
||||
}
|
||||
}, lifetime());
|
||||
|
||||
// MSVC BUG + REGRESSION rpl::mappers::tuple :(
|
||||
|
@ -538,11 +551,9 @@ bool MainWidget::shareUrl(
|
|||
history->setLocalDraft(
|
||||
std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
|
||||
history->clearLocalEditDraft();
|
||||
if (_history->peer() == peer) {
|
||||
_history->applyDraft();
|
||||
} else {
|
||||
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
||||
}
|
||||
history->session().changes().historyUpdated(
|
||||
history,
|
||||
Data::HistoryUpdate::Flag::LocalDraftSet);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -567,12 +578,9 @@ bool MainWidget::inlineSwitchChosen(PeerId peerId, const QString &botAndQuery) {
|
|||
MessageCursor cursor = { botAndQuery.size(), botAndQuery.size(), QFIXED_MAX };
|
||||
h->setLocalDraft(std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
|
||||
h->clearLocalEditDraft();
|
||||
const auto opened = _history->peer() && (_history->peer() == peer);
|
||||
if (opened) {
|
||||
_history->applyDraft();
|
||||
} else {
|
||||
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
||||
}
|
||||
h->session().changes().historyUpdated(
|
||||
h,
|
||||
Data::HistoryUpdate::Flag::LocalDraftSet);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue