Fix mention links to groups and channels.

This commit is contained in:
John Preston 2022-04-14 14:14:50 +04:00
parent d25bd2f481
commit 205cd3b751
5 changed files with 26 additions and 29 deletions

View file

@ -176,7 +176,7 @@ void MentionClickHandler::onClick(ClickContext context) const {
using Info = Window::SessionNavigation::PeerByLinkInfo; using Info = Window::SessionNavigation::PeerByLinkInfo;
m->controller()->showPeerByLink(Info{ m->controller()->showPeerByLink(Info{
.usernameOrId = _tag.mid(1), .usernameOrId = _tag.mid(1),
.messageId = ShowAtProfileMsgId .resolveType = Window::ResolveType::Mention,
}); });
} }
} }

View file

@ -330,22 +330,21 @@ bool ResolveUsernameOrPhone(
} else if (!validDomain(domain) && !validPhone(phone)) { } else if (!validDomain(domain) && !validPhone(phone)) {
return false; return false;
} }
using BotStartType = Window::BotStartType; using ResolveType = Window::ResolveType;
auto startType = BotStartType::None; auto resolveType = ResolveType::Default;
auto startToken = params.value(u"start"_q); auto startToken = params.value(u"start"_q);
if (!startToken.isEmpty()) { if (!startToken.isEmpty()) {
startType = BotStartType::Personal; resolveType = ResolveType::BotStart;
} else if (params.contains(u"startgroup"_q)) { } else if (params.contains(u"startgroup"_q)) {
startType = BotStartType::Group; resolveType = ResolveType::AddToGroup;
startToken = params.value(u"startgroup"_q); startToken = params.value(u"startgroup"_q);
} else if (params.contains(u"startchannel"_q)) { } else if (params.contains(u"startchannel"_q)) {
startType = BotStartType::Channel; resolveType = ResolveType::AddToChannel;
} }
auto post = ShowAtUnreadMsgId; auto post = ShowAtUnreadMsgId;
auto adminRights = ChatAdminRights(); auto adminRights = ChatAdminRights();
if (startType == BotStartType::Group if (resolveType == ResolveType::AddToGroup
|| startType == BotStartType::Channel) { || resolveType == ResolveType::AddToChannel) {
post = ShowAtProfileMsgId;
adminRights = ParseRequestedAdminRights(params.value(u"admin"_q)); adminRights = ParseRequestedAdminRights(params.value(u"admin"_q));
} }
const auto postParam = params.value(qsl("post")); const auto postParam = params.value(qsl("post"));
@ -359,8 +358,7 @@ bool ResolveUsernameOrPhone(
const auto gameParam = params.value(qsl("game")); const auto gameParam = params.value(qsl("game"));
if (!gameParam.isEmpty() && validDomain(gameParam)) { if (!gameParam.isEmpty() && validDomain(gameParam)) {
startToken = gameParam; startToken = gameParam;
post = ShowAtProfileMsgId; resolveType = ResolveType::ShareGame;
startType = BotStartType::ShareGame;
} }
const auto fromMessageId = context.value<ClickHandlerContext>().itemId; const auto fromMessageId = context.value<ClickHandlerContext>().itemId;
using Navigation = Window::SessionNavigation; using Navigation = Window::SessionNavigation;
@ -377,7 +375,7 @@ bool ResolveUsernameOrPhone(
Navigation::ThreadId{ threadId } Navigation::ThreadId{ threadId }
} }
: Navigation::RepliesByLinkInfo{ v::null }, : Navigation::RepliesByLinkInfo{ v::null },
.startType = startType, .resolveType = resolveType,
.startToken = startToken, .startToken = startToken,
.startAdminRights = adminRights, .startAdminRights = adminRights,
.attachBotUsername = params.value(u"attach"_q), .attachBotUsername = params.value(u"attach"_q),

View file

