mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support hashtags with mentions.
This commit is contained in:
parent
f89aeb6ad4
commit
7ee2e3d8bc
6 changed files with 42 additions and 1 deletions
|
@ -40,6 +40,25 @@ std::vector<ReactionId> SearchTagsFromQuery(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HashtagWithUsername HashtagWithUsernameFromQuery(QStringView query) {
|
||||||
|
const auto match = TextUtilities::RegExpHashtag(true).match(query);
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
const auto username = match.capturedView(2).mid(1).toString();
|
||||||
|
const auto offset = int(match.capturedLength(1));
|
||||||
|
const auto full = int(query.size());
|
||||||
|
const auto length = full
|
||||||
|
- int(username.size())
|
||||||
|
- 1
|
||||||
|
- offset
|
||||||
|
- int(match.capturedLength(3));
|
||||||
|
if (!username.isEmpty() && length > 0 && offset + length <= full) {
|
||||||
|
const auto hashtag = query.mid(offset, length).toString();
|
||||||
|
return { hashtag, username };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
QString ReactionEntityData(const ReactionId &id) {
|
QString ReactionEntityData(const ReactionId &id) {
|
||||||
if (id.empty()) {
|
if (id.empty()) {
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -65,6 +65,13 @@ struct MessageReaction {
|
||||||
[[nodiscard]] std::vector<ReactionId> SearchTagsFromQuery(
|
[[nodiscard]] std::vector<ReactionId> SearchTagsFromQuery(
|
||||||
const QString &query);
|
const QString &query);
|
||||||
|
|
||||||
|
struct HashtagWithUsername {
|
||||||
|
QString hashtag;
|
||||||
|
QString username;
|
||||||
|
};
|
||||||
|
[[nodiscard]] HashtagWithUsername HashtagWithUsernameFromQuery(
|
||||||
|
QStringView query);
|
||||||
|
|
||||||
[[nodiscard]] QString ReactionEntityData(const ReactionId &id);
|
[[nodiscard]] QString ReactionEntityData(const ReactionId &id);
|
||||||
|
|
||||||
[[nodiscard]] ReactionId ReactionFromMTP(const MTPReaction &reaction);
|
[[nodiscard]] ReactionId ReactionFromMTP(const MTPReaction &reaction);
|
||||||
|
|
|
@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_history_hider.h"
|
#include "window/window_history_hider.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "window/window_peer_menu.h"
|
#include "window/window_peer_menu.h"
|
||||||
|
#include "window/window_session_controller_link_info.h"
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
#include "chat_helpers/bot_command.h"
|
#include "chat_helpers/bot_command.h"
|
||||||
#include "chat_helpers/tabbed_selector.h" // TabbedSelector::refreshStickers
|
#include "chat_helpers/tabbed_selector.h" // TabbedSelector::refreshStickers
|
||||||
|
@ -744,6 +745,15 @@ void MainWidget::hideSingleUseKeyboard(FullMsgId replyToId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat) {
|
void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat) {
|
||||||
|
const auto complex = Data::HashtagWithUsernameFromQuery(query);
|
||||||
|
if (!complex.username.isEmpty()) {
|
||||||
|
_controller->showPeerByLink(Window::PeerByLinkInfo{
|
||||||
|
.usernameOrId = complex.username,
|
||||||
|
.text = complex.hashtag,
|
||||||
|
.resolveType = Window::ResolveType::HashtagSearch,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto tags = Data::SearchTagsFromQuery(query);
|
auto tags = Data::SearchTagsFromQuery(query);
|
||||||
if (_dialogs) {
|
if (_dialogs) {
|
||||||
auto state = Dialogs::SearchState{
|
auto state = Dialogs::SearchState{
|
||||||
|
|
|
@ -2722,7 +2722,9 @@ std::optional<RecentHashtagPack> Account::saveRecentHashtags(
|
||||||
auto found = false;
|
auto found = false;
|
||||||
auto m = QRegularExpressionMatch();
|
auto m = QRegularExpressionMatch();
|
||||||
auto recent = getPack();
|
auto recent = getPack();
|
||||||
for (auto i = 0, next = 0; (m = TextUtilities::RegExpHashtag(false).match(text, i)).hasMatch(); i = next) {
|
for (auto i = 0, next = 0
|
||||||
|
; (m = TextUtilities::RegExpHashtag(false).match(text, i)).hasMatch()
|
||||||
|
; i = next) {
|
||||||
i = m.capturedStart();
|
i = m.capturedStart();
|
||||||
next = m.capturedEnd();
|
next = m.capturedEnd();
|
||||||
if (m.hasMatch()) {
|
if (m.hasMatch()) {
|
||||||
|
|
|
@ -580,6 +580,8 @@ void SessionNavigation::showPeerByLinkResolved(
|
||||||
params);
|
params);
|
||||||
} else if (resolveType == ResolveType::Profile) {
|
} else if (resolveType == ResolveType::Profile) {
|
||||||
showPeerInfo(peer, params);
|
showPeerInfo(peer, params);
|
||||||
|
} else if (resolveType == ResolveType::HashtagSearch) {
|
||||||
|
searchMessages(info.text, peer->owner().history(peer));
|
||||||
} else if (peer->isForum() && resolveType != ResolveType::Boost) {
|
} else if (peer->isForum() && resolveType != ResolveType::Boost) {
|
||||||
const auto itemId = info.messageId;
|
const auto itemId = info.messageId;
|
||||||
if (!itemId) {
|
if (!itemId) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ enum class ResolveType {
|
||||||
BotStart,
|
BotStart,
|
||||||
AddToGroup,
|
AddToGroup,
|
||||||
AddToChannel,
|
AddToChannel,
|
||||||
|
HashtagSearch,
|
||||||
ShareGame,
|
ShareGame,
|
||||||
Mention,
|
Mention,
|
||||||
Boost,
|
Boost,
|
||||||
|
|
Loading…
Add table
Reference in a new issue