mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(chatform): Remove Nexus and Profile dependency from ChatForm
This commit is contained in:
parent
531defd0aa
commit
6780331f40
|
@ -28,10 +28,9 @@
|
|||
#include "src/core/core.h"
|
||||
#include "src/core/coreav.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/offlinemsgengine.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/persistence/history.h"
|
||||
#include "src/video/netcamview.h"
|
||||
#include "src/widget/chatformheader.h"
|
||||
#include "src/widget/form/loadhistorydialog.h"
|
||||
|
@ -109,10 +108,11 @@ QString secondsToDHMS(quint32 duration)
|
|||
}
|
||||
|
||||
|
||||
ChatForm::ChatForm(Friend* chatFriend)
|
||||
ChatForm::ChatForm(Friend* chatFriend, History* history)
|
||||
: f(chatFriend)
|
||||
, callDuration(new QLabel(this))
|
||||
, isTyping(false)
|
||||
, history{history}
|
||||
, lastCallIsVideo{false}
|
||||
{
|
||||
setName(f->getDisplayedName());
|
||||
|
@ -679,7 +679,6 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
|||
}
|
||||
}
|
||||
|
||||
History* history = Nexus::getProfile()->getHistory();
|
||||
QString pk = f->getPublicKey().toString();
|
||||
QList<History::HistMessage> msgs = history->getChatHistory(pk, since, now);
|
||||
|
||||
|
@ -787,7 +786,7 @@ void ChatForm::sendImage(const QPixmap& pixmap)
|
|||
|
||||
void ChatForm::onLoadHistory()
|
||||
{
|
||||
if (!Nexus::getProfile()->isHistoryEnabled()) {
|
||||
if (!history) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -924,13 +923,12 @@ void ChatForm::SendMessageStr(QString msg)
|
|||
uint32_t friendId = f->getId();
|
||||
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
|
||||
|
||||
Profile* profile = Nexus::getProfile();
|
||||
if (profile->isHistoryEnabled()) {
|
||||
if (history) {
|
||||
auto* offMsgEngine = getOfflineMsgEngine();
|
||||
QString selfPk = Core::getInstance()->getSelfId().toString();
|
||||
QString pk = f->getPublicKey().toString();
|
||||
QString name = Core::getInstance()->getUsername();
|
||||
profile->getHistory()->addNewMessage(pk, historyPart, selfPk, timestamp, status, name,
|
||||
history->addNewMessage(pk, historyPart, selfPk, timestamp, status, name,
|
||||
[offMsgEngine, rec, ma](int64_t id) {
|
||||
offMsgEngine->registerReceipt(rec, id, ma);
|
||||
});
|
||||
|
@ -961,7 +959,6 @@ void ChatForm::retranslateUi()
|
|||
|
||||
void ChatForm::onExportChat()
|
||||
{
|
||||
History* history = Nexus::getProfile()->getHistory();
|
||||
QString pk = f->getPublicKey().toString();
|
||||
QDateTime epochStart = QDateTime::fromMSecsSinceEpoch(0);
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
|
|
|
@ -27,23 +27,23 @@
|
|||
|
||||
#include "genericchatform.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/persistence/history.h"
|
||||
#include "src/widget/tool/screenshotgrabber.h"
|
||||
|
||||
class Friend;
|
||||
class FileTransferInstance;
|
||||
class QPixmap;
|
||||
class CallConfirmWidget;
|
||||
class CoreAV;
|
||||
class FileTransferInstance;
|
||||
class Friend;
|
||||
class History;
|
||||
class OfflineMsgEngine;
|
||||
class QPixmap;
|
||||
class QHideEvent;
|
||||
class QMoveEvent;
|
||||
class OfflineMsgEngine;
|
||||
class CoreAV;
|
||||
|
||||
class ChatForm : public GenericChatForm
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ChatForm(Friend* chatFriend);
|
||||
ChatForm(Friend* chatFriend, History* history);
|
||||
~ChatForm();
|
||||
void setStatusMessage(const QString& newMessage);
|
||||
void loadHistory(const QDateTime& since, bool processUndelivered = false);
|
||||
|
@ -132,6 +132,7 @@ private:
|
|||
QAction* copyStatusAction;
|
||||
QAction* exportChatAction;
|
||||
|
||||
History* history;
|
||||
QHash<uint, FileTransferInstance*> ftransWidgets;
|
||||
bool isTyping;
|
||||
bool lastCallIsVideo;
|
||||
|
|
|
@ -975,7 +975,8 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
|||
Friend* newfriend = FriendList::addFriend(friendId, friendPk);
|
||||
bool compact = s.getCompactLayout();
|
||||
FriendWidget* widget = new FriendWidget(newfriend, compact);
|
||||
ChatForm* friendForm = new ChatForm(newfriend);
|
||||
History* history = Nexus::getProfile()->getHistory();
|
||||
ChatForm* friendForm = new ChatForm(newfriend, history);
|
||||
newfriend->setChatForm(friendForm);
|
||||
|
||||
friendWidgets[friendId] = widget;
|
||||
|
|
Loading…
Reference in New Issue
Block a user