Use a detailed phrase for single user join request.

This commit is contained in:
John Preston 2021-10-19 19:53:37 +04:00
parent 05bdef041b
commit c9e5eadb06
4 changed files with 52 additions and 7 deletions

View File

@ -1342,6 +1342,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_group_request_sent_channel" = "You will be added to the channel once its admins approve your request.";
"lng_group_requests_pending#one" = "{count} user requested to join";
"lng_group_requests_pending#other" = "{count} users requested to join";
"lng_group_requests_pending_user" = "{user} requested to join";
"lng_group_requests_status" = "requested to join {date}";
"lng_group_requests_add" = "Add to Group";
"lng_group_requests_add_channel" = "Add to Channel";

View File

@ -137,9 +137,9 @@ rpl::producer<Ui::RequestsBarContent> RequestsBarContentByPeer(
result.match([&](
const MTPDmessages_chatInviteImporters &data) {
const auto count = data.vcount().v;
const auto changed = (state->current.count != count);
const auto &importers = data.vimporters().v;
auto &owner = state->peer->owner();
const auto old = base::take(state->users);
state->users = std::vector<not_null<UserData*>>();
const auto use = std::min(
importers.size(),
@ -152,8 +152,22 @@ rpl::producer<Ui::RequestsBarContent> RequestsBarContentByPeer(
owner.user(data.vuser_id()));
});
}
const auto changed = (state->current.count != count)
|| (count == 1
&& ((state->users.size() != old.size())
|| (old.size() == 1
&& state->users.front() != old.front())));
if (changed) {
state->current.count = count;
if (count == 1 && !state->users.empty()) {
const auto user = state->users.front();
state->current.nameShort = user->shortName();
state->current.nameFull = user->name;
} else {
state->current.nameShort
= state->current.nameFull
= QString();
}
}
if (RegenerateUserpics(state, userpicSize) || changed) {
push();

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/group_call_userpics.h"
#include "ui/widgets/shadow.h"
#include "ui/text/text_options.h"
#include "lang/lang_keys.h"
#include "styles/style_chat.h"
#include "styles/style_calls.h"
@ -47,10 +48,31 @@ RequestsBar::RequestsBar(
) | rpl::start_with_next([=](RequestsBarContent &&content) {
_content = content;
if (_content.count > 0) {
_text = tr::lng_group_requests_pending(
tr::now,
lt_count_decimal,
_content.count);
if (_content.count == 1 && !_content.nameFull.isEmpty()) {
_textFull.setText(
st::defaultMessageBar.title,
tr::lng_group_requests_pending_user(
tr::now,
lt_user,
_content.nameFull),
Ui::NameTextOptions());
_textShort.setText(
st::defaultMessageBar.title,
tr::lng_group_requests_pending_user(
tr::now,
lt_user,
_content.nameShort),
Ui::NameTextOptions());
} else {
_textShort.setText(
st::defaultMessageBar.title,
tr::lng_group_requests_pending(
tr::now,
lt_count_decimal,
_content.count),
Ui::NameTextOptions());
_textFull.clear();
}
}
_userpics->update(_content.users, !_wrap.isHidden());
_inner->update();
@ -131,7 +153,11 @@ void RequestsBar::paint(Painter &p) {
const auto textLeft = userpicsLeft + _userpicsWidth + userpicsLeft;
const auto available = width - textLeft - userpicsLeft;
p.drawTextLeft(textLeft, textTop, width, _text);
if (_textFull.isEmpty() || available < _textFull.maxWidth()) {
_textShort.drawElided(p, textLeft, textTop, available);
} else {
_textFull.drawElided(p, textLeft, textTop, available);
}
// Skip shadow of the bar above.
_userpics->paint(p, userpicsLeft, userpicsTop, userpicsSize);

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/slide_wrap.h"
#include "ui/effects/animations.h"
#include "ui/text/text.h"
#include "base/object_ptr.h"
#include "base/timer.h"
@ -22,6 +23,8 @@ class GroupCallUserpics;
struct RequestsBarContent {
std::vector<GroupCallUser> users;
QString nameFull;
QString nameShort;
int count = 0;
bool isGroup = false;
};
@ -70,7 +73,8 @@ private:
RequestsBarContent _content;
std::unique_ptr<GroupCallUserpics> _userpics;
int _userpicsWidth = 0;
QString _text;
Ui::Text::String _textShort;
Ui::Text::String _textFull;
};