1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Code consistency fixes → 's/ToxID/ToxId/'

Since consistency in code is most important, 'ToxId' is used
for code, whereas 'Tox ID' anywhere outside of code.

Also fixed wrong comments in core.h:
* qTox gets only public key of a grouchat peer, not their
  Tox ID
* qTox tries to return full address (Tox ID) or public key
This commit is contained in:
Zetok Zalbavar 2015-05-23 19:58:41 +01:00
parent a841224683
commit 227c061ea1
No known key found for this signature in database
GPG Key ID: C953D3880212068A
14 changed files with 36 additions and 36 deletions

View File

@ -1080,20 +1080,20 @@ QString Core::getGroupPeerName(int groupId, int peerId) const
return name; return name;
} }
ToxId Core::getGroupPeerToxID(int groupId, int peerId) const ToxId Core::getGroupPeerToxId(int groupId, int peerId) const
{ {
ToxId peerToxID; ToxId peerToxId;
uint8_t rawID[TOX_PUBLIC_KEY_SIZE]; uint8_t rawID[TOX_PUBLIC_KEY_SIZE];
int res = tox_group_peer_pubkey(tox, groupId, peerId, rawID); int res = tox_group_peer_pubkey(tox, groupId, peerId, rawID);
if (res == -1) if (res == -1)
{ {
qWarning() << "getGroupPeerToxID: Unknown error"; qWarning() << "getGroupPeerToxId: Unknown error";
return peerToxID; return peerToxId;
} }
peerToxID = ToxId(CUserId::toString(rawID)); peerToxId = ToxId(CUserId::toString(rawID));
return peerToxID; return peerToxId;
} }
QList<QString> Core::getGroupPeerNames(int groupId) const QList<QString> Core::getGroupPeerNames(int groupId) const

View File

@ -61,9 +61,9 @@ public:
QVector<uint32_t> getFriendList() const; ///< Returns the list of friendIds in our friendlist, an empty list on error QVector<uint32_t> getFriendList() const; ///< Returns the list of friendIds in our friendlist, an empty list on error
int getGroupNumberPeers(int groupId) const; ///< Return the number of peers in the group chat on success, or -1 on failure int getGroupNumberPeers(int groupId) const; ///< Return the number of peers in the group chat on success, or -1 on failure
QString getGroupPeerName(int groupId, int peerId) const; ///< Get the name of a peer of a group QString getGroupPeerName(int groupId, int peerId) const; ///< Get the name of a peer of a group
ToxId getGroupPeerToxID(int groupId, int peerId) const; ///< Get the ToxID of a peer of a group ToxId getGroupPeerToxId(int groupId, int peerId) const; ///< Get the public key of a peer of a group
QList<QString> getGroupPeerNames(int groupId) const; ///< Get the names of the peers of a group QList<QString> getGroupPeerNames(int groupId) const; ///< Get the names of the peers of a group
QString getFriendAddress(uint32_t friendId) const; ///< Get the full address if known, or Tox ID of a friend QString getFriendAddress(uint32_t friendId) const; ///< Get the full address if known, or public key of a friend
QString getFriendUsername(uint32_t friendId) const; ///< Get the username of a friend QString getFriendUsername(uint32_t friendId) const; ///< Get the username of a friend
bool isFriendOnline(uint32_t friendId) const; ///< Check if a friend is online. Unknown friends are considered offline. bool isFriendOnline(uint32_t friendId) const; ///< Check if a friend is online. Unknown friends are considered offline.
bool hasFriendWithAddress(const QString &addr) const; ///< Check if we have a friend by address bool hasFriendWithAddress(const QString &addr) const; ///< Check if we have a friend by address

View File

@ -93,7 +93,7 @@ QString Friend::getDisplayedName() const
return userAlias; return userAlias;
} }
const ToxId &Friend::getToxID() const const ToxId &Friend::getToxId() const
{ {
return userID; return userID;
} }

View File

@ -44,7 +44,7 @@ public:
void setEventFlag(int f); void setEventFlag(int f);
int getEventFlag() const; int getEventFlag() const;
const ToxId &getToxID() const; const ToxId &getToxId() const;
uint32_t getFriendID() const; uint32_t getFriendID() const;
void setStatus(Status s); void setStatus(Status s);

View File

