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

refactor(core): Move saving request to history to Profile

This commit is contained in:
Diadlo 2017-05-06 15:35:54 +03:00
parent b25f5b5ed6
commit 49e9eb8de2
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
5 changed files with 25 additions and 23 deletions

View File

@ -592,26 +592,6 @@ QString Core::getFriendRequestErrorMessage(const ToxId& friendId, const QString&
return QString{}; return QString{};
} }
/**
* @brief Adds history message about friendship request attempt if history is enabled
* @param friendPk Pk of a friend which request is destined to
* @param selfPk Self public key
* @param message Friendship request message
*/
void tryAddFriendRequestToHistory(const ToxPk& friendPk, const ToxPk& selfPk, const QString& msg)
{
Profile* profile = Nexus::getProfile();
if (!profile->isHistoryEnabled()) {
return;
}
QString pkStr = friendPk.toString();
QString inviteStr = Core::tr("/me offers friendship, \"%1\"").arg(msg);
QString selfStr = selfPk.toString();
QDateTime datetime = QDateTime::currentDateTime();
profile->getHistory()->addNewMessage(pkStr, inviteStr, selfStr, datetime, true, QString());
}
void Core::requestFriendship(const ToxId& friendId, const QString& message) void Core::requestFriendship(const ToxId& friendId, const QString& message)
{ {
ToxPk friendPk = friendId.getPublicKey(); ToxPk friendPk = friendId.getPublicKey();
@ -631,11 +611,9 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message)
qDebug() << "Requested friendship of " << friendNumber; qDebug() << "Requested friendship of " << friendNumber;
Settings::getInstance().updateFriendAddress(friendId.toString()); Settings::getInstance().updateFriendAddress(friendId.toString());
// TODO: this really shouldn't be in Core
tryAddFriendRequestToHistory(friendPk, getSelfPublicKey(), message);
emit friendAdded(friendNumber, friendPk); emit friendAdded(friendNumber, friendPk);
emit friendshipChanged(friendNumber); emit friendshipChanged(friendNumber);
emit requestSent(friendPk, message);
} }
profile.saveToxSave(); profile.saveToxSave();

View File

@ -123,6 +123,7 @@ signals:
void friendAdded(uint32_t friendId, const ToxPk& friendPk); void friendAdded(uint32_t friendId, const ToxPk& friendPk);
void friendshipChanged(uint32_t friendId); void friendshipChanged(uint32_t friendId);
void requestSent(const ToxPk& friendPk, const QString& message);
void friendStatusChanged(uint32_t friendId, Status status); void friendStatusChanged(uint32_t friendId, Status status);
void friendStatusMessageChanged(uint32_t friendId, const QString& message); void friendStatusMessageChanged(uint32_t friendId, const QString& message);

View File

@ -199,6 +199,8 @@ void Nexus::showMainGUI()
// Connections // Connections
Core* core = profile->getCore(); Core* core = profile->getCore();
connect(core, &Core::requestSent, profile, &Profile::onRequestSent);
connect(core, &Core::connected, widget, &Widget::onConnected); connect(core, &Core::connected, widget, &Widget::onConnected);
connect(core, &Core::disconnected, widget, &Widget::onDisconnected); connect(core, &Core::disconnected, widget, &Widget::onDisconnected);
connect(core, &Core::failedToStart, widget, &Widget::onFailedToStartCore, connect(core, &Core::failedToStart, widget, &Widget::onFailedToStartCore,

View File

@ -439,6 +439,24 @@ void Profile::loadDatabase(const ToxId& id, QString password)
} }
} }
/**
* @brief Adds history message about friendship request attempt if history is enabled
* @param friendPk Pk of a friend which request is destined to
* @param message Friendship request message
*/
void Profile::onRequestSent(const ToxPk& friendPk, const QString& message)
{
if (!isHistoryEnabled()) {
return;
}
QString pkStr = friendPk.toString();
QString inviteStr = Core::tr("/me offers friendship, \"%1\"").arg(message);
QString selfStr = core->getSelfPublicKey().toString();
QDateTime datetime = QDateTime::currentDateTime();
history->addNewMessage(pkStr, inviteStr, selfStr, datetime, true, QString());
}
/** /**
* @brief Save an avatar to cache. * @brief Save an avatar to cache.
* @param pic Picture to save. * @param pic Picture to save.

View File

@ -80,6 +80,9 @@ public:
static bool isEncrypted(QString name); static bool isEncrypted(QString name);
static QString getDbPath(const QString& profileName); static QString getDbPath(const QString& profileName);
public slots:
void onRequestSent(const ToxPk& friendPk, const QString& message);
private slots: private slots:
void loadDatabase(const ToxId& id, QString password); void loadDatabase(const ToxId& id, QString password);