mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use correct string for reacted / seen item.
This commit is contained in:
parent
ecedce0c2f
commit
74a28ffdf7
3 changed files with 78 additions and 4 deletions
|
@ -52,12 +52,14 @@ inline bool operator==(
|
||||||
struct PeersWithReactions {
|
struct PeersWithReactions {
|
||||||
std::vector<PeerWithReaction> list;
|
std::vector<PeerWithReaction> list;
|
||||||
int fullReactionsCount = 0;
|
int fullReactionsCount = 0;
|
||||||
|
int fullReadCount = 0;
|
||||||
bool unknown = false;
|
bool unknown = false;
|
||||||
};
|
};
|
||||||
inline bool operator==(
|
inline bool operator==(
|
||||||
const PeersWithReactions &a,
|
const PeersWithReactions &a,
|
||||||
const PeersWithReactions &b) noexcept {
|
const PeersWithReactions &b) noexcept {
|
||||||
return (a.fullReactionsCount == b.fullReactionsCount)
|
return (a.fullReactionsCount == b.fullReactionsCount)
|
||||||
|
&& (a.fullReadCount == b.fullReadCount)
|
||||||
&& (a.list == b.list)
|
&& (a.list == b.list)
|
||||||
&& (a.unknown == b.unknown);
|
&& (a.unknown == b.unknown);
|
||||||
}
|
}
|
||||||
|
@ -249,6 +251,7 @@ struct State {
|
||||||
.list = peers.list | ranges::views::transform([](PeerId peer) {
|
.list = peers.list | ranges::views::transform([](PeerId peer) {
|
||||||
return PeerWithReaction{.peer = peer };
|
return PeerWithReaction{.peer = peer };
|
||||||
}) | ranges::to_vector,
|
}) | ranges::to_vector,
|
||||||
|
.fullReadCount = int(peers.list.size()),
|
||||||
.unknown = peers.unknown,
|
.unknown = peers.unknown,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -324,6 +327,7 @@ struct State {
|
||||||
return PeersWithReactions{ .unknown = true };
|
return PeersWithReactions{ .unknown = true };
|
||||||
}
|
}
|
||||||
auto &list = reacted.list;
|
auto &list = reacted.list;
|
||||||
|
reacted.fullReadCount = int(read.list.size());
|
||||||
for (const auto &peer : read.list) {
|
for (const auto &peer : read.list) {
|
||||||
if (!ranges::contains(list, peer, &PeerWithReaction::peer)) {
|
if (!ranges::contains(list, peer, &PeerWithReaction::peer)) {
|
||||||
list.push_back({ .peer = peer });
|
list.push_back({ .peer = peer });
|
||||||
|
@ -540,10 +544,12 @@ rpl::producer<Ui::WhoReadContent> WhoReacted(
|
||||||
consumer.put_next(Ui::WhoReadContent{
|
consumer.put_next(Ui::WhoReadContent{
|
||||||
.type = state->current.type,
|
.type = state->current.type,
|
||||||
.fullReactionsCount = state->current.fullReactionsCount,
|
.fullReactionsCount = state->current.fullReactionsCount,
|
||||||
|
.fullReadCount = state->current.fullReadCount,
|
||||||
.unknown = true,
|
.unknown = true,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
state->current.fullReadCount = peers.fullReadCount;
|
||||||
state->current.fullReactionsCount = peers.fullReactionsCount;
|
state->current.fullReactionsCount = peers.fullReactionsCount;
|
||||||
if (UpdateUserpics(state, item, peers.list)) {
|
if (UpdateUserpics(state, item, peers.list)) {
|
||||||
RegenerateParticipants(state, small, large);
|
RegenerateParticipants(state, small, large);
|
||||||
|
|
|
@ -16,6 +16,54 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
|
namespace Lang {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct StringWithReacted {
|
||||||
|
QString text;
|
||||||
|
int seen = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
template <typename ResultString>
|
||||||
|
struct StartReplacements;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct StartReplacements<StringWithReacted> {
|
||||||
|
static inline StringWithReacted Call(QString &&langString) {
|
||||||
|
return { std::move(langString) };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename ResultString>
|
||||||
|
struct ReplaceTag;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct ReplaceTag<StringWithReacted> {
|
||||||
|
static StringWithReacted Call(
|
||||||
|
StringWithReacted &&original,
|
||||||
|
ushort tag,
|
||||||
|
const StringWithReacted &replacement);
|
||||||
|
};
|
||||||
|
|
||||||
|
StringWithReacted ReplaceTag<StringWithReacted>::Call(
|
||||||
|
StringWithReacted &&original,
|
||||||
|
ushort tag,
|
||||||
|
const StringWithReacted &replacement) {
|
||||||
|
const auto offset = FindTagReplacementPosition(original.text, tag);
|
||||||
|
if (offset < 0) {
|
||||||
|
return std::move(original);
|
||||||
|
}
|
||||||
|
original.text = ReplaceTag<QString>::Call(
|
||||||
|
std::move(original.text),
|
||||||
|
tag,
|
||||||
|
replacement.text + '/' + QString::number(original.seen));
|
||||||
|
return std::move(original);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Lang
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -80,6 +128,18 @@ TextParseOptions MenuTextOptions = {
|
||||||
Qt::LayoutDirectionAuto, // dir
|
Qt::LayoutDirectionAuto, // dir
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] QString FormatReactedString(int reacted, int seen) {
|
||||||
|
const auto projection = [&](const QString &text) {
|
||||||
|
return Lang::StringWithReacted{ text, seen };
|
||||||
|
};
|
||||||
|
return tr::lng_context_seen_reacted(
|
||||||
|
tr::now,
|
||||||
|
lt_count_short,
|
||||||
|
reacted,
|
||||||
|
projection
|
||||||
|
).text;
|
||||||
|
}
|
||||||
|
|
||||||
Action::Action(
|
Action::Action(
|
||||||
not_null<PopupMenu*> parentMenu,
|
not_null<PopupMenu*> parentMenu,
|
||||||
rpl::producer<WhoReadContent> content,
|
rpl::producer<WhoReadContent> content,
|
||||||
|
@ -177,10 +237,12 @@ void Action::resolveMinWidth() {
|
||||||
? tr::lng_context_seen_text(tr::now, lt_count, 999)
|
? tr::lng_context_seen_text(tr::now, lt_count, 999)
|
||||||
: QString();
|
: QString();
|
||||||
const auto maxReacted = (_content.fullReactionsCount > 0)
|
const auto maxReacted = (_content.fullReactionsCount > 0)
|
||||||
? tr::lng_context_seen_reacted(
|
? (!maxText.isEmpty()
|
||||||
tr::now,
|
? FormatReactedString(_content.fullReactionsCount, 999)
|
||||||
lt_count_short,
|
: tr::lng_context_seen_reacted(
|
||||||
_content.fullReactionsCount)
|
tr::now,
|
||||||
|
lt_count_short,
|
||||||
|
_content.fullReactionsCount))
|
||||||
: QString();
|
: QString();
|
||||||
const auto maxTextWidth = std::max(width(maxText), width(maxReacted));
|
const auto maxTextWidth = std::max(width(maxText), width(maxReacted));
|
||||||
const auto maxWidth = st::defaultWhoRead.itemPadding.left()
|
const auto maxWidth = st::defaultWhoRead.itemPadding.left()
|
||||||
|
@ -297,6 +359,11 @@ void Action::refreshText() {
|
||||||
? tr::lng_context_seen_loading(tr::now)
|
? tr::lng_context_seen_loading(tr::now)
|
||||||
: (usersCount == 1)
|
: (usersCount == 1)
|
||||||
? _content.participants.front().name
|
? _content.participants.front().name
|
||||||
|
: (_content.fullReactionsCount > 0
|
||||||
|
&& _content.fullReactionsCount <= _content.fullReadCount)
|
||||||
|
? FormatReactedString(
|
||||||
|
_content.fullReactionsCount,
|
||||||
|
_content.fullReadCount)
|
||||||
: (_content.type == WhoReadType::Reacted
|
: (_content.type == WhoReadType::Reacted
|
||||||
|| (count > 0 && _content.fullReactionsCount > usersCount))
|
|| (count > 0 && _content.fullReactionsCount > usersCount))
|
||||||
? (count
|
? (count
|
||||||
|
|
|
@ -42,6 +42,7 @@ struct WhoReadContent {
|
||||||
WhoReadType type = WhoReadType::Seen;
|
WhoReadType type = WhoReadType::Seen;
|
||||||
QString singleReaction;
|
QString singleReaction;
|
||||||
int fullReactionsCount = 0;
|
int fullReactionsCount = 0;
|
||||||
|
int fullReadCount = 0;
|
||||||
bool unknown = false;
|
bool unknown = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue