mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(toxid): Removed Core dependency from ToxId
It's needed to make ToxId just data structure
This commit is contained in:
parent
953fe2416a
commit
2a88e5c069
|
@ -1283,7 +1283,7 @@ QString Core::getPeerName(const ToxId& id) const
|
|||
/**
|
||||
* @brief Most of the API shouldn't be used until Core is ready, call start() first
|
||||
*/
|
||||
bool Core::isReady()
|
||||
bool Core::isReady() const
|
||||
{
|
||||
return av && av->getToxAv() && tox && ready;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
static QByteArray decryptData(const QByteArray& data, const TOX_PASS_KEY &encryptionKey);
|
||||
static QByteArray decryptData(const QByteArray& data);
|
||||
|
||||
bool isReady();
|
||||
bool isReady() const;
|
||||
|
||||
void sendFile(uint32_t friendId, QString filename, QString filePath, long long filesize);
|
||||
|
||||
|
|
|
@ -104,16 +104,6 @@ bool ToxId::operator!=(const ToxId &other) const
|
|||
return publicKey != other.publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check, that the current user ID is the active user ID
|
||||
* @return True if this Tox ID is equals to
|
||||
* the Tox ID of the currently active profile.
|
||||
*/
|
||||
bool ToxId::isSelf() const
|
||||
{
|
||||
return *this == Core::getInstance()->getSelfId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns Tox ID converted to QString.
|
||||
* @return The Tox ID as QString.
|
||||
|
|
|
@ -32,7 +32,6 @@ public:
|
|||
|
||||
bool operator==(const ToxId& other) const;
|
||||
bool operator!=(const ToxId& other) const;
|
||||
bool isSelf() const;
|
||||
QString toString() const;
|
||||
void clear();
|
||||
|
||||
|
|
|
@ -84,13 +84,15 @@ QString Group::getName() const
|
|||
|
||||
void Group::regeneratePeerList()
|
||||
{
|
||||
peers = Core::getInstance()->getGroupPeerNames(groupId);
|
||||
const Core* core = Core::getInstance();
|
||||
peers = core->getGroupPeerNames(groupId);
|
||||
toxids.clear();
|
||||
nPeers = peers.size();
|
||||
for (int i = 0; i < nPeers; ++i)
|
||||
{
|
||||
ToxId id = Core::getInstance()->getGroupPeerToxId(groupId, i);
|
||||
if (id.isSelf())
|
||||
ToxId id = core->getGroupPeerToxId(groupId, i);
|
||||
ToxId self = core->getSelfId();
|
||||
if (id == self)
|
||||
selfPeerNum = i;
|
||||
|
||||
QString toxid = id.publicKey;
|
||||
|
|
|
@ -216,10 +216,12 @@ void AddFriendForm::setIdFromClipboard()
|
|||
{
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
QString id = clipboard->text().trimmed();
|
||||
if (Core::getInstance()->isReady() && !id.isEmpty() && ToxId::isToxId(id))
|
||||
const Core* core = Core::getInstance();
|
||||
if (core->isReady() && !id.isEmpty()
|
||||
&& ToxId::isToxId(id)
|
||||
&& ToxId(id) == core->getSelfId())
|
||||
{
|
||||
if (!ToxId(id).isSelf())
|
||||
toxId.setText(id);
|
||||
toxId.setText(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -229,11 +229,12 @@ void ChatForm::startFileSend(ToxFile file)
|
|||
return;
|
||||
|
||||
QString name;
|
||||
if (!previousId.isSelf())
|
||||
const Core* core = Core::getInstance();
|
||||
ToxId self = core->getSelfId();
|
||||
if (previousId != self)
|
||||
{
|
||||
Core* core = Core::getInstance();
|
||||
name = core->getUsername();
|
||||
previousId = core->getSelfId();
|
||||
previousId = self;
|
||||
}
|
||||
|
||||
insertChatMessage(ChatMessage::createFileTransferMessage(name, file, true, QDateTime::currentDateTime()));
|
||||
|
@ -721,6 +722,7 @@ void ChatForm::onAvatarRemoved(uint32_t FriendId)
|
|||
avatar->setPixmap(QPixmap(":/img/contact_dark.svg"));
|
||||
}
|
||||
|
||||
// TODO: Split on smaller methods (style)
|
||||
void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
||||
{
|
||||
QDateTime now = historyBaselineDate.addMSecs(-1);
|
||||
|
@ -757,20 +759,41 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
if (msgDate > lastDate)
|
||||
{
|
||||
lastDate = msgDate;
|
||||
historyMessages.append(ChatMessage::createChatInfoMessage(msgDate.toString(Settings::getInstance().getDateFormat()), ChatMessage::INFO, QDateTime()));
|
||||
QString dateText = msgDate.toString(Settings::getInstance().getDateFormat());
|
||||
historyMessages.append(
|
||||
ChatMessage::createChatInfoMessage(dateText,
|
||||
ChatMessage::INFO,
|
||||
QDateTime()));
|
||||
}
|
||||
|
||||
// Show each messages
|
||||
ToxId authorId = ToxId(it.sender);
|
||||
QString authorStr = !it.dispName.isEmpty() ? it.dispName : (authorId.isSelf() ? Core::getInstance()->getUsername() : resolveToxId(authorId));
|
||||
bool isAction = it.message.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
|
||||
bool needSending = !it.isSent && authorId.isSelf();
|
||||
const Core* core = Core::getInstance();
|
||||
ToxId authorId(it.sender);
|
||||
QString authorStr;
|
||||
bool isSelf = authorId == core->getSelfId();
|
||||
|
||||
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
|
||||
isAction ? it.message.mid(4) : it.message,
|
||||
isAction ? ChatMessage::ACTION : ChatMessage::NORMAL,
|
||||
authorId.isSelf(),
|
||||
needSending ? QDateTime() : msgDateTime);
|
||||
if (!it.dispName.isEmpty())
|
||||
{
|
||||
authorStr = it.dispName;
|
||||
}
|
||||
else if (isSelf)
|
||||
{
|
||||
authorStr = core->getUsername();
|
||||
}
|
||||
else
|
||||
{
|
||||
authorStr = resolveToxId(authorId);
|
||||
}
|
||||
|
||||
bool isAction = it.message.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
|
||||
bool needSending = !it.isSent && isSelf;
|
||||
|
||||
ChatMessage::Ptr msg =
|
||||
ChatMessage::createChatMessage(authorStr,
|
||||
isAction ? it.message.mid(4) : it.message,
|
||||
isAction ? ChatMessage::ACTION : ChatMessage::NORMAL,
|
||||
isSelf,
|
||||
needSending ? QDateTime() : msgDateTime);
|
||||
|
||||
if (!isAction && (prevId == authorId) && (prevMsgDateTime.secsTo(msgDateTime) < getChatLog()->repNameAfter) )
|
||||
msg->hideSender();
|
||||
|
|
|
@ -319,11 +319,17 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
|||
ChatMessage::Ptr GenericChatForm::addMessage(const ToxId& author, const QString &message, bool isAction,
|
||||
const QDateTime &datetime, bool isSent)
|
||||
{
|
||||
bool authorIsActiveProfile = author.isSelf();
|
||||
QString authorStr = authorIsActiveProfile ? Core::getInstance()->getUsername() : resolveToxId(author);
|
||||
const Core* core = Core::getInstance();
|
||||
bool authorIsActiveProfile = author == core->getSelfId();
|
||||
QString authorStr = authorIsActiveProfile ? core->getUsername() : resolveToxId(author);
|
||||
|
||||
|
||||
if (getLatestDate() != QDate::currentDate())
|
||||
addSystemInfoMessage(QDate::currentDate().toString(Settings::getInstance().getDateFormat()), ChatMessage::INFO, QDateTime());
|
||||
{
|
||||
const Settings& s = Settings::getInstance();
|
||||
QString dateText = QDate::currentDate().toString(s.getDateFormat());
|
||||
addSystemInfoMessage(dateText, ChatMessage::INFO, QDateTime());
|
||||
}
|
||||
|
||||
ChatMessage::Ptr msg;
|
||||
if (isAction)
|
||||
|
@ -357,7 +363,8 @@ ChatMessage::Ptr GenericChatForm::addSelfMessage(const QString &message, bool is
|
|||
void GenericChatForm::addAlertMessage(const ToxId &author, QString message, QDateTime datetime)
|
||||
{
|
||||
QString authorStr = resolveToxId(author);
|
||||
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, author.isSelf(), datetime);
|
||||
bool isSelf = author == Core::getInstance()->getSelfId();
|
||||
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, isSelf, datetime);
|
||||
insertChatMessage(msg);
|
||||
|
||||
if ((author == previousId) && (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter))
|
||||
|
|
|
@ -1595,15 +1595,23 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
|
|||
{
|
||||
Group* g = GroupList::findGroup(groupnumber);
|
||||
if (!g)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ToxId author = Core::getInstance()->getGroupPeerToxId(groupnumber, peernumber);
|
||||
const Core* core = Core::getInstance();
|
||||
ToxId author = core->getGroupPeerToxId(groupnumber, peernumber);
|
||||
bool isSelf = author == core->getSelfId();
|
||||
|
||||
bool targeted = !author.isSelf() && (message.contains(nameMention) || message.contains(sanitizedNameMention));
|
||||
bool targeted = !isSelf && (message.contains(nameMention) || message.contains(sanitizedNameMention));
|
||||
if (targeted && !isAction)
|
||||
{
|
||||
g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
g->getChatForm()->addMessage(author, message, isAction, QDateTime::currentDateTime(), true);
|
||||
}
|
||||
|
||||
newGroupMessageAlert(g->getGroupId(), targeted || Settings::getInstance().getGroupAlwaysNotify());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user