diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2024-03-08 18:43:59 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2024-03-08 18:45:18 +0100 |
commit | 7c2a152cfbc2197989f7d722deb961ac80269019 (patch) | |
tree | 1ff5bc7c938ceb2242a0d769f9f64ef5e980f683 /src/timeline/InputBar.h | |
parent | Fix buttons vanishing on the kde themes in the settings page (diff) | |
download | nheko-7c2a152cfbc2197989f7d722deb961ac80269019.tar.xz |
Add support for intentional mentions
This is still a bit flaky around when to remove a mention, but it should work in most cases. Might add a toggle in the future to disable these though.
Diffstat (limited to 'src/timeline/InputBar.h')
-rw-r--r-- | src/timeline/InputBar.h | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index fbf08343..c38de662 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -158,12 +158,12 @@ class InputBar final : public QObject { Q_OBJECT Q_PROPERTY(bool uploading READ uploading NOTIFY uploadingChanged) - Q_PROPERTY(bool containsAtRoom READ containsAtRoom NOTIFY containsAtRoomChanged) Q_PROPERTY( bool containsInvalidCommand READ containsInvalidCommand NOTIFY containsInvalidCommandChanged) Q_PROPERTY(bool containsIncompleteCommand READ containsIncompleteCommand NOTIFY containsIncompleteCommandChanged) Q_PROPERTY(QString currentCommand READ currentCommand NOTIFY currentCommandChanged) + Q_PROPERTY(QStringList mentions READ mentions NOTIFY mentionsChanged) Q_PROPERTY(QString text READ text NOTIFY textChanged) Q_PROPERTY(QVariantList uploads READ uploads NOTIFY uploadsChanged) @@ -188,7 +188,37 @@ public slots: QString nextText(); void setText(const QString &newText); - [[nodiscard]] bool containsAtRoom() const { return containsAtRoom_; } + [[nodiscard]] QStringList mentions() const { return mentions_; } + void addMention(QString m, QString text); + void removeMention(QString m); + + void storeForEdit() + { + textBeforeEdit = text(); + mentionsBefore = mentions_; + mentionTextsBefore = mentionTexts_; + emit mentionsChanged(); + } + void restoreAfterEdit() + { + mentions_ = mentionsBefore; + mentionTexts_ = mentionTextsBefore; + mentionsBefore.clear(); + mentionTextsBefore.clear(); + setText(textBeforeEdit); + textBeforeEdit.clear(); + emit mentionsChanged(); + } + void replaceMentions(QStringList newMentions, QStringList newMentionTexts) + { + if (newMentions.size() != newMentionTexts.size()) + return; + + mentions_ = newMentions; + mentionTexts_ = newMentionTexts; + emit mentionsChanged(); + } + bool containsInvalidCommand() const { return containsInvalidCommand_; } bool containsIncompleteCommand() const { return containsIncompleteCommand_; } QString currentCommand() const { return currentCommand_; } @@ -218,8 +248,8 @@ private slots: signals: void textChanged(QString newText); void uploadingChanged(bool value); - void containsAtRoomChanged(); void containsInvalidCommandChanged(); + void mentionsChanged(); void containsIncompleteCommandChanged(); void currentCommandChanged(); void uploadsChanged(); @@ -269,6 +299,7 @@ private: QPair<QString, QString> getCommandAndArgs() const { return getCommandAndArgs(text()); } QPair<QString, QString> getCommandAndArgs(const QString ¤tText) const; mtx::common::Relations generateRelations() const; + mtx::common::Mentions generateMentions(); void startUploadFromPath(const QString &path); void startUploadFromMimeData(const QMimeData &source, const QString &format); @@ -281,7 +312,7 @@ private: } } - void updateTextContentProperties(const QString &t); + void updateTextContentProperties(const QString &t, bool textDeleted = false); void toggleIgnore(const QString &user, const bool ignored); @@ -296,6 +327,10 @@ private: bool containsInvalidCommand_ = false; bool containsIncompleteCommand_ = false; QString currentCommand_; + QStringList mentions_, mentionTexts_; + // store stuff during edits + QStringList mentionsBefore, mentionTextsBefore; + QString textBeforeEdit; using UploadHandle = std::unique_ptr<MediaUpload, DeleteLaterDeleter>; std::vector<UploadHandle> unconfirmedUploads; |