diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 6e761753f0..5dd1133659 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -49,8 +49,8 @@ T clamp(T x, T min, T max) return x; } -ChatLog::ChatLog(QWidget* parent) - : QGraphicsView(parent) +ChatLog::ChatLog(const bool canRemove, QWidget* parent) + : QGraphicsView(parent), canRemove(canRemove) { // Create the scene busyScene = new QGraphicsScene(this); @@ -391,7 +391,7 @@ void ChatLog::insertChatlineAtBottom(const QList& newLines) if (newLines.isEmpty()) return; - if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { + if (canRemove && lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { removeFirsts(DEF_NUM_MSG_TO_LOAD); } @@ -442,7 +442,7 @@ void ChatLog::insertChatlinesOnTop(const QList& newLines) combLines.push_back(l); } - if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { + if (canRemove && lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { removeLasts(DEF_NUM_MSG_TO_LOAD); } @@ -804,7 +804,6 @@ void ChatLog::checkVisibility(bool causedWheelEvent) } if (causedWheelEvent) { - qDebug() << "causedWheelEvent"; if (lowerBound != lines.cend() && lowerBound->get()->row == 0) { emit loadHistoryLower(); } else if (upperBound == lines.cend()) { diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 61c63304cc..81e8c1d439 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -41,7 +41,7 @@ class ChatLog : public QGraphicsView { Q_OBJECT public: - explicit ChatLog(QWidget* parent = nullptr); + explicit ChatLog(const bool canRemove, QWidget* parent = nullptr); virtual ~ChatLog(); void insertChatlineAtBottom(ChatLine::Ptr l); @@ -182,6 +182,7 @@ private slots: int numRemove{0}; const int maxMessages{300}; + bool canRemove; }; #endif // CHATLOG_H diff --git a/src/model/contact.h b/src/model/contact.h index e2faa57997..182d1ce90b 100644 --- a/src/model/contact.h +++ b/src/model/contact.h @@ -37,6 +37,8 @@ class Contact : public QObject virtual void setEventFlag(bool flag) = 0; virtual bool getEventFlag() const = 0; + virtual bool useHistory() const = 0; // TODO: remove after added history in group chat + signals: void displayedNameChanged(const QString& newName); }; diff --git a/src/model/friend.cpp b/src/model/friend.cpp index abb2bd6bbb..08f80dadfb 100644 --- a/src/model/friend.cpp +++ b/src/model/friend.cpp @@ -166,3 +166,8 @@ bool Friend::isOnline() const { return friendStatus != Status::Status::Offline && friendStatus != Status::Status::Blocked; } + +bool Friend::useHistory() const +{ + return true; +} diff --git a/src/model/friend.h b/src/model/friend.h index b62fceb1f4..a3eaee7906 100644 --- a/src/model/friend.h +++ b/src/model/friend.h @@ -55,6 +55,8 @@ class Friend : public Contact Status::Status getStatus() const; bool isOnline() const; + bool useHistory() const override final; + signals: void nameChanged(const ToxPk& friendId, const QString& name); void aliasChanged(const ToxPk& friendId, QString alias); diff --git a/src/model/group.cpp b/src/model/group.cpp index 39f7e58ab9..f08d4397dc 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -205,6 +205,11 @@ QString Group::getSelfName() const return selfName; } +bool Group::useHistory() const +{ + return false; +} + void Group::stopAudioOfDepartedPeers(const ToxPk& peerPk) { if (avGroupchat) { diff --git a/src/model/group.h b/src/model/group.h index 4e70a407ec..fd19461ca9 100644 --- a/src/model/group.h +++ b/src/model/group.h @@ -61,6 +61,8 @@ class Group : public Contact void setSelfName(const QString& name); QString getSelfName() const; + bool useHistory() const override final; + signals: void titleChangedByUser(const QString& title); void titleChanged(const QString& author, const QString& title); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 0beb03a021..ebde18293d 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -261,7 +261,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog, headWidget = new ChatFormHeader(); searchForm = new SearchForm(); dateInfo = new QLabel(this); - chatWidget = new ChatLog(this); + chatWidget = new ChatLog(contact->useHistory(), this); chatWidget->setBusyNotification(ChatMessage::createBusyNotification()); searchForm->hide(); dateInfo->setAlignment(Qt::AlignHCenter); @@ -703,7 +703,6 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time) int add = DEF_NUM_MSG_TO_LOAD; if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) { - auto aTest = chatLog.getNextIdx().get(); add = chatLog.getNextIdx().get() - begin.get(); } auto end = ChatLogIdx(begin.get() + add);