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

feat: prohibition to remove messages in group chat

This commit is contained in:
TriKriSta 2019-07-01 14:48:10 +03:00
parent 0a9e72020e
commit 5aeac56b76
8 changed files with 23 additions and 8 deletions

View File

@ -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<ChatLine::Ptr>& 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<ChatLine::Ptr>& 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()) {

View File

@ -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:
int numRemove{0};
const int maxMessages{300};
bool canRemove;
};
#endif // CHATLOG_H

View File

@ -37,6 +37,8 @@ public:
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);
};

View File

@ -166,3 +166,8 @@ bool Friend::isOnline() const
{
return friendStatus != Status::Status::Offline && friendStatus != Status::Status::Blocked;
}
bool Friend::useHistory() const
{
return true;
}

View File

@ -55,6 +55,8 @@ public:
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);

View File

@ -205,6 +205,11 @@ QString Group::getSelfName() const
return selfName;
}
bool Group::useHistory() const
{
return false;
}
void Group::stopAudioOfDepartedPeers(const ToxPk& peerPk)
{
if (avGroupchat) {

View File

@ -61,6 +61,8 @@ public:
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);

View File

@ -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);