mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge branch 'pr1675'
This commit is contained in:
commit
2334add011
6
qtox.pro
6
qtox.pro
|
@ -436,7 +436,8 @@ SOURCES += \
|
|||
src/widget/tool/screengrabberoverlayitem.cpp \
|
||||
src/widget/tool/toolboxgraphicsitem.cpp \
|
||||
src/widget/tool/flyoutoverlaywidget.cpp \
|
||||
src/widget/form/settings/verticalonlyscroller.cpp
|
||||
src/widget/form/settings/verticalonlyscroller.cpp \
|
||||
src/core/toxid.cpp
|
||||
|
||||
|
||||
HEADERS += \
|
||||
|
@ -468,4 +469,5 @@ HEADERS += \
|
|||
src/widget/tool/screengrabberoverlayitem.h \
|
||||
src/widget/tool/toolboxgraphicsitem.h \
|
||||
src/widget/tool/flyoutoverlaywidget.h \
|
||||
src/widget/form/settings/verticalonlyscroller.h
|
||||
src/widget/form/settings/verticalonlyscroller.h \
|
||||
src/core/toxid.h
|
||||
|
|
|
@ -764,11 +764,11 @@ void Core::setAvatar(const QByteArray& data)
|
|||
AvatarBroadcaster::enableAutoBroadcast();
|
||||
}
|
||||
|
||||
ToxID Core::getSelfId() const
|
||||
ToxId Core::getSelfId() const
|
||||
{
|
||||
uint8_t friendAddress[TOX_ADDRESS_SIZE] = {0};
|
||||
tox_self_get_address(tox, friendAddress);
|
||||
return ToxID::fromString(CFriendAddress::toString(friendAddress));
|
||||
return ToxId(CFriendAddress::toString(friendAddress));
|
||||
}
|
||||
|
||||
QString Core::getIDString() const
|
||||
|
@ -1080,9 +1080,9 @@ QString Core::getGroupPeerName(int groupId, int peerId) const
|
|||
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];
|
||||
int res = tox_group_peer_pubkey(tox, groupId, peerId, rawID);
|
||||
|
@ -1092,7 +1092,7 @@ ToxID Core::getGroupPeerToxID(int groupId, int peerId) const
|
|||
return peerToxID;
|
||||
}
|
||||
|
||||
peerToxID = ToxID::fromString(CUserId::toString(rawID));
|
||||
peerToxID = ToxId(CUserId::toString(rawID));
|
||||
return peerToxID;
|
||||
}
|
||||
|
||||
|
@ -1281,7 +1281,7 @@ QList<CString> Core::splitMessage(const QString &message, int maxLen)
|
|||
return splittedMsgs;
|
||||
}
|
||||
|
||||
QString Core::getPeerName(const ToxID& id) const
|
||||
QString Core::getPeerName(const ToxId& id) const
|
||||
{
|
||||
QString name;
|
||||
CUserId cid(id.toString());
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "corestructs.h"
|
||||
#include "coreav.h"
|
||||
#include "coredefines.h"
|
||||
#include "toxid.h"
|
||||
|
||||
template <typename T> class QList;
|
||||
class Camera;
|
||||
|
@ -55,12 +56,12 @@ public:
|
|||
|
||||
static QByteArray getSaltFromFile(QString filename);
|
||||
|
||||
QString getPeerName(const ToxID& id) const;
|
||||
QString getPeerName(const ToxId& id) const;
|
||||
|
||||
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
|
||||
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 ToxID of a peer 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 getFriendUsername(uint32_t friendId) const; ///< Get the username of a friend
|
||||
|
@ -74,7 +75,7 @@ public:
|
|||
|
||||
QString getUsername() const; ///< Returns our username, or an empty string on failure
|
||||
QString getStatusMessage() const; ///< Returns our status message, or an empty string on failure
|
||||
ToxID getSelfId() const; ///< Returns our Tox ID
|
||||
ToxId getSelfId() const; ///< Returns our Tox ID
|
||||
QPair<QByteArray, QByteArray> getKeypair() const; ///< Returns our public and private keys
|
||||
|
||||
VideoSource* getVideoSourceFromCall(int callNumber); ///< Get a call's video source
|
||||
|
|
|
@ -33,51 +33,3 @@ bool ToxFile::open(bool write)
|
|||
{
|
||||
return write ? file->open(QIODevice::ReadWrite) : file->open(QIODevice::ReadOnly);
|
||||
}
|
||||
|
||||
ToxID::ToxID(const ToxID& other)
|
||||
{
|
||||
publicKey = other.publicKey;
|
||||
noSpam = other.noSpam;
|
||||
checkSum = other.checkSum;
|
||||
}
|
||||
|
||||
QString ToxID::toString() const
|
||||
{
|
||||
return publicKey + noSpam + checkSum;
|
||||
}
|
||||
|
||||
ToxID ToxID::fromString(QString id)
|
||||
{
|
||||
ToxID toxID;
|
||||
toxID.publicKey = id.left(TOX_ID_PUBLIC_KEY_LENGTH);
|
||||
toxID.noSpam = id.mid(TOX_ID_PUBLIC_KEY_LENGTH, TOX_ID_NO_SPAM_LENGTH);
|
||||
toxID.checkSum = id.mid(TOX_ID_PUBLIC_KEY_LENGTH + TOX_ID_NO_SPAM_LENGTH, TOX_ID_CHECKSUM_LENGTH);
|
||||
return toxID;
|
||||
}
|
||||
|
||||
|
||||
bool ToxID::operator==(const ToxID& other) const
|
||||
{
|
||||
return publicKey == other.publicKey;
|
||||
}
|
||||
|
||||
bool ToxID::operator!=(const ToxID& other) const
|
||||
{
|
||||
return publicKey != other.publicKey;
|
||||
}
|
||||
|
||||
bool ToxID::isMine() const
|
||||
{
|
||||
return *this == Core::getInstance()->getSelfId();
|
||||
}
|
||||
|
||||
void ToxID::clear()
|
||||
{
|
||||
publicKey.clear();
|
||||
}
|
||||
|
||||
bool ToxID::isToxId(const QString& value)
|
||||
{
|
||||
const QRegularExpression hexRegExp("^[A-Fa-f0-9]+$");
|
||||
return value.length() == TOX_HEX_ID_LENGTH && value.contains(hexRegExp);
|
||||
}
|
||||
|
|
|
@ -11,29 +11,6 @@ class QTimer;
|
|||
|
||||
enum class Status : int {Online = 0, Away, Busy, Offline};
|
||||
|
||||
#define TOX_ID_PUBLIC_KEY_LENGTH 64
|
||||
#define TOX_ID_NO_SPAM_LENGTH 8
|
||||
#define TOX_ID_CHECKSUM_LENGTH 4
|
||||
|
||||
struct ToxID
|
||||
{
|
||||
ToxID()=default;
|
||||
ToxID(const ToxID& other);
|
||||
|
||||
QString publicKey;
|
||||
QString noSpam;
|
||||
QString checkSum;
|
||||
|
||||
QString toString() const;
|
||||
static ToxID fromString(QString id);
|
||||
static bool isToxId(const QString& id);
|
||||
|
||||
bool operator==(const ToxID& other) const;
|
||||
bool operator!=(const ToxID& other) const;
|
||||
bool isMine() const;
|
||||
void clear();
|
||||
};
|
||||
|
||||
struct ToxFile
|
||||
{
|
||||
enum FileStatus
|
||||
|
|
66
src/core/toxid.cpp
Normal file
66
src/core/toxid.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "toxid.h"
|
||||
|
||||
#include "core.h"
|
||||
|
||||
#include <tox/tox.h>
|
||||
#include <qregularexpression.h>
|
||||
|
||||
#define TOX_ID_PUBLIC_KEY_LENGTH 64
|
||||
#define TOX_ID_NO_SPAM_LENGTH 8
|
||||
#define TOX_ID_CHECKSUM_LENGTH 4
|
||||
#define TOX_HEX_ID_LENGTH 2*TOX_ADDRESS_SIZE
|
||||
|
||||
ToxId::ToxId()
|
||||
: publicKey(), noSpam(), checkSum()
|
||||
{}
|
||||
|
||||
ToxId::ToxId(const ToxId &other)
|
||||
: publicKey(other.publicKey), noSpam(other.noSpam), checkSum(other.checkSum)
|
||||
{}
|
||||
|
||||
ToxId::ToxId(const QString &id)
|
||||
{
|
||||
if (isToxId(id))
|
||||
{
|
||||
publicKey = id.left(TOX_ID_PUBLIC_KEY_LENGTH);
|
||||
noSpam = id.mid(TOX_ID_PUBLIC_KEY_LENGTH, TOX_ID_NO_SPAM_LENGTH);
|
||||
checkSum = id.mid(TOX_ID_PUBLIC_KEY_LENGTH + TOX_ID_NO_SPAM_LENGTH, TOX_ID_CHECKSUM_LENGTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
publicKey = id;
|
||||
}
|
||||
}
|
||||
|
||||
bool ToxId::operator==(const ToxId& other) const
|
||||
{
|
||||
return publicKey == other.publicKey;
|
||||
}
|
||||
|
||||
bool ToxId::operator!=(const ToxId &other) const
|
||||
{
|
||||
return publicKey != other.publicKey;
|
||||
}
|
||||
|
||||
bool ToxId::isActiveProfile() const
|
||||
{
|
||||
return *this == Core::getInstance()->getSelfId();
|
||||
}
|
||||
|
||||
QString ToxId::toString() const
|
||||
{
|
||||
return publicKey + noSpam + checkSum;
|
||||
}
|
||||
|
||||
void ToxId::clear()
|
||||
{
|
||||
publicKey.clear();
|
||||
noSpam.clear();
|
||||
checkSum.clear();
|
||||
}
|
||||
|
||||
bool ToxId::isToxId(const QString &id)
|
||||
{
|
||||
const QRegularExpression hexRegExp("^[A-Fa-f0-9]+$");
|
||||
return id.length() == TOX_HEX_ID_LENGTH && id.contains(hexRegExp);
|
||||
}
|
34
src/core/toxid.h
Normal file
34
src/core/toxid.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef TOXID_H
|
||||
#define TOXID_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
/*!
|
||||
* \brief This class represents a Tox ID as specified at:
|
||||
* https://libtoxcore.so/core_concepts.html
|
||||
*/
|
||||
class ToxId
|
||||
{
|
||||
public:
|
||||
ToxId(); ///< The default constructor. Creates an empty Tox ID.
|
||||
ToxId(const ToxId& other); ///< The copy constructor.
|
||||
ToxId(const QString& id); ///< Create a Tox ID from QString.
|
||||
/// If the given id is not a valid Tox ID, then:
|
||||
/// publicKey == id and noSpam == "" == checkSum.
|
||||
|
||||
bool operator==(const ToxId& other) const; ///< Compares only publicKey.
|
||||
bool operator!=(const ToxId& other) const; ///< Compares only publicKey.
|
||||
bool isActiveProfile() const; ///< Returns true if this Tox ID is equals to
|
||||
/// the Tox ID of the currently active profile.
|
||||
QString toString() const; ///< Returns the Tox ID as QString.
|
||||
void clear(); ///< Clears all elements of the Tox ID.
|
||||
|
||||
static bool isToxId(const QString& id); ///< Returns true if id is a valid Tox ID.
|
||||
|
||||
public:
|
||||
QString publicKey;
|
||||
QString noSpam;
|
||||
QString checkSum;
|
||||
};
|
||||
|
||||
#endif // TOXID_H
|
|
@ -20,7 +20,7 @@
|
|||
#include "src/core/core.h"
|
||||
#include "src/misc/settings.h"
|
||||
|
||||
Friend::Friend(uint32_t FriendId, const ToxID &UserId)
|
||||
Friend::Friend(uint32_t FriendId, const ToxId &UserId)
|
||||
: userName{Core::getInstance()->getPeerName(UserId)},
|
||||
userID{UserId}, friendId{FriendId}
|
||||
{
|
||||
|
@ -93,7 +93,7 @@ QString Friend::getDisplayedName() const
|
|||
return userAlias;
|
||||
}
|
||||
|
||||
const ToxID &Friend::getToxID() const
|
||||
const ToxId &Friend::getToxID() const
|
||||
{
|
||||
return userID;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
#include "src/core/corestructs.h"
|
||||
#include "core/toxid.h"
|
||||
|
||||
struct FriendWidget;
|
||||
class ChatForm;
|
||||
|
@ -26,7 +27,7 @@ class Friend : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Friend(uint32_t FriendId, const ToxID &UserId);
|
||||
Friend(uint32_t FriendId, const ToxId &UserId);
|
||||
Friend(const Friend& other)=delete;
|
||||
~Friend();
|
||||
Friend& operator=(const Friend& other)=delete;
|
||||
|
@ -43,7 +44,7 @@ public:
|
|||
void setEventFlag(int f);
|
||||
int getEventFlag() const;
|
||||
|
||||
const ToxID &getToxID() const;
|
||||
const ToxId &getToxID() const;
|
||||
uint32_t getFriendID() const;
|
||||
|
||||
void setStatus(Status s);
|
||||
|
@ -57,7 +58,7 @@ signals:
|
|||
|
||||
private:
|
||||
QString userAlias, userName;
|
||||
ToxID userID;
|
||||
ToxId userID;
|
||||
uint32_t friendId;
|
||||
int hasNewEvents;
|
||||
Status friendStatus;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
QHash<int, Friend*> FriendList::friendList;
|
||||
QHash<QString, int> FriendList::tox2id;
|
||||
|
||||
Friend* FriendList::addFriend(int friendId, const ToxID& userId)
|
||||
Friend* FriendList::addFriend(int friendId, const ToxId& userId)
|
||||
{
|
||||
auto friendChecker = friendList.find(friendId);
|
||||
if (friendChecker != friendList.end())
|
||||
|
@ -66,7 +66,7 @@ void FriendList::clear()
|
|||
friendList.clear();
|
||||
}
|
||||
|
||||
Friend* FriendList::findFriend(const ToxID& userId)
|
||||
Friend* FriendList::findFriend(const ToxId& userId)
|
||||
{
|
||||
auto id = tox2id.find(userId.publicKey);
|
||||
if (id != tox2id.end())
|
||||
|
|
|
@ -19,14 +19,14 @@ template <class T> class QList;
|
|||
template <class A, class B> class QHash;
|
||||
class Friend;
|
||||
class QString;
|
||||
struct ToxID;
|
||||
class ToxId;
|
||||
|
||||
class FriendList
|
||||
{
|
||||
public:
|
||||
static Friend* addFriend(int friendId, const ToxID &userId);
|
||||
static Friend* addFriend(int friendId, const ToxId &userId);
|
||||
static Friend* findFriend(int friendId);
|
||||
static Friend* findFriend(const ToxID &userId);
|
||||
static Friend* findFriend(const ToxId &userId);
|
||||
static QList<Friend*> getAllFriends();
|
||||
static void removeFriend(int friendId, bool fake = false);
|
||||
static void clear();
|
||||
|
|
|
@ -66,7 +66,7 @@ void Group::removePeer(int peerId)
|
|||
|
||||
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;
|
||||
peers[peerId] = name;
|
||||
toxids[toxid] = name;
|
||||
|
@ -97,8 +97,8 @@ void Group::regeneratePeerList()
|
|||
nPeers = peers.size();
|
||||
for (int i = 0; i < nPeers; i++)
|
||||
{
|
||||
ToxID id = Core::getInstance()->getGroupPeerToxID(groupId, i);
|
||||
if (id.isMine())
|
||||
ToxId id = Core::getInstance()->getGroupPeerToxID(groupId, i);
|
||||
if (id.isActiveProfile())
|
||||
selfPeerNum = i;
|
||||
|
||||
QString toxid = id.publicKey;
|
||||
|
@ -170,7 +170,7 @@ int Group::getMentionedFlag() const
|
|||
return userWasMentioned;
|
||||
}
|
||||
|
||||
QString Group::resolveToxID(const ToxID &id) const
|
||||
QString Group::resolveToxID(const ToxId &id) const
|
||||
{
|
||||
QString key = id.publicKey;
|
||||
auto it = toxids.find(key);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
class Friend;
|
||||
class GroupWidget;
|
||||
class GroupChatForm;
|
||||
struct ToxID;
|
||||
class ToxId;
|
||||
|
||||
class Group : public QObject
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
void updatePeer(int peerId, QString newName);
|
||||
void setName(const QString& name);
|
||||
|
||||
QString resolveToxID(const ToxID &id) const;
|
||||
QString resolveToxID(const ToxId &id) const;
|
||||
|
||||
private:
|
||||
GroupWidget* widget;
|
||||
|
|
|
@ -357,7 +357,7 @@ void Settings::load()
|
|||
fp.addr = ps.value("addr").toString();
|
||||
fp.alias = ps.value("alias").toString();
|
||||
fp.autoAcceptDir = ps.value("autoAcceptDir").toString();
|
||||
friendLst[ToxID::fromString(fp.addr).publicKey] = fp;
|
||||
friendLst[ToxId(fp.addr).publicKey] = fp;
|
||||
}
|
||||
ps.endArray();
|
||||
ps.endGroup();
|
||||
|
@ -892,7 +892,7 @@ void Settings::setAutoAwayTime(int newValue)
|
|||
autoAwayTime = newValue;
|
||||
}
|
||||
|
||||
QString Settings::getAutoAcceptDir(const ToxID& id) const
|
||||
QString Settings::getAutoAcceptDir(const ToxId& id) const
|
||||
{
|
||||
QString key = id.publicKey;
|
||||
|
||||
|
@ -903,7 +903,7 @@ QString Settings::getAutoAcceptDir(const ToxID& id) const
|
|||
return QString();
|
||||
}
|
||||
|
||||
void Settings::setAutoAcceptDir(const ToxID &id, const QString& dir)
|
||||
void Settings::setAutoAcceptDir(const ToxId &id, const QString& dir)
|
||||
{
|
||||
QString key = id.publicKey;
|
||||
|
||||
|
@ -1156,7 +1156,7 @@ void Settings::setCamVideoRes(QSize newValue)
|
|||
|
||||
QString Settings::getFriendAdress(const QString &publicKey) const
|
||||
{
|
||||
QString key = ToxID::fromString(publicKey).publicKey;
|
||||
QString key = ToxId(publicKey).publicKey;
|
||||
auto it = friendLst.find(key);
|
||||
if (it != friendLst.end())
|
||||
return it->addr;
|
||||
|
@ -1166,7 +1166,7 @@ QString Settings::getFriendAdress(const QString &publicKey) const
|
|||
|
||||
void Settings::updateFriendAdress(const QString &newAddr)
|
||||
{
|
||||
QString key = ToxID::fromString(newAddr).publicKey;
|
||||
QString key = ToxId(newAddr).publicKey;
|
||||
auto it = friendLst.find(key);
|
||||
if (it != friendLst.end())
|
||||
{
|
||||
|
@ -1182,7 +1182,7 @@ void Settings::updateFriendAdress(const QString &newAddr)
|
|||
}
|
||||
}
|
||||
|
||||
QString Settings::getFriendAlias(const ToxID &id) const
|
||||
QString Settings::getFriendAlias(const ToxId &id) const
|
||||
{
|
||||
QString key = id.publicKey;
|
||||
auto it = friendLst.find(key);
|
||||
|
@ -1192,7 +1192,7 @@ QString Settings::getFriendAlias(const ToxID &id) const
|
|||
return QString();
|
||||
}
|
||||
|
||||
void Settings::setFriendAlias(const ToxID &id, const QString &alias)
|
||||
void Settings::setFriendAlias(const ToxId &id, const QString &alias)
|
||||
{
|
||||
QString key = id.publicKey;
|
||||
auto it = friendLst.find(key);
|
||||
|
@ -1210,7 +1210,7 @@ void Settings::setFriendAlias(const ToxID &id, const QString &alias)
|
|||
}
|
||||
}
|
||||
|
||||
void Settings::removeFriendSettings(const ToxID &id)
|
||||
void Settings::removeFriendSettings(const ToxId &id)
|
||||
{
|
||||
QString key = id.publicKey;
|
||||
friendLst.remove(key);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
|
||||
struct ToxID;
|
||||
class ToxId;
|
||||
namespace Db { enum class syncType; }
|
||||
|
||||
enum ProxyType {ptNone, ptSOCKS5, ptHTTP};
|
||||
|
@ -192,8 +192,8 @@ public:
|
|||
int getEmojiFontPointSize() const;
|
||||
void setEmojiFontPointSize(int value);
|
||||
|
||||
QString getAutoAcceptDir(const ToxID& id) const;
|
||||
void setAutoAcceptDir(const ToxID&id, const QString& dir);
|
||||
QString getAutoAcceptDir(const ToxId& id) const;
|
||||
void setAutoAcceptDir(const ToxId&id, const QString& dir);
|
||||
|
||||
QString getGlobalAutoAcceptDir() const;
|
||||
void setGlobalAutoAcceptDir(const QString& dir);
|
||||
|
@ -237,10 +237,10 @@ public:
|
|||
QString getFriendAdress(const QString &publicKey) const;
|
||||
void updateFriendAdress(const QString &newAddr);
|
||||
|
||||
QString getFriendAlias(const ToxID &id) const;
|
||||
void setFriendAlias(const ToxID &id, const QString &alias);
|
||||
QString getFriendAlias(const ToxId &id) const;
|
||||
void setFriendAlias(const ToxId &id, const QString &alias);
|
||||
|
||||
void removeFriendSettings(const ToxID &id);
|
||||
void removeFriendSettings(const ToxId &id);
|
||||
|
||||
bool getFauxOfflineMessaging() const;
|
||||
void setFauxOfflineMessaging(bool value);
|
||||
|
|
|
@ -149,7 +149,7 @@ QString ToxDNS::queryTox1(const QString& record, bool silent)
|
|||
}
|
||||
|
||||
toxId = entry.mid(idx, TOX_HEX_ID_LENGTH);
|
||||
if (!ToxID::isToxId(toxId))
|
||||
if (!ToxId::isToxId(toxId))
|
||||
{
|
||||
if (!silent)
|
||||
showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS"));
|
||||
|
@ -250,17 +250,17 @@ If unsure, press “No”, so that request to ToxDNS service will not be made us
|
|||
return toxIdStr;
|
||||
}
|
||||
|
||||
ToxID ToxDNS::resolveToxAddress(const QString &address, bool silent)
|
||||
ToxId ToxDNS::resolveToxAddress(const QString &address, bool silent)
|
||||
{
|
||||
ToxID toxId;
|
||||
ToxId toxId;
|
||||
|
||||
if (address.isEmpty())
|
||||
{
|
||||
return toxId;
|
||||
}
|
||||
else if (ToxID::isToxId(address))
|
||||
else if (ToxId::isToxId(address))
|
||||
{
|
||||
toxId = ToxID::fromString(address);
|
||||
toxId = ToxId(address);
|
||||
return toxId;
|
||||
}
|
||||
else
|
||||
|
@ -271,7 +271,7 @@ ToxID ToxDNS::resolveToxAddress(const QString &address, bool silent)
|
|||
{
|
||||
if (servname == pin.name)
|
||||
{
|
||||
toxId = ToxID::fromString(queryTox3(pin, address, silent));
|
||||
toxId = ToxId(queryTox3(pin, address, silent));
|
||||
return toxId;
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ ToxID ToxDNS::resolveToxAddress(const QString &address, bool silent)
|
|||
ToxDNS::tox3_server server;
|
||||
server.name = servnameData.data();
|
||||
server.pubkey = (uint8_t*)pubkey.data();
|
||||
toxId = ToxID::fromString(queryTox3(server, address, silent));
|
||||
toxId = ToxId(queryTox3(server, address, silent));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -296,7 +296,7 @@ Unfortunately tox1 is not secure, and you are at risk of someone hijacking what
|
|||
Should tox1 be used anyway?\n\
|
||||
If unsure, press “No”, so that request to ToxDNS service will not be made using unsecure protocol."), QMessageBox::Ok|QMessageBox::No, QMessageBox::No);
|
||||
if (btn == QMessageBox::Ok)
|
||||
toxId = ToxID::fromString(queryTox1(address, silent));
|
||||
toxId = ToxId(queryTox1(address, silent));
|
||||
|
||||
#else
|
||||
return toxId;
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
#ifndef QTOXDNS_H
|
||||
#define QTOXDNS_H
|
||||
|
||||
#include "src/core/corestructs.h"
|
||||
#include "core/corestructs.h"
|
||||
#include "core/toxid.h"
|
||||
#include <QDnsLookup>
|
||||
#include <QObject>
|
||||
|
||||
|
@ -43,7 +44,7 @@ public:
|
|||
|
||||
public:
|
||||
/// 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 queryTox3(const tox3_server& server, const QString& record, bool silent=true); ///< Record should look like user@domain.tld, will *NOT* fallback on queryTox1 anymore
|
||||
|
|
|
@ -55,13 +55,13 @@ QByteArray Toxme::prepareEncryptedJson(int action, QString payload)
|
|||
return json.toUtf8();
|
||||
}
|
||||
|
||||
ToxID Toxme::lookup(QString address)
|
||||
ToxId Toxme::lookup(QString address)
|
||||
{
|
||||
// JSON injection ?
|
||||
address.replace('\\',"\\\\");
|
||||
address.replace('"',"\"");
|
||||
|
||||
ToxID id;
|
||||
ToxId id;
|
||||
const QString json{"{\"action\":3,\"name\":\""+address+"\"}"};
|
||||
static const QByteArray pattern{"public_key\""};
|
||||
|
||||
|
@ -84,7 +84,7 @@ ToxID Toxme::lookup(QString address)
|
|||
|
||||
response.truncate(idEnd);
|
||||
|
||||
id = ToxID::fromString(response);
|
||||
id = ToxId(response);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ int Toxme::extractError(QString json)
|
|||
return r;
|
||||
}
|
||||
|
||||
bool Toxme::createAddress(ToxID id, QString address,
|
||||
bool Toxme::createAddress(ToxId id, QString address,
|
||||
bool keepPrivate, QString bio)
|
||||
{
|
||||
int privacy = keepPrivate ? 0 : 2;
|
||||
|
@ -134,7 +134,7 @@ bool Toxme::createAddress(ToxID id, QString address,
|
|||
return (extractError(response) == 0);
|
||||
}
|
||||
|
||||
bool Toxme::deleteAddress(ToxID id)
|
||||
bool Toxme::deleteAddress(ToxId id)
|
||||
{
|
||||
const QString payload{"{\"public_key\":\""+id.toString().left(64)+"\","
|
||||
"\"timestamp\":"+QString().setNum(time(0))+"}"};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QString>
|
||||
#include <QMutex>
|
||||
#include <memory>
|
||||
#include "src/core/corestructs.h"
|
||||
#include "core/toxid.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
|
||||
|
@ -15,14 +15,14 @@ class Toxme
|
|||
{
|
||||
public:
|
||||
/// Converts a toxme.se address to a Tox ID, returns an empty ID on error
|
||||
static ToxID lookup(QString address);
|
||||
static ToxId lookup(QString address);
|
||||
/// Creates a new toxme.se address associated with a Tox ID.
|
||||
/// If keepPrivate, the address will not be published on toxme.se
|
||||
/// The bio is a short optional description of yourself if you want to publish your address.
|
||||
static bool createAddress(ToxID id, QString address,
|
||||
static bool createAddress(ToxId id, QString address,
|
||||
bool keepPrivate=true, QString bio=QString());
|
||||
/// Deletes the address associated with your current Tox ID
|
||||
static bool deleteAddress(ToxID id);
|
||||
static bool deleteAddress(ToxId id);
|
||||
|
||||
private:
|
||||
Toxme()=delete;
|
||||
|
|
|
@ -89,7 +89,7 @@ void AddFriendForm::onSendTriggered()
|
|||
{
|
||||
GUI::showWarning(tr("Couldn't add friend"), tr("Please fill in a valid Tox ID","Tox ID of the friend you're sending a friend request to"));
|
||||
}
|
||||
else if (ToxID::isToxId(id))
|
||||
else if (ToxId::isToxId(id))
|
||||
{
|
||||
if (id.toUpper() == Core::getInstance()->getSelfId().toString().toUpper())
|
||||
GUI::showWarning(tr("Couldn't add friend"), tr("You can't add yourself as a friend!","When trying to add your own Tox ID as friend"));
|
||||
|
@ -109,7 +109,7 @@ Ignore the proxy and connect to the Internet directly?"), QMessageBox::Yes|QMess
|
|||
return;
|
||||
}
|
||||
|
||||
ToxID toxId = ToxDNS::resolveToxAddress(id, true);
|
||||
ToxId toxId = ToxDNS::resolveToxAddress(id, true);
|
||||
|
||||
if (toxId.toString().isEmpty())
|
||||
{
|
||||
|
@ -127,9 +127,9 @@ void AddFriendForm::setIdFromClipboard()
|
|||
{
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
QString id = clipboard->text().trimmed();
|
||||
if (Core::getInstance()->isReady() && !id.isEmpty() && ToxID::isToxId(id))
|
||||
if (Core::getInstance()->isReady() && !id.isEmpty() && ToxId::isToxId(id))
|
||||
{
|
||||
if (!ToxID::fromString(id).isMine())
|
||||
if (!ToxId(id).isActiveProfile())
|
||||
toxId.setText(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ void ChatForm::startFileSend(ToxFile file)
|
|||
return;
|
||||
|
||||
QString name;
|
||||
if (!previousId.isMine())
|
||||
if (!previousId.isActiveProfile())
|
||||
{
|
||||
Core* core = Core::getInstance();
|
||||
name = core->getUsername();
|
||||
|
@ -203,7 +203,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
|||
}
|
||||
|
||||
QString name;
|
||||
ToxID friendId = f->getToxID();
|
||||
ToxId friendId = f->getToxID();
|
||||
if (friendId != previousId)
|
||||
{
|
||||
name = f->getDisplayedName();
|
||||
|
@ -794,8 +794,8 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
|
||||
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now);
|
||||
|
||||
ToxID storedPrevId = previousId;
|
||||
ToxID prevId;
|
||||
ToxId storedPrevId = previousId;
|
||||
ToxId prevId;
|
||||
|
||||
QList<ChatLine::Ptr> historyMessages;
|
||||
|
||||
|
@ -813,14 +813,14 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
}
|
||||
|
||||
// Show each messages
|
||||
ToxID authorId = ToxID::fromString(it.sender);
|
||||
QString authorStr = authorId.isMine() ? Core::getInstance()->getUsername() : resolveToxID(authorId);
|
||||
ToxId authorId = ToxId(it.sender);
|
||||
QString authorStr = authorId.isActiveProfile() ? Core::getInstance()->getUsername() : resolveToxID(authorId);
|
||||
bool isAction = it.message.startsWith("/me ", Qt::CaseInsensitive);
|
||||
|
||||
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
|
||||
isAction ? it.message.right(it.message.length() - 4) : it.message,
|
||||
isAction ? ChatMessage::ACTION : ChatMessage::NORMAL,
|
||||
authorId.isMine(),
|
||||
authorId.isActiveProfile(),
|
||||
QDateTime());
|
||||
|
||||
if (!isAction && (prevId == authorId) && (prevMsgDateTime.secsTo(msgDateTime) < getChatLog()->repNameAfter) )
|
||||
|
@ -829,7 +829,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
prevId = authorId;
|
||||
prevMsgDateTime = msgDateTime;
|
||||
|
||||
if (it.isSent || !authorId.isMine())
|
||||
if (it.isSent || !authorId.isActiveProfile())
|
||||
{
|
||||
msg->markAsSent(msgDateTime);
|
||||
}
|
||||
|
|
|
@ -245,10 +245,10 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
|||
menu.exec(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)
|
||||
{
|
||||
QString authorStr = author.isMine() ? Core::getInstance()->getUsername() : resolveToxID(author);
|
||||
QString authorStr = author.isActiveProfile() ? Core::getInstance()->getUsername() : resolveToxID(author);
|
||||
|
||||
ChatMessage::Ptr msg;
|
||||
if (isAction)
|
||||
|
@ -258,7 +258,7 @@ ChatMessage::Ptr GenericChatForm::addMessage(const ToxID& author, const QString
|
|||
}
|
||||
else
|
||||
{
|
||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, author.isMine());
|
||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, author.isActiveProfile());
|
||||
if ( (author == previousId) && (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter) )
|
||||
msg->hideSender();
|
||||
|
||||
|
@ -279,10 +279,10 @@ ChatMessage::Ptr GenericChatForm::addSelfMessage(const QString &message, bool is
|
|||
return addMessage(Core::getInstance()->getSelfId(), message, isAction, datetime, isSent);
|
||||
}
|
||||
|
||||
void GenericChatForm::addAlertMessage(const ToxID &author, QString message, QDateTime datetime)
|
||||
void GenericChatForm::addAlertMessage(const ToxId &author, QString message, QDateTime datetime)
|
||||
{
|
||||
QString authorStr = resolveToxID(author);
|
||||
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, author.isMine(), datetime);
|
||||
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, author.isActiveProfile(), datetime);
|
||||
insertChatMessage(msg);
|
||||
|
||||
if ((author == previousId) && (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter))
|
||||
|
@ -372,7 +372,7 @@ void GenericChatForm::clearChatArea()
|
|||
void GenericChatForm::clearChatArea(bool notinform)
|
||||
{
|
||||
chatWidget->clear();
|
||||
previousId = ToxID();
|
||||
previousId = ToxId();
|
||||
|
||||
if (!notinform)
|
||||
addSystemInfoMessage(tr("Cleared"), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||
|
@ -388,7 +388,7 @@ void GenericChatForm::onSelectAllClicked()
|
|||
chatWidget->selectAll();
|
||||
}
|
||||
|
||||
QString GenericChatForm::resolveToxID(const ToxID &id)
|
||||
QString GenericChatForm::resolveToxID(const ToxId &id)
|
||||
{
|
||||
Friend *f = FriendList::findFriend(id);
|
||||
if (f)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QMenu>
|
||||
#include "src/core/corestructs.h"
|
||||
#include "src/chatlog/chatmessage.h"
|
||||
#include "../../core/toxid.h"
|
||||
|
||||
// Spacing in px inserted when the author of the last message changes
|
||||
#define AUTHOR_CHANGE_SPACING 5 // why the hell is this a thing? surely the different font is enough?
|
||||
|
@ -33,7 +34,6 @@ class ChatTextEdit;
|
|||
class ChatLog;
|
||||
class MaskablePixmapWidget;
|
||||
class Widget;
|
||||
struct ToxID;
|
||||
class FlyoutOverlayWidget;
|
||||
|
||||
namespace Ui {
|
||||
|
@ -49,11 +49,11 @@ public:
|
|||
virtual void setName(const QString &newName);
|
||||
virtual void show(Ui::MainWindow &ui);
|
||||
|
||||
ChatMessage::Ptr addMessage(const ToxID& author, const QString &message, bool isAction, const QDateTime &datetime, bool isSent);
|
||||
ChatMessage::Ptr addMessage(const ToxId& author, const QString &message, bool isAction, const QDateTime &datetime, bool isSent);
|
||||
ChatMessage::Ptr addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent);
|
||||
|
||||
void addSystemInfoMessage(const QString &message, ChatMessage::SystemMessageType type, const QDateTime &datetime);
|
||||
void addAlertMessage(const ToxID& author, QString message, QDateTime datetime);
|
||||
void addAlertMessage(const ToxId& author, QString message, QDateTime datetime);
|
||||
bool isEmpty();
|
||||
|
||||
ChatLog* getChatLog() const;
|
||||
|
@ -80,13 +80,13 @@ protected slots:
|
|||
void hideFileMenu();
|
||||
|
||||
protected:
|
||||
QString resolveToxID(const ToxID &id);
|
||||
QString resolveToxID(const ToxId &id);
|
||||
void insertChatMessage(ChatMessage::Ptr msg);
|
||||
void hideEvent(QHideEvent* event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
void adjustFileMenuPosition();
|
||||
|
||||
ToxID previousId;
|
||||
ToxId previousId;
|
||||
QDateTime prevMsgDateTime;
|
||||
Widget *parent;
|
||||
QMenu menu;
|
||||
|
|
|
@ -51,7 +51,7 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
|||
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||
{
|
||||
QPoint pos = event->globalPos();
|
||||
ToxID id = FriendList::findFriend(friendId)->getToxID();
|
||||
ToxId id = FriendList::findFriend(friendId)->getToxID();
|
||||
QString dir = Settings::getInstance().getAutoAcceptDir(id);
|
||||
QMenu menu;
|
||||
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
|
||||
|
|
|
@ -609,7 +609,7 @@ void Widget::reloadHistory()
|
|||
|
||||
void Widget::addFriend(int friendId, const QString &userId)
|
||||
{
|
||||
ToxID userToxId = ToxID::fromString(userId);
|
||||
ToxId userToxId = ToxId(userId);
|
||||
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
|
||||
contactListWidget->moveWidget(newfriend->getFriendWidget(),Status::Offline);
|
||||
|
||||
|
@ -950,8 +950,8 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
|
|||
if (!g)
|
||||
return;
|
||||
|
||||
ToxID author = Core::getInstance()->getGroupPeerToxID(groupnumber, peernumber);
|
||||
bool targeted = !author.isMine() && (message.contains(nameMention) || message.contains(sanitizedNameMention));
|
||||
ToxId author = Core::getInstance()->getGroupPeerToxID(groupnumber, peernumber);
|
||||
bool targeted = !author.isActiveProfile() && (message.contains(nameMention) || message.contains(sanitizedNameMention));
|
||||
if (targeted && !isAction)
|
||||
g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime());
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue
Block a user