mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +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(
|
}) | rpl::flatten_latest(
|
||||||
) | ToPositiveNumberString(),
|
) | ToPositiveNumberString(),
|
||||||
[=] { ShowEditInviteLinks(_navigation, _peer); },
|
[=] { },
|
||||||
st::infoIconInviteLinks);
|
st::infoIconInviteLinks);
|
||||||
}
|
}
|
||||||
if (canViewAdmins) {
|
if (canViewAdmins) {
|
||||||
|
|
|
@ -9,7 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "data/data_drafts.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
#include "api/api_invite_links.h"
|
#include "api/api_invite_links.h"
|
||||||
#include "ui/wrap/vertical_layout.h"
|
#include "ui/wrap/vertical_layout.h"
|
||||||
#include "ui/wrap/padding_wrap.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/controls/invite_link_buttons.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
#include "history/view/history_view_group_call_tracker.h" // GenerateUs...
|
#include "history/view/history_view_group_call_tracker.h" // GenerateUs...
|
||||||
|
#include "history/history.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "boxes/confirm_box.h"
|
#include "boxes/confirm_box.h"
|
||||||
|
#include "boxes/peer_list_box.h"
|
||||||
|
#include "boxes/peer_list_controllers.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_common.h"
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#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(
|
void AddPermanentLinkBlock(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
not_null<PeerData*> peer) {
|
not_null<PeerData*> peer) {
|
||||||
|
@ -55,8 +113,7 @@ void AddPermanentLinkBlock(
|
||||||
});
|
});
|
||||||
const auto shareLink = crl::guard(weak, [=] {
|
const auto shareLink = crl::guard(weak, [=] {
|
||||||
if (const auto link = computePermanentLink()) {
|
if (const auto link = computePermanentLink()) {
|
||||||
QGuiApplication::clipboard()->setText(link->link);
|
ShareLinkBox(peer, link->link);
|
||||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const auto revokeLink = crl::guard(weak, [=] {
|
const auto revokeLink = crl::guard(weak, [=] {
|
||||||
|
|
|
@ -116,8 +116,9 @@ struct HistoryUpdate {
|
||||||
OutboxRead = (1 << 10),
|
OutboxRead = (1 << 10),
|
||||||
BotKeyboard = (1 << 11),
|
BotKeyboard = (1 << 11),
|
||||||
CloudDraft = (1 << 12),
|
CloudDraft = (1 << 12),
|
||||||
|
LocalDraftSet = (1 << 13),
|
||||||
|
|
||||||
LastUsedBit = (1 << 12),
|
LastUsedBit = (1 << 13),
|
||||||
};
|
};
|
||||||
using Flags = base::flags<Flag>;
|
using Flags = base::flags<Flag>;
|
||||||
friend inline constexpr auto is_flag_type(Flag) { return true; }
|
friend inline constexpr auto is_flag_type(Flag) { return true; }
|
||||||
|
|
|
@ -301,14 +301,27 @@ MainWidget::MainWidget(
|
||||||
|
|
||||||
session().changes().historyUpdates(
|
session().changes().historyUpdates(
|
||||||
Data::HistoryUpdate::Flag::MessageSent
|
Data::HistoryUpdate::Flag::MessageSent
|
||||||
|
| Data::HistoryUpdate::Flag::LocalDraftSet
|
||||||
) | rpl::start_with_next([=](const Data::HistoryUpdate &update) {
|
) | rpl::start_with_next([=](const Data::HistoryUpdate &update) {
|
||||||
const auto history = update.history;
|
const auto history = update.history;
|
||||||
history->forgetScrollState();
|
if (update.flags & Data::HistoryUpdate::Flag::MessageSent) {
|
||||||
if (const auto from = history->peer->migrateFrom()) {
|
history->forgetScrollState();
|
||||||
if (const auto migrated = history->owner().historyLoaded(from)) {
|
if (const auto from = history->peer->migrateFrom()) {
|
||||||
migrated->forgetScrollState();
|
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());
|
}, lifetime());
|
||||||
|
|
||||||
// MSVC BUG + REGRESSION rpl::mappers::tuple :(
|
// MSVC BUG + REGRESSION rpl::mappers::tuple :(
|
||||||
|
@ -538,11 +551,9 @@ bool MainWidget::shareUrl(
|
||||||
history->setLocalDraft(
|
history->setLocalDraft(
|
||||||
std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
|
std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
|
||||||
history->clearLocalEditDraft();
|
history->clearLocalEditDraft();
|
||||||
if (_history->peer() == peer) {
|
history->session().changes().historyUpdated(
|
||||||
_history->applyDraft();
|
history,
|
||||||
} else {
|
Data::HistoryUpdate::Flag::LocalDraftSet);
|
||||||
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,12 +578,9 @@ bool MainWidget::inlineSwitchChosen(PeerId peerId, const QString &botAndQuery) {
|
||||||
MessageCursor cursor = { botAndQuery.size(), botAndQuery.size(), QFIXED_MAX };
|
MessageCursor cursor = { botAndQuery.size(), botAndQuery.size(), QFIXED_MAX };
|
||||||
h->setLocalDraft(std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
|
h->setLocalDraft(std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
|
||||||
h->clearLocalEditDraft();
|
h->clearLocalEditDraft();
|
||||||
const auto opened = _history->peer() && (_history->peer() == peer);
|
h->session().changes().historyUpdated(
|
||||||
if (opened) {
|
h,
|
||||||
_history->applyDraft();
|
Data::HistoryUpdate::Flag::LocalDraftSet);
|
||||||
} else {
|
|
||||||
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue