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
+1 -1
View File
@@ -686,7 +686,7 @@ QString ApiWrap::exportDirectMessageLink(
}
}
const auto base = linkChannel->hasUsername()
? linkChannel->username
? linkChannel->username()
: "c/" + QString::number(peerToChannel(linkChannel->id).bare);
const auto query = base
+ '/'
@@ -847,7 +847,7 @@ SetupChannelBox::SetupChannelBox(
this,
st::setupChannelLink,
nullptr,
channel->username,
channel->username(),
channel->session().createInternalLink(QString()))
, _checkTimer([=] { check(); }) {
}
@@ -1176,7 +1176,7 @@ void SetupChannelBox::check() {
)).done([=](const MTPBool &result) {
_checkRequestId = 0;
_errorText = (mtpIsTrue(result)
|| _checkUsername == _channel->username)
|| _checkUsername == _channel->username())
? QString()
: tr::lng_create_channel_link_occupied(tr::now);
_goodText = _errorText.isEmpty()
@@ -1238,7 +1238,7 @@ SetupChannelBox::UsernameResult SetupChannelBox::parseError(
void SetupChannelBox::updateFail(UsernameResult result) {
if ((result == UsernameResult::Ok)
|| (_sentUsername == _channel->username)) {
|| (_sentUsername == _channel->username())) {
_channel->setName(
TextUtilities::SingleLine(_channel->name()),
TextUtilities::SingleLine(_sentUsername));
@@ -1272,7 +1272,7 @@ void SetupChannelBox::checkFail(UsernameResult result) {
_errorText = tr::lng_create_channel_link_invalid(tr::now);
update();
} else if ((result == UsernameResult::Occupied)
&& _checkUsername != _channel->username) {
&& _checkUsername != _channel->username()) {
_errorText = tr::lng_create_channel_link_occupied(tr::now);
update();
} else {
@@ -715,7 +715,7 @@ void Controller::fillPrivacyTypeButton() {
? Privacy::HasUsername
: Privacy::NoUsername),
.username = (_peer->isChannel()
? _peer->asChannel()->username
? _peer->asChannel()->username()
: QString()),
.noForwards = !_peer->allowsForwarding(),
.joinToWrite = (_peer->isMegagroup()
@@ -1420,7 +1420,7 @@ void Controller::cancelSave() {
void Controller::saveUsername() {
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) {
return continueSave();
} else if (!channel) {
@@ -1517,7 +1517,7 @@ void Controller::saveTitle() {
if (type == qstr("CHAT_NOT_MODIFIED")
|| type == qstr("CHAT_TITLE_NOT_MODIFIED")) {
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()) {
chat->setName(*_savingData.title);
}
@@ -173,7 +173,7 @@ Controller::Controller(
, _isGroup(_peer->isChat() || _peer->isMegagroup())
, _goodUsername(_dataSavedValue
? !_dataSavedValue->username.isEmpty()
: (_peer->isChannel() && !_peer->asChannel()->username.isEmpty()))
: (_peer->isChannel() && !_peer->asChannel()->username().isEmpty()))
, _wrap(container)
, _checkUsernameTimer([=] { checkUsernameAvailability(); }) {
_peer->updateFull();
@@ -408,7 +408,7 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
const auto channel = _peer->asChannel();
const auto username = (!_dataSavedValue || !channel)
? QString()
: channel->username;
: channel->username();
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
_wrap,
@@ -535,7 +535,7 @@ void Controller::checkUsernameAvailability() {
_api.request(_checkUsernameRequestId).cancel();
}
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(
channel ? channel->inputChannel : MTP_inputChannelEmpty(),
MTP_string(checking)
@@ -608,7 +608,8 @@ void SettingsBox(
const auto lookupLink = [=] {
if (const auto group = peer->asMegagroup()) {
return group->hasUsername()
? group->session().createInternalLinkFull(group->username)
? group->session().createInternalLinkFull(
group->username())
: group->inviteLink();
} else if (const auto chat = peer->asChat()) {
return chat->inviteLink();
@@ -101,6 +101,16 @@ void ChannelData::setName(
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) {
access = accessHash;
input = MTP_inputPeerChannel(
+5 -2
View File
@@ -146,6 +146,7 @@ public:
ChannelData(not_null<Data::Session*> owner, PeerId id);
void setName(const QString &name, const QString &username);
void setUsername(const QString &username);
void setPhoto(const MTPChatPhoto &photo);
void setAccessHash(uint64 accessHash);
@@ -159,6 +160,8 @@ public:
return _flags.value();
}
[[nodiscard]] QString username() const;
[[nodiscard]] int membersCount() const {
return std::max(_membersCount, 1);
}
@@ -435,8 +438,6 @@ public:
MTPinputChannel inputChannel = MTP_inputChannelEmpty();
QString username;
int32 date = 0;
std::unique_ptr<MegagroupInfo> mgInfo;
@@ -459,6 +460,8 @@ private:
PtsWaiter _ptsWaiter;
QString _username;
int _membersCount = -1;
int _adminsCount = 1;
int _restrictedCount = 0;
+5 -5
View File
@@ -202,7 +202,7 @@ void PeerData::updateNameDelayed(
return;
}
} else if (isChannel()) {
if (asChannel()->username == newUsername) {
if (asChannel()->username() == newUsername) {
return;
}
} else if (isChat()) {
@@ -226,8 +226,8 @@ void PeerData::updateNameDelayed(
}
asUser()->setNameOrPhone(newNameOrPhone);
} else if (isChannel()) {
if (asChannel()->username != newUsername) {
asChannel()->username = newUsername;
if (asChannel()->username() != newUsername) {
asChannel()->setUsername(newUsername);
if (newUsername.isEmpty()) {
asChannel()->removeFlags(ChannelDataFlag::Username);
} else {
@@ -648,7 +648,7 @@ void PeerData::fillNames() {
}
}
} else if (const auto channel = asChannel()) {
appendToIndex(channel->username);
appendToIndex(channel->username());
}
auto toIndex = toIndexList.join(' ');
toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
@@ -822,7 +822,7 @@ QString PeerData::userName() const {
if (const auto user = asUser()) {
return user->username;
} else if (const auto channel = asChannel()) {
return channel->username;
return channel->username();
}
return QString();
}