Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(message size): Replaced TOX_MAX_*_LENGTH with API calls.
Browse files Browse the repository at this point in the history
It is good for flexibility to have fewer hardcoded values.
  • Loading branch information
yurivict committed May 11, 2017
1 parent 7f006b3 commit 3963d3c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ QString Core::getFriendRequestErrorMessage(const ToxId& friendId, const QString&
"Error while sending friendship request");
}

if (message.length() > TOX_MAX_FRIEND_REQUEST_LENGTH) {
if (message.length() > static_cast<int>(tox_max_friend_request_length())) {
return tr("Your message is too long!", "Error while sending friendship request");
}

Expand Down Expand Up @@ -1098,7 +1098,7 @@ uint32_t Core::getGroupNumberPeers(int groupId) const
*/
QString Core::getGroupPeerName(int groupId, int peerId) const
{
uint8_t nameArray[TOX_MAX_NAME_LENGTH];
uint8_t nameArray[tox_max_name_length()];
TOX_ERR_CONFERENCE_PEER_QUERY error;
size_t length = tox_conference_peer_get_name_size(tox, groupId, peerId, &error);
if (!parsePeerQueryError(error)) {
Expand Down Expand Up @@ -1159,7 +1159,8 @@ QStringList Core::getGroupPeerNames(int groupId) const

QStringList names;
for (uint32_t i = 0; i < nPeers; ++i) {
uint8_t name[TOX_MAX_NAME_LENGTH] = {0};
uint8_t name[tox_max_name_length()];
memset(name, 0, tox_max_name_length());
size_t length = tox_conference_peer_get_name_size(tox, groupId, i, &error);
bool ok = tox_conference_peer_get_name(tox, groupId, i, name, &error);
if (ok && parsePeerQueryError(error)) {
Expand Down Expand Up @@ -1408,7 +1409,7 @@ QString Core::getPeerName(const ToxPk& id) const
return name;
}

uint8_t* cname = new uint8_t[nameSize < TOX_MAX_NAME_LENGTH ? TOX_MAX_NAME_LENGTH : nameSize];
uint8_t* cname = new uint8_t[nameSize < tox_max_name_length() ? tox_max_name_length() : nameSize];
if (!tox_friend_get_name(tox, friendId, cname, nullptr)) {
qWarning() << "getPeerName: Can't get name of friend " + QString().setNum(friendId);
delete[] cname;
Expand Down
4 changes: 2 additions & 2 deletions src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ void ChatForm::dropEvent(QDropEvent* ev)
QFile file(info.absoluteFilePath());

QString urlString = url.toString();
if (url.isValid() && !url.isLocalFile() && urlString.length() < TOX_MAX_MESSAGE_LENGTH) {
if (url.isValid() && !url.isLocalFile() && urlString.length() < static_cast<int>(tox_max_message_length())) {
SendMessageStr(urlString);
continue;
}
Expand Down Expand Up @@ -949,7 +949,7 @@ void ChatForm::SendMessageStr(QString msg)
msg.remove(0, ACTION_PREFIX.length());
}

QStringList splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
QStringList splittedMsg = Core::splitMessage(msg, tox_max_message_length());
QDateTime timestamp = QDateTime::currentDateTime();

for (const QString& part : splittedMsg) {
Expand Down
4 changes: 2 additions & 2 deletions src/widget/form/profileform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ ProfileForm::ProfileForm(QWidget* parent)
core = Core::getInstance();

bodyUI->userNameLabel->setToolTip(tr("Tox user names cannot exceed %1 characters.")
.arg(TOX_MAX_NAME_LENGTH));
bodyUI->userName->setMaxLength(TOX_MAX_NAME_LENGTH);
.arg(tox_max_name_length()));
bodyUI->userName->setMaxLength(tox_max_name_length());

// tox
toxId = new ClickableTE();
Expand Down
2 changes: 1 addition & 1 deletion src/widget/friendwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void FriendWidget::mouseMoveEvent(QMouseEvent* ev)

void FriendWidget::setAlias(const QString& _alias)
{
QString alias = _alias.left(128); // same as TOX_MAX_NAME_LENGTH
QString alias = _alias.left(tox_max_name_length());
Friend* f = FriendList::findFriend(friendId);
f->setAlias(alias);
Settings::getInstance().setFriendAlias(f->getPublicKey(), alias);
Expand Down

0 comments on commit 3963d3c

Please sign in to comment.