Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat: prohibition to remove messages in group chat
Browse files Browse the repository at this point in the history
  • Loading branch information
TriKriSta committed Jul 22, 2019
1 parent 0a9e720 commit 5aeac56
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/chatlog/chatlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/chatlog/chatlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -182,6 +182,7 @@ private slots:

int numRemove{0};
const int maxMessages{300};
bool canRemove;
};

#endif // CHATLOG_H
2 changes: 2 additions & 0 deletions src/model/contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
5 changes: 5 additions & 0 deletions src/model/friend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,8 @@ bool Friend::isOnline() const
{
return friendStatus != Status::Status::Offline && friendStatus != Status::Status::Blocked;
}

bool Friend::useHistory() const
{
return true;
}
2 changes: 2 additions & 0 deletions src/model/friend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/model/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ QString Group::getSelfName() const
return selfName;
}

bool Group::useHistory() const
{
return false;
}

void Group::stopAudioOfDepartedPeers(const ToxPk& peerPk)
{
if (avGroupchat) {
Expand Down
2 changes: 2 additions & 0 deletions src/model/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/widget/form/genericchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5aeac56

Please sign in to comment.