@ -54,7 +54,7 @@ void FriendList::removeFriend(int friendId, bool fake)
if (f_it != friendList.end()) if (f_it != friendList.end())
{ {
if (!fake) if (!fake)
Settings::getInstance().removeFriendSettings(f_it.value()->getToxID()); Settings::getInstance().removeFriendSettings(f_it.value()->getToxId());
friendList.erase(f_it); friendList.erase(f_it);
} }
} }
@ -74,7 +74,7 @@ Friend* FriendList::findFriend(const ToxId& userId)
Friend *f = findFriend(*id); Friend *f = findFriend(*id);
if (!f) if (!f)
return nullptr; return nullptr;
if (f->getToxID() == userId) if (f->getToxId() == userId)
return f; return f;
} }

View File

@ -66,7 +66,7 @@ void Group::removePeer(int peerId)
void Group::updatePeer(int peerId, QString name) void Group::updatePeer(int peerId, QString name)
{ {
ToxId id = Core::getInstance()->getGroupPeerToxID(groupId, peerId); ToxId id = Core::getInstance()->getGroupPeerToxId(groupId, peerId);
QString toxid = id.publicKey; QString toxid = id.publicKey;
peers[peerId] = name; peers[peerId] = name;
toxids[toxid] = name; toxids[toxid] = name;
@ -97,7 +97,7 @@ void Group::regeneratePeerList()
nPeers = peers.size(); nPeers = peers.size();
for (int i = 0; i < nPeers; i++) for (int i = 0; i < nPeers; i++)
{ {
ToxId id = Core::getInstance()->getGroupPeerToxID(groupId, i); ToxId id = Core::getInstance()->getGroupPeerToxId(groupId, i);
if (id.isActiveProfile()) if (id.isActiveProfile())
selfPeerNum = i; selfPeerNum = i;
@ -170,7 +170,7 @@ int Group::getMentionedFlag() const
return userWasMentioned; return userWasMentioned;
} }
QString Group::resolveToxID(const ToxId &id) const QString Group::resolveToxId(const ToxId &id) const
{ {
QString key = id.publicKey; QString key = id.publicKey;
auto it = toxids.find(key); auto it = toxids.find(key);

View File

@ -57,7 +57,7 @@ public:
void updatePeer(int peerId, QString newName); void updatePeer(int peerId, QString newName);
void setName(const QString& name); void setName(const QString& name);
QString resolveToxID(const ToxId &id) const; QString resolveToxId(const ToxId &id) const;
private: private:
GroupWidget* widget; GroupWidget* widget;

View File

@ -289,7 +289,7 @@ ToxId ToxDNS::resolveToxAddress(const QString &address, bool silent)
else else
{ {
#if TOX1_SILENT_FALLBACK #if TOX1_SILENT_FALLBACK
toxId = ToxID::fromString(queryTox1(address, silent)); toxId = ToxId::fromString(queryTox1(address, silent));
#elif TOX1_ASK_FALLBACK #elif TOX1_ASK_FALLBACK
QMessageBox::StandardButton btn = QMessageBox::warning(nullptr, "qTox", tr("It appears that qTox has to use the old tox1 protocol to access DNS record of your friend's Tox ID.\n\ QMessageBox::StandardButton btn = QMessageBox::warning(nullptr, "qTox", tr("It appears that qTox has to use the old tox1 protocol to access DNS record of your friend's Tox ID.\n\
Unfortunately tox1 is not secure, and you are at risk of someone hijacking what is sent between you and ToxDNS service.\n\ Unfortunately tox1 is not secure, and you are at risk of someone hijacking what is sent between you and ToxDNS service.\n\

View File

@ -43,7 +43,7 @@ public:
}; };
public: public:
/// Tries to map a text string to a ToxID struct, will query Tox DNS records if necessary /// Tries to map a text string to a ToxId struct, will query Tox DNS records if necessary
static ToxId resolveToxAddress(const QString& address, bool silent=true); static ToxId resolveToxAddress(const QString& address, bool silent=true);
static QString queryTox1(const QString& record, bool silent=true); ///< Record should look like user@domain.tld. Do *NOT* use tox1 without a good reason, it's unsafe. static QString queryTox1(const QString& record, bool silent=true); ///< Record should look like user@domain.tld. Do *NOT* use tox1 without a good reason, it's unsafe.

View File

@ -203,7 +203,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
} }
QString name; QString name;
ToxId friendId = f->getToxID(); ToxId friendId = f->getToxId();
if (friendId != previousId) if (friendId != previousId)
{ {
name = f->getDisplayedName(); name = f->getDisplayedName();
@ -213,7 +213,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
ChatMessage::Ptr msg = ChatMessage::createFileTransferMessage(name, file, false, QDateTime::currentDateTime()); ChatMessage::Ptr msg = ChatMessage::createFileTransferMessage(name, file, false, QDateTime::currentDateTime());
insertChatMessage(msg); insertChatMessage(msg);
if (!Settings::getInstance().getAutoAcceptDir(f->getToxID()).isEmpty() if (!Settings::getInstance().getAutoAcceptDir(f->getToxId()).isEmpty()
|| Settings::getInstance().getAutoSaveEnabled()) || Settings::getInstance().getAutoSaveEnabled())
{ {
ChatLineContentProxy* proxy = dynamic_cast<ChatLineContentProxy*>(msg->getContent(1)); ChatLineContentProxy* proxy = dynamic_cast<ChatLineContentProxy*>(msg->getContent(1));
@ -222,7 +222,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
FileTransferWidget* tfWidget = dynamic_cast<FileTransferWidget*>(proxy->getWidget()); FileTransferWidget* tfWidget = dynamic_cast<FileTransferWidget*>(proxy->getWidget());
if (tfWidget) if (tfWidget)
tfWidget->autoAcceptTransfer(Settings::getInstance().getAutoAcceptDir(f->getToxID())); tfWidget->autoAcceptTransfer(Settings::getInstance().getAutoAcceptDir(f->getToxId()));
} }
} }
} }
@ -792,7 +792,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
} }
} }
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now); auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxId().publicKey, since, now);
ToxId storedPrevId = previousId; ToxId storedPrevId = previousId;
ToxId prevId; ToxId prevId;
@ -814,7 +814,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
// Show each messages // Show each messages
ToxId authorId = ToxId(it.sender); ToxId authorId = ToxId(it.sender);
QString authorStr = authorId.isActiveProfile() ? Core::getInstance()->getUsername() : resolveToxID(authorId); QString authorStr = authorId.isActiveProfile() ? Core::getInstance()->getUsername() : resolveToxId(authorId);
bool isAction = it.message.startsWith("/me ", Qt::CaseInsensitive); bool isAction = it.message.startsWith("/me ", Qt::CaseInsensitive);
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
@ -1015,7 +1015,7 @@ void ChatForm::SendMessageStr(QString msg)
bool status = !Settings::getInstance().getFauxOfflineMessaging(); bool status = !Settings::getInstance().getFauxOfflineMessaging();
int id = HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, qt_msg_hist, int id = HistoryKeeper::getInstance()->addChatEntry(f->getToxId().publicKey, qt_msg_hist,
Core::getInstance()->getSelfId().publicKey, timestamp, status); Core::getInstance()->getSelfId().publicKey, timestamp, status);
ChatMessage::Ptr ma = addSelfMessage(msg, isAction, timestamp, false); ChatMessage::Ptr ma = addSelfMessage(msg, isAction, timestamp, false);

