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/core.h"
|
||||||
#include "src/core/coreav.h"
|
#include "src/core/coreav.h"
|
||||||
#include "src/model/friend.h"
|
#include "src/model/friend.h"
|
||||||
#include "src/nexus.h"
|
|
||||||
#include "src/persistence/offlinemsgengine.h"
|
#include "src/persistence/offlinemsgengine.h"
|
||||||
#include "src/persistence/profile.h"
|
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
|
#include "src/persistence/history.h"
|
||||||
#include "src/video/netcamview.h"
|
#include "src/video/netcamview.h"
|
||||||
#include "src/widget/chatformheader.h"
|
#include "src/widget/chatformheader.h"
|
||||||
#include "src/widget/form/loadhistorydialog.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)
|
: f(chatFriend)
|
||||||
, callDuration(new QLabel(this))
|
, callDuration(new QLabel(this))
|
||||||
, isTyping(false)
|
, isTyping(false)
|
||||||
|
, history{history}
|
||||||
, lastCallIsVideo{false}
|
, lastCallIsVideo{false}
|
||||||
{
|
{
|
||||||
setName(f->getDisplayedName());
|
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();
|
QString pk = f->getPublicKey().toString();
|
||||||
QList<History::HistMessage> msgs = history->getChatHistory(pk, since, now);
|
QList<History::HistMessage> msgs = history->getChatHistory(pk, since, now);
|
||||||
|
|
||||||
@ -787,7 +786,7 @@ void ChatForm::sendImage(const QPixmap& pixmap)
|
|||||||
|
|
||||||
void ChatForm::onLoadHistory()
|
void ChatForm::onLoadHistory()
|
||||||
{
|
{
|
||||||
if (!Nexus::getProfile()->isHistoryEnabled()) {
|
if (!history) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,13 +923,12 @@ void ChatForm::SendMessageStr(QString msg)
|
|||||||
uint32_t friendId = f->getId();
|
uint32_t friendId = f->getId();
|
||||||
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
|
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
|
||||||
|
|
||||||
Profile* profile = Nexus::getProfile();
|
if (history) {
|
||||||
if (profile->isHistoryEnabled()) {
|
|
||||||
auto* offMsgEngine = getOfflineMsgEngine();
|
auto* offMsgEngine = getOfflineMsgEngine();
|
||||||
QString selfPk = Core::getInstance()->getSelfId().toString();
|
QString selfPk = Core::getInstance()->getSelfId().toString();
|
||||||
QString pk = f->getPublicKey().toString();
|
QString pk = f->getPublicKey().toString();
|
||||||
QString name = Core::getInstance()->getUsername();
|
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, rec, ma](int64_t id) {
|
||||||
offMsgEngine->registerReceipt(rec, id, ma);
|
offMsgEngine->registerReceipt(rec, id, ma);
|
||||||
});
|
});
|
||||||
@ -961,7 +959,6 @@ void ChatForm::retranslateUi()
|
|||||||
|
|
||||||
void ChatForm::onExportChat()
|
void ChatForm::onExportChat()
|
||||||
{
|
{
|
||||||
History* history = Nexus::getProfile()->getHistory();
|
|
||||||
QString pk = f->getPublicKey().toString();
|
QString pk = f->getPublicKey().toString();
|
||||||
QDateTime epochStart = QDateTime::fromMSecsSinceEpoch(0);
|
QDateTime epochStart = QDateTime::fromMSecsSinceEpoch(0);
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
|
@ -27,23 +27,23 @@
|
|||||||
|
|
||||||
#include "genericchatform.h"
|
#include "genericchatform.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/persistence/history.h"
|
|
||||||
#include "src/widget/tool/screenshotgrabber.h"
|
#include "src/widget/tool/screenshotgrabber.h"
|
||||||
|
|
||||||
class Friend;
|
|
||||||
class FileTransferInstance;
|
|
||||||
class QPixmap;
|
|
||||||
class CallConfirmWidget;
|
class CallConfirmWidget;
|
||||||
|
class CoreAV;
|
||||||
|
class FileTransferInstance;
|
||||||
|
class Friend;
|
||||||
|
class History;
|
||||||
|
class OfflineMsgEngine;
|
||||||
|
class QPixmap;
|
||||||
class QHideEvent;
|
class QHideEvent;
|
||||||
class QMoveEvent;
|
class QMoveEvent;
|
||||||
class OfflineMsgEngine;
|
|
||||||
class CoreAV;
|
|
||||||
|
|
||||||
class ChatForm : public GenericChatForm
|
class ChatForm : public GenericChatForm
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ChatForm(Friend* chatFriend);
|
ChatForm(Friend* chatFriend, History* history);
|
||||||
~ChatForm();
|
~ChatForm();
|
||||||
void setStatusMessage(const QString& newMessage);
|
void setStatusMessage(const QString& newMessage);
|
||||||
void loadHistory(const QDateTime& since, bool processUndelivered = false);
|
void loadHistory(const QDateTime& since, bool processUndelivered = false);
|
||||||
@ -132,6 +132,7 @@ private:
|
|||||||
QAction* copyStatusAction;
|
QAction* copyStatusAction;
|
||||||
QAction* exportChatAction;
|
QAction* exportChatAction;
|
||||||
|
|
||||||
|
History* history;
|
||||||
QHash<uint, FileTransferInstance*> ftransWidgets;
|
QHash<uint, FileTransferInstance*> ftransWidgets;
|
||||||
bool isTyping;
|
bool isTyping;
|
||||||
bool lastCallIsVideo;
|
bool lastCallIsVideo;
|
||||||
|
@ -975,7 +975,8 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
|||||||
Friend* newfriend = FriendList::addFriend(friendId, friendPk);
|
Friend* newfriend = FriendList::addFriend(friendId, friendPk);
|
||||||
bool compact = s.getCompactLayout();
|
bool compact = s.getCompactLayout();
|
||||||
FriendWidget* widget = new FriendWidget(newfriend, compact);
|
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);
|
newfriend->setChatForm(friendForm);
|
||||||
|
|
||||||
friendWidgets[friendId] = widget;
|
friendWidgets[friendId] = widget;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user