Implement nice confcall bar text.

This commit is contained in:
John Preston 2025-05-07 22:09:41 +04:00
parent ae1711a685
commit 180e663a43
2 changed files with 90 additions and 25 deletions

View file

@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_group_call.h" #include "data/data_group_call.h"
#include "data/data_peer.h" #include "data/data_peer.h"
#include "data/data_changes.h" #include "data/data_changes.h"
#include "data/data_session.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "base/timer.h" #include "base/timer.h"
@ -580,7 +581,11 @@ void TopBar::initBlobsUnder(
void TopBar::subscribeToMembersChanges(not_null<GroupCall*> call) { void TopBar::subscribeToMembersChanges(not_null<GroupCall*> call) {
const auto peer = call->peer(); const auto peer = call->peer();
peer->session().changes().peerFlagsValue( const auto group = _groupCall.get();
const auto conference = group && group->conference();
auto realValue = conference
? (rpl::single(group->conferenceCall().get()) | rpl::type_erased())
: peer->session().changes().peerFlagsValue(
peer, peer,
Data::PeerUpdate::Flag::GroupCall Data::PeerUpdate::Flag::GroupCall
) | rpl::map([=] { ) | rpl::map([=] {
@ -588,20 +593,21 @@ void TopBar::subscribeToMembersChanges(not_null<GroupCall*> call) {
}) | rpl::filter([=](Data::GroupCall *real) { }) | rpl::filter([=](Data::GroupCall *real) {
const auto call = _groupCall.get(); const auto call = _groupCall.get();
return call && real && (real->id() == call->id()); return call && real && (real->id() == call->id());
}) | rpl::take( }) | rpl::take(1);
1 std::move(
realValue
) | rpl::before_next([=](not_null<Data::GroupCall*> real) { ) | rpl::before_next([=](not_null<Data::GroupCall*> real) {
real->titleValue() | rpl::start_with_next([=] { real->titleValue() | rpl::start_with_next([=] {
updateInfoLabels(); updateInfoLabels();
}, lifetime()); }, lifetime());
}) | rpl::map([=](not_null<Data::GroupCall*> real) { }) | rpl::map([=](not_null<Data::GroupCall*> real) {
return HistoryView::GroupCallBarContentByCall( return HistoryView::GroupCallBarContentByCall(
real, real,
st::groupCallTopBarUserpics.size); st::groupCallTopBarUserpics.size);
}) | rpl::flatten_latest( }) | rpl::flatten_latest(
) | rpl::filter([=](const Ui::GroupCallBarContent &content) { ) | rpl::filter([=](const Ui::GroupCallBarContent &content) {
if (_users.size() != content.users.size()) { if (_users.size() != content.users.size()
|| (conference && _usersCount != content.count)) {
return true; return true;
} }
for (auto i = 0, count = int(_users.size()); i != count; ++i) { for (auto i = 0, count = int(_users.size()); i != count; ++i) {
@ -613,10 +619,14 @@ void TopBar::subscribeToMembersChanges(not_null<GroupCall*> call) {
return false; return false;
}) | rpl::start_with_next([=](const Ui::GroupCallBarContent &content) { }) | rpl::start_with_next([=](const Ui::GroupCallBarContent &content) {
_users = content.users; _users = content.users;
_usersCount = content.count;
for (auto &user : _users) { for (auto &user : _users) {
user.speaking = false; user.speaking = false;
} }
_userpics->update(_users, !isHidden()); _userpics->update(_users, !isHidden());
if (conference) {
updateInfoLabels();
}
}, lifetime()); }, lifetime());
_userpics->widthValue( _userpics->widthValue(
@ -655,15 +665,63 @@ void TopBar::setInfoLabels() {
} else if (const auto group = _groupCall.get()) { } else if (const auto group = _groupCall.get()) {
const auto peer = group->peer(); const auto peer = group->peer();
const auto real = peer->groupCall(); const auto real = peer->groupCall();
const auto connecting = _isGroupConnecting.current();
if (!group->conference()) {
_shortInfoLabel.destroy();
}
if (!group->conference() || connecting) {
const auto name = peer->name(); const auto name = peer->name();
const auto title = (real && real->id() == group->id())
? real->title()
: QString();
const auto text = _isGroupConnecting.current() const auto text = _isGroupConnecting.current()
? tr::lng_group_call_connecting(tr::now) ? tr::lng_group_call_connecting(tr::now)
: (real && real->id() == group->id() && !real->title().isEmpty()) : !title.isEmpty()
? real->title() ? title
: name; : name;
_fullInfoLabel->setText(text); _fullInfoLabel->setText(text);
if (_shortInfoLabel) {
_shortInfoLabel->setText(text); _shortInfoLabel->setText(text);
} }
} else if (!_usersCount
|| _users.empty()
|| (_users.size() == 1
&& _users.front().id == peer->session().userPeerId().value
&& _usersCount == 1)) {
_fullInfoLabel->setText(tr::lng_confcall_join_title(tr::now));
_shortInfoLabel->setText(tr::lng_confcall_join_title(tr::now));
} else {
const auto textWithUserpics = [&](int userpics) {
const auto other = std::max(_usersCount - userpics, 0);
auto names = QStringList();
for (const auto &entry : _users) {
const auto user = peer->owner().peer(PeerId(entry.id));
names.push_back(user->shortName());
if (names.size() >= userpics) {
break;
}
}
if (other > 0) {
return tr::lng_forwarding_from(
tr::now,
lt_count,
other,
lt_user,
names.join(u", "_q));
} else if (userpics > 1) {
return tr::lng_forwarding_from_two(
tr::now,
lt_user,
names.mid(0, userpics - 1).join(u", "_q),
lt_second_user,
names.back());
}
return names.back();
};
_fullInfoLabel->setText(textWithUserpics(int(_users.size())));
_shortInfoLabel->setText(textWithUserpics(1));
}
}
} }
void TopBar::setMuted(bool mute) { void TopBar::setMuted(bool mute) {
@ -732,10 +790,8 @@ void TopBar::updateControlsGeometry() {
height()); height());
auto fullWidth = _fullInfoLabel->textMaxWidth(); auto fullWidth = _fullInfoLabel->textMaxWidth();
auto showFull = (left + fullWidth + right <= width()); auto showFull = !_shortInfoLabel
_fullInfoLabel->setVisible(showFull); || (left + fullWidth + right <= width());
_shortInfoLabel->setVisible(!showFull);
auto setInfoLabelGeometry = [this, left, right](auto &&infoLabel) { auto setInfoLabelGeometry = [this, left, right](auto &&infoLabel) {
auto minPadding = qMax(left, right); auto minPadding = qMax(left, right);
auto infoWidth = infoLabel->textMaxWidth(); auto infoWidth = infoLabel->textMaxWidth();
@ -746,8 +802,13 @@ void TopBar::updateControlsGeometry() {
} }
infoLabel->setGeometryToLeft(infoLeft, st::callBarLabelTop, infoWidth, st::callBarInfoLabel.style.font->height); infoLabel->setGeometryToLeft(infoLeft, st::callBarLabelTop, infoWidth, st::callBarInfoLabel.style.font->height);
}; };
_fullInfoLabel->setVisible(showFull);
setInfoLabelGeometry(_fullInfoLabel); setInfoLabelGeometry(_fullInfoLabel);
if (_shortInfoLabel) {
_shortInfoLabel->setVisible(!showFull);
setInfoLabelGeometry(_shortInfoLabel); setInfoLabelGeometry(_shortInfoLabel);
}
_gradients.set_points( _gradients.set_points(
QPointF(0, st::callBarHeight / 2), QPointF(0, st::callBarHeight / 2),

View file

@ -85,6 +85,7 @@ private:
bool _muted = false; bool _muted = false;
std::vector<Ui::GroupCallUser> _users; std::vector<Ui::GroupCallUser> _users;
int _usersCount = 0;
std::unique_ptr<Ui::GroupCallUserpics> _userpics; std::unique_ptr<Ui::GroupCallUserpics> _userpics;
int _userpicsWidth = 0; int _userpicsWidth = 0;
object_ptr<Ui::LabelSimple> _durationLabel; object_ptr<Ui::LabelSimple> _durationLabel;
@ -99,6 +100,9 @@ private:
rpl::variable<bool> _isGroupConnecting = false; rpl::variable<bool> _isGroupConnecting = false;
std::vector<not_null<PeerData*>> _conferenceFirstUsers;
int _conferenceUsersCount = 0;
QBrush _groupBrush; QBrush _groupBrush;
anim::linear_gradients<BarState> _gradients; anim::linear_gradients<BarState> _gradients;
Ui::Animations::Simple _switchStateAnimation; Ui::Animations::Simple _switchStateAnimation;