View File

@ -248,7 +248,7 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos)
ChatMessage::Ptr GenericChatForm::addMessage(const ToxId& author, const QString &message, bool isAction, ChatMessage::Ptr GenericChatForm::addMessage(const ToxId& author, const QString &message, bool isAction,
const QDateTime &datetime, bool isSent) const QDateTime &datetime, bool isSent)
{ {
QString authorStr = author.isActiveProfile() ? Core::getInstance()->getUsername() : resolveToxID(author); QString authorStr = author.isActiveProfile() ? Core::getInstance()->getUsername() : resolveToxId(author);
ChatMessage::Ptr msg; ChatMessage::Ptr msg;
if (isAction) if (isAction)
@ -281,7 +281,7 @@ ChatMessage::Ptr GenericChatForm::addSelfMessage(const QString &message, bool is
void GenericChatForm::addAlertMessage(const ToxId &author, QString message, QDateTime datetime) void GenericChatForm::addAlertMessage(const ToxId &author, QString message, QDateTime datetime)
{ {
QString authorStr = resolveToxID(author); QString authorStr = resolveToxId(author);
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, author.isActiveProfile(), datetime); ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, author.isActiveProfile(), datetime);
insertChatMessage(msg); insertChatMessage(msg);
@ -388,7 +388,7 @@ void GenericChatForm::onSelectAllClicked()
chatWidget->selectAll(); chatWidget->selectAll();
} }
QString GenericChatForm::resolveToxID(const ToxId &id) QString GenericChatForm::resolveToxId(const ToxId &id)
{ {
Friend *f = FriendList::findFriend(id); Friend *f = FriendList::findFriend(id);
if (f) if (f)
@ -399,7 +399,7 @@ QString GenericChatForm::resolveToxID(const ToxId &id)
{ {
for (auto it : GroupList::getAllGroups()) for (auto it : GroupList::getAllGroups())
{ {
QString res = it->resolveToxID(id); QString res = it->resolveToxId(id);
if (res.size()) if (res.size())
return res; return res;
} }

View File

@ -80,7 +80,7 @@ protected slots:
void hideFileMenu(); void hideFileMenu();
protected: protected:
QString resolveToxID(const ToxId &id); QString resolveToxId(const ToxId &id);
void insertChatMessage(ChatMessage::Ptr msg); void insertChatMessage(ChatMessage::Ptr msg);
void hideEvent(QHideEvent* event); void hideEvent(QHideEvent* event);
void resizeEvent(QResizeEvent* event); void resizeEvent(QResizeEvent* event);

View File

@ -51,7 +51,7 @@ FriendWidget::FriendWidget(int FriendId, QString id)
void FriendWidget::contextMenuEvent(QContextMenuEvent * event) void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
{ {
QPoint pos = event->globalPos(); QPoint pos = event->globalPos();
ToxId id = FriendList::findFriend(friendId)->getToxID(); ToxId id = FriendList::findFriend(friendId)->getToxId();
QString dir = Settings::getInstance().getAutoAcceptDir(id); QString dir = Settings::getInstance().getAutoAcceptDir(id);
QMenu menu; QMenu menu;
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat")); QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
@ -247,7 +247,7 @@ void FriendWidget::setAlias(const QString& _alias)
alias = alias.left(128); // same as TOX_MAX_NAME_LENGTH alias = alias.left(128); // same as TOX_MAX_NAME_LENGTH
Friend* f = FriendList::findFriend(friendId); Friend* f = FriendList::findFriend(friendId);
f->setAlias(alias); f->setAlias(alias);
Settings::getInstance().setFriendAlias(f->getToxID(), alias); Settings::getInstance().setFriendAlias(f->getToxId(), alias);
Settings::getInstance().save(true); Settings::getInstance().save(true);
hide(); hide();
show(); show();

View File

@ -769,10 +769,10 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
return; return;
QDateTime timestamp = QDateTime::currentDateTime(); QDateTime timestamp = QDateTime::currentDateTime();
f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp, true); f->getChatForm()->addMessage(f->getToxId(), message, isAction, timestamp, true);
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, isAction ? "/me " + f->getDisplayedName() + " " + message : message, HistoryKeeper::getInstance()->addChatEntry(f->getToxId().publicKey, isAction ? "/me " + f->getDisplayedName() + " " + message : message,
f->getToxID().publicKey, timestamp, true); f->getToxId().publicKey, timestamp, true);
f->setEventFlag(f->getFriendWidget() != activeChatroomWidget); f->setEventFlag(f->getFriendWidget() != activeChatroomWidget);
newMessageAlert(f->getFriendWidget()); newMessageAlert(f->getFriendWidget());
@ -871,7 +871,7 @@ void Widget::removeFriend(Friend* f, bool fake)
if (removeFriendMB == QMessageBox::Cancel) if (removeFriendMB == QMessageBox::Cancel)
return; return;
else if (removeFriendMB == QMessageBox::Yes) else if (removeFriendMB == QMessageBox::Yes)
HistoryKeeper::getInstance()->removeFriendHistory(f->getToxID().publicKey); HistoryKeeper::getInstance()->removeFriendHistory(f->getToxId().publicKey);
} }
f->getFriendWidget()->setAsInactiveChatroom(); f->getFriendWidget()->setAsInactiveChatroom();
@ -945,7 +945,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
if (!g) if (!g)
return; return;
ToxId author = Core::getInstance()->getGroupPeerToxID(groupnumber, peernumber); ToxId author = Core::getInstance()->getGroupPeerToxId(groupnumber, peernumber);
bool targeted = !author.isActiveProfile() && (message.contains(nameMention) || message.contains(sanitizedNameMention)); bool targeted = !author.isActiveProfile() && (message.contains(nameMention) || message.contains(sanitizedNameMention));
if (targeted && !isAction) if (targeted && !isAction)
g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime()); g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime());