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:
parent
b25f5b5ed6
commit
49e9eb8de2
|
@ -592,26 +592,6 @@ QString Core::getFriendRequestErrorMessage(const ToxId& friendId, const 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)
|
||||
{
|
||||
ToxPk friendPk = friendId.getPublicKey();
|
||||
|
@ -631,11 +611,9 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message)
|
|||
qDebug() << "Requested friendship of " << friendNumber;
|
||||
Settings::getInstance().updateFriendAddress(friendId.toString());
|
||||
|
||||
// TODO: this really shouldn't be in Core
|
||||
tryAddFriendRequestToHistory(friendPk, getSelfPublicKey(), message);
|
||||
|
||||
emit friendAdded(friendNumber, friendPk);
|
||||
emit friendshipChanged(friendNumber);
|
||||
emit requestSent(friendPk, message);
|
||||
}
|
||||
|
||||
profile.saveToxSave();
|
||||
|
|
|
@ -123,6 +123,7 @@ signals:
|
|||
|
||||
void friendAdded(uint32_t friendId, const ToxPk& friendPk);
|
||||
void friendshipChanged(uint32_t friendId);
|
||||
void requestSent(const ToxPk& friendPk, const QString& message);
|
||||
|
||||
void friendStatusChanged(uint32_t friendId, Status status);
|
||||
void friendStatusMessageChanged(uint32_t friendId, const QString& message);
|
||||
|
|
|
@ -199,6 +199,8 @@ void Nexus::showMainGUI()
|
|||
|
||||
// Connections
|
||||
Core* core = profile->getCore();
|
||||
connect(core, &Core::requestSent, profile, &Profile::onRequestSent);
|
||||
|
||||
connect(core, &Core::connected, widget, &Widget::onConnected);
|
||||
connect(core, &Core::disconnected, widget, &Widget::onDisconnected);
|
||||
connect(core, &Core::failedToStart, widget, &Widget::onFailedToStartCore,
|
||||
|
|
|
@ -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.
|
||||
* @param pic Picture to save.
|
||||
|
|
|
@ -80,6 +80,9 @@ public:
|
|||
static bool isEncrypted(QString name);
|
||||
static QString getDbPath(const QString& profileName);
|
||||
|
||||
public slots:
|
||||
void onRequestSent(const ToxPk& friendPk, const QString& message);
|
||||
|
||||
private slots:
|
||||
void loadDatabase(const ToxId& id, QString password);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user