Removed username from public data members of ChannelData.

This commit is contained in:
23rd 2022-10-05 13:40:31 +03:00 committed by John Preston
parent 38f5cda800
commit 9b7329b378
8 changed files with 33 additions and 19 deletions

View file

@ -686,7 +686,7 @@ QString ApiWrap::exportDirectMessageLink(
} }
} }
const auto base = linkChannel->hasUsername() const auto base = linkChannel->hasUsername()
? linkChannel->username ? linkChannel->username()
: "c/" + QString::number(peerToChannel(linkChannel->id).bare); : "c/" + QString::number(peerToChannel(linkChannel->id).bare);
const auto query = base const auto query = base
+ '/' + '/'

View file

@ -847,7 +847,7 @@ SetupChannelBox::SetupChannelBox(
this, this,
st::setupChannelLink, st::setupChannelLink,
nullptr, nullptr,
channel->username, channel->username(),
channel->session().createInternalLink(QString())) channel->session().createInternalLink(QString()))
, _checkTimer([=] { check(); }) { , _checkTimer([=] { check(); }) {
} }
@ -1176,7 +1176,7 @@ void SetupChannelBox::check() {
)).done([=](const MTPBool &result) { )).done([=](const MTPBool &result) {
_checkRequestId = 0; _checkRequestId = 0;
_errorText = (mtpIsTrue(result) _errorText = (mtpIsTrue(result)
|| _checkUsername == _channel->username) || _checkUsername == _channel->username())
? QString() ? QString()
: tr::lng_create_channel_link_occupied(tr::now); : tr::lng_create_channel_link_occupied(tr::now);
_goodText = _errorText.isEmpty() _goodText = _errorText.isEmpty()
@ -1238,7 +1238,7 @@ SetupChannelBox::UsernameResult SetupChannelBox::parseError(
void SetupChannelBox::updateFail(UsernameResult result) { void SetupChannelBox::updateFail(UsernameResult result) {
if ((result == UsernameResult::Ok) if ((result == UsernameResult::Ok)
|| (_sentUsername == _channel->username)) { || (_sentUsername == _channel->username())) {
_channel->setName( _channel->setName(
TextUtilities::SingleLine(_channel->name()), TextUtilities::SingleLine(_channel->name()),
TextUtilities::SingleLine(_sentUsername)); TextUtilities::SingleLine(_sentUsername));
@ -1272,7 +1272,7 @@ void SetupChannelBox::checkFail(UsernameResult result) {
_errorText = tr::lng_create_channel_link_invalid(tr::now); _errorText = tr::lng_create_channel_link_invalid(tr::now);
update(); update();
} else if ((result == UsernameResult::Occupied) } else if ((result == UsernameResult::Occupied)
&& _checkUsername != _channel->username) { && _checkUsername != _channel->username()) {
_errorText = tr::lng_create_channel_link_occupied(tr::now); _errorText = tr::lng_create_channel_link_occupied(tr::now);
update(); update();
} else { } else {

View file

@ -715,7 +715,7 @@ void Controller::fillPrivacyTypeButton() {
? Privacy::HasUsername ? Privacy::HasUsername
: Privacy::NoUsername), : Privacy::NoUsername),
.username = (_peer->isChannel() .username = (_peer->isChannel()
? _peer->asChannel()->username ? _peer->asChannel()->username()
: QString()), : QString()),
.noForwards = !_peer->allowsForwarding(), .noForwards = !_peer->allowsForwarding(),
.joinToWrite = (_peer->isMegagroup() .joinToWrite = (_peer->isMegagroup()
@ -1420,7 +1420,7 @@ void Controller::cancelSave() {
void Controller::saveUsername() { void Controller::saveUsername() {
const auto channel = _peer->asChannel(); const auto channel = _peer->asChannel();
const auto username = (channel ? channel->username : QString()); const auto username = (channel ? channel->username() : QString());
if (!_savingData.username || *_savingData.username == username) { if (!_savingData.username || *_savingData.username == username) {
return continueSave(); return continueSave();
} else if (!channel) { } else if (!channel) {
@ -1517,7 +1517,7 @@ void Controller::saveTitle() {
if (type == qstr("CHAT_NOT_MODIFIED") if (type == qstr("CHAT_NOT_MODIFIED")
|| type == qstr("CHAT_TITLE_NOT_MODIFIED")) { || type == qstr("CHAT_TITLE_NOT_MODIFIED")) {
if (const auto channel = _peer->asChannel()) { if (const auto channel = _peer->asChannel()) {
channel->setName(*_savingData.title, channel->username); channel->setName(*_savingData.title, channel->username());
} else if (const auto chat = _peer->asChat()) { } else if (const auto chat = _peer->asChat()) {
chat->setName(*_savingData.title); chat->setName(*_savingData.title);
} }

View file

@ -173,7 +173,7 @@ Controller::Controller(
, _isGroup(_peer->isChat() || _peer->isMegagroup()) , _isGroup(_peer->isChat() || _peer->isMegagroup())
, _goodUsername(_dataSavedValue , _goodUsername(_dataSavedValue
? !_dataSavedValue->username.isEmpty() ? !_dataSavedValue->username.isEmpty()
: (_peer->isChannel() && !_peer->asChannel()->username.isEmpty())) : (_peer->isChannel() && !_peer->asChannel()->username().isEmpty()))
, _wrap(container) , _wrap(container)
, _checkUsernameTimer([=] { checkUsernameAvailability(); }) { , _checkUsernameTimer([=] { checkUsernameAvailability(); }) {
_peer->updateFull(); _peer->updateFull();
@ -408,7 +408,7 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
const auto channel = _peer->asChannel(); const auto channel = _peer->asChannel();
const auto username = (!_dataSavedValue || !channel) const auto username = (!_dataSavedValue || !channel)
? QString() ? QString()
: channel->username; : channel->username();
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
_wrap, _wrap,
@ -535,7 +535,7 @@ void Controller::checkUsernameAvailability() {
_api.request(_checkUsernameRequestId).cancel(); _api.request(_checkUsernameRequestId).cancel();
} }
const auto channel = _peer->migrateToOrMe()->asChannel(); const auto channel = _peer->migrateToOrMe()->asChannel();
const auto username = channel ? channel->username : QString(); const auto username = channel ? channel->username() : QString();
_checkUsernameRequestId = _api.request(MTPchannels_CheckUsername( _checkUsernameRequestId = _api.request(MTPchannels_CheckUsername(
channel ? channel->inputChannel : MTP_inputChannelEmpty(), channel ? channel->inputChannel : MTP_inputChannelEmpty(),
MTP_string(checking) MTP_string(checking)

View file

@ -608,7 +608,8 @@ void SettingsBox(
const auto lookupLink = [=] { const auto lookupLink = [=] {
if (const auto group = peer->asMegagroup()) { if (const auto group = peer->asMegagroup()) {
return group->hasUsername() return group->hasUsername()
? group->session().createInternalLinkFull(group->username) ? group->session().createInternalLinkFull(
group->username())
: group->inviteLink(); : group->inviteLink();
} else if (const auto chat = peer->asChat()) { } else if (const auto chat = peer->asChat()) {
return chat->inviteLink(); return chat->inviteLink();

View file

@ -101,6 +101,16 @@ void ChannelData::setName(
updateNameDelayed(newName.isEmpty() ? name() : newName, {}, newUsername); updateNameDelayed(newName.isEmpty() ? name() : newName, {}, newUsername);
} }
void ChannelData::setUsername(const QString &username) {
if (_username != username) {
_username = username;
}
}
QString ChannelData::username() const {
return _username;
}
void ChannelData::setAccessHash(uint64 accessHash) { void ChannelData::setAccessHash(uint64 accessHash) {
access = accessHash; access = accessHash;
input = MTP_inputPeerChannel( input = MTP_inputPeerChannel(

View file

@ -146,6 +146,7 @@ public:
ChannelData(not_null<Data::Session*> owner, PeerId id); ChannelData(not_null<Data::Session*> owner, PeerId id);
void setName(const QString &name, const QString &username); void setName(const QString &name, const QString &username);
void setUsername(const QString &username);
void setPhoto(const MTPChatPhoto &photo); void setPhoto(const MTPChatPhoto &photo);
void setAccessHash(uint64 accessHash); void setAccessHash(uint64 accessHash);
@ -159,6 +160,8 @@ public:
return _flags.value(); return _flags.value();
} }
[[nodiscard]] QString username() const;
[[nodiscard]] int membersCount() const { [[nodiscard]] int membersCount() const {
return std::max(_membersCount, 1); return std::max(_membersCount, 1);
} }
@ -435,8 +438,6 @@ public:
MTPinputChannel inputChannel = MTP_inputChannelEmpty(); MTPinputChannel inputChannel = MTP_inputChannelEmpty();
QString username;
int32 date = 0; int32 date = 0;
std::unique_ptr<MegagroupInfo> mgInfo; std::unique_ptr<MegagroupInfo> mgInfo;
@ -459,6 +460,8 @@ private:
PtsWaiter _ptsWaiter; PtsWaiter _ptsWaiter;
QString _username;
int _membersCount = -1; int _membersCount = -1;
int _adminsCount = 1; int _adminsCount = 1;
int _restrictedCount = 0; int _restrictedCount = 0;

View file

@ -202,7 +202,7 @@ void PeerData::updateNameDelayed(
return; return;
} }
} else if (isChannel()) { } else if (isChannel()) {
if (asChannel()->username == newUsername) { if (asChannel()->username() == newUsername) {
return; return;
} }
} else if (isChat()) { } else if (isChat()) {
@ -226,8 +226,8 @@ void PeerData::updateNameDelayed(
} }
asUser()->setNameOrPhone(newNameOrPhone); asUser()->setNameOrPhone(newNameOrPhone);
} else if (isChannel()) { } else if (isChannel()) {
if (asChannel()->username != newUsername) { if (asChannel()->username() != newUsername) {
asChannel()->username = newUsername; asChannel()->setUsername(newUsername);
if (newUsername.isEmpty()) { if (newUsername.isEmpty()) {
asChannel()->removeFlags(ChannelDataFlag::Username); asChannel()->removeFlags(ChannelDataFlag::Username);
} else { } else {
@ -648,7 +648,7 @@ void PeerData::fillNames() {
} }
} }
} else if (const auto channel = asChannel()) { } else if (const auto channel = asChannel()) {
appendToIndex(channel->username); appendToIndex(channel->username());
} }
auto toIndex = toIndexList.join(' '); auto toIndex = toIndexList.join(' ');
toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex); toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
@ -822,7 +822,7 @@ QString PeerData::userName() const {
if (const auto user = asUser()) { if (const auto user = asUser()) {
return user->username; return user->username;
} else if (const auto channel = asChannel()) { } else if (const auto channel = asChannel()) {
return channel->username; return channel->username();
} }
return QString(); return QString();
} }