2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Use color index from API.

This commit is contained in:
John Preston
2023-10-16 13:52:08 +04:00
parent f90a010b84
commit 4b6107fa56
26 changed files with 282 additions and 149 deletions

View File

@@ -59,8 +59,8 @@ using UpdateFlag = Data::PeerUpdate::Flag;
namespace Data {
int PeerColorIndex(PeerId peerId) {
return Ui::EmptyUserpic::ColorIndex(peerId.value & PeerId::kChatTypeMask);
uint8 DecideColorIndex(PeerId peerId) {
return Ui::DecideColorIndex(peerId.value & PeerId::kChatTypeMask);
}
PeerId FakePeerIdForJustName(const QString &name) {
@@ -230,7 +230,7 @@ not_null<Ui::EmptyUserpic*> PeerData::ensureEmptyUserpic() const {
if (!_userpicEmpty) {
const auto user = asUser();
_userpicEmpty = std::make_unique<Ui::EmptyUserpic>(
Ui::EmptyUserpic::UserpicColor(Data::PeerColorIndex(id)),
Ui::EmptyUserpic::UserpicColor(colorIndex()),
((user && user->isInaccessible())
? Ui::EmptyUserpic::InaccessibleName()
: name()));
@@ -251,7 +251,7 @@ void PeerData::setUserpic(
const ImageLocation &location,
bool hasVideo) {
_userpicPhotoId = photoId;
_userpicHasVideo = hasVideo;
_userpicHasVideo = hasVideo ? 1 : 0;
_userpic.set(&session(), ImageWithLocation{ .location = location });
}
@@ -389,6 +389,22 @@ QImage PeerData::generateUserpicImage(
return result;
}
ImageLocation PeerData::userpicLocation() const {
return _userpic.location();
}
bool PeerData::userpicPhotoUnknown() const {
return (_userpicPhotoId == kUnknownPhotoId);
}
PhotoId PeerData::userpicPhotoId() const {
return userpicPhotoUnknown() ? 0 : _userpicPhotoId;
}
bool PeerData::userpicHasVideo() const {
return _userpicHasVideo != 0;
}
Data::FileOrigin PeerData::userpicOrigin() const {
return Data::FileOriginPeerPhoto(id);
}
@@ -428,7 +444,7 @@ void PeerData::setUserpicChecked(
bool hasVideo) {
if (_userpicPhotoId != photoId
|| _userpic.location() != location
|| _userpicHasVideo != hasVideo) {
|| _userpicHasVideo != (hasVideo ? 1 : 0)) {
const auto known = !userpicPhotoUnknown();
setUserpic(photoId, location, hasVideo);
session().changes().peerUpdated(this, UpdateFlag::Photo);
@@ -818,6 +834,15 @@ QString PeerData::userName() const {
return QString();
}
bool PeerData::changeColorIndex(uint8 index) {
index %= Ui::kColorIndexCount;
if (_colorIndex == index) {
return false;
}
_colorIndex = index;
return true;
}
bool PeerData::isSelf() const {
if (const auto user = asUser()) {
return (user->flags() & UserDataFlag::Self);