@ -82,7 +82,6 @@ constexpr auto ShowAtUnreadMsgId = MsgId(0);
constexpr auto SpecialMsgIdShift = EndClientMsgId.bare; constexpr auto SpecialMsgIdShift = EndClientMsgId.bare;
constexpr auto ShowAtTheEndMsgId = MsgId(SpecialMsgIdShift + 1); constexpr auto ShowAtTheEndMsgId = MsgId(SpecialMsgIdShift + 1);
constexpr auto SwitchAtTopMsgId = MsgId(SpecialMsgIdShift + 2); constexpr auto SwitchAtTopMsgId = MsgId(SpecialMsgIdShift + 2);
constexpr auto ShowAtProfileMsgId = MsgId(SpecialMsgIdShift + 3);
constexpr auto ShowAndStartBotMsgId = MsgId(SpecialMsgIdShift + 4); constexpr auto ShowAndStartBotMsgId = MsgId(SpecialMsgIdShift + 4);
constexpr auto ShowForChooseMessagesMsgId = MsgId(SpecialMsgIdShift + 6); constexpr auto ShowForChooseMessagesMsgId = MsgId(SpecialMsgIdShift + 6);

View file

@ -317,14 +317,14 @@ void SessionNavigation::showPeerByLinkResolved(
commentId->id, commentId->id,
params); params);
} else if (bot } else if (bot
&& (info.startType == BotStartType::Group && (info.resolveType == ResolveType::AddToGroup
|| info.startType == BotStartType::Channel || info.resolveType == ResolveType::AddToChannel
|| info.startType == BotStartType::ShareGame)) { || info.resolveType == ResolveType::ShareGame)) {
const auto scope = (info.startType == BotStartType::ShareGame) const auto scope = (info.resolveType == ResolveType::ShareGame)
? Scope::ShareGame ? Scope::ShareGame
: (info.startType == BotStartType::Group) : (info.resolveType == ResolveType::AddToGroup)
? (info.startAdminRights ? Scope::GroupAdmin : Scope::All) ? (info.startAdminRights ? Scope::GroupAdmin : Scope::All)
: (info.startType == BotStartType::Channel) : (info.resolveType == ResolveType::AddToChannel)
? Scope::ChannelAdmin ? Scope::ChannelAdmin
: Scope::None; : Scope::None;
Assert(scope != Scope::None); Assert(scope != Scope::None);
@ -334,11 +334,10 @@ void SessionNavigation::showPeerByLinkResolved(
scope, scope,
info.startToken, info.startToken,
info.startAdminRights); info.startAdminRights);
} else if (info.messageId == ShowAtProfileMsgId) { } else if (info.resolveType == ResolveType::Mention) {
if (bot) { if (bot || peer->isChannel()) {
// Always open bot chats, even from mention links.
crl::on_main(this, [=] { crl::on_main(this, [=] {
showPeerHistory(bot->id, params); showPeerHistory(peer->id, params);
}); });
} else { } else {
showPeerInfo(peer, params); showPeerInfo(peer, params);

View file

@ -89,12 +89,13 @@ enum class GifPauseReason {
using GifPauseReasons = base::flags<GifPauseReason>; using GifPauseReasons = base::flags<GifPauseReason>;
inline constexpr bool is_flag_type(GifPauseReason) { return true; }; inline constexpr bool is_flag_type(GifPauseReason) { return true; };
enum class BotStartType { enum class ResolveType {
None, Default,
Personal, BotStart,
Group, AddToGroup,
Channel, AddToChannel,
ShareGame, ShareGame,
Mention,
}; };
struct PeerThemeOverride { struct PeerThemeOverride {
@ -189,7 +190,7 @@ public:
QString phone; QString phone;
MsgId messageId = ShowAtUnreadMsgId; MsgId messageId = ShowAtUnreadMsgId;
RepliesByLinkInfo repliesInfo; RepliesByLinkInfo repliesInfo;
BotStartType startType = BotStartType::None; ResolveType resolveType = ResolveType::Default;
QString startToken; QString startToken;
ChatAdminRights startAdminRights; ChatAdminRights startAdminRights;
QString attachBotUsername; QString attachBotUsername;