2018-09-17 13:01:02 +00:00
|
|
|
#ifndef SpectralRoom_H
|
|
|
|
#define SpectralRoom_H
|
2018-08-18 08:02:47 +00:00
|
|
|
|
|
|
|
#include "room.h"
|
2018-10-22 13:08:24 +00:00
|
|
|
#include "spectraluser.h"
|
2018-08-18 08:02:47 +00:00
|
|
|
|
|
|
|
#include <QObject>
|
2018-11-07 08:29:24 +00:00
|
|
|
#include <QPointer>
|
2018-08-20 14:40:36 +00:00
|
|
|
#include <QTimer>
|
2018-08-18 08:02:47 +00:00
|
|
|
|
2019-04-21 04:41:53 +00:00
|
|
|
#include <events/redactionevent.h>
|
|
|
|
#include <events/roomavatarevent.h>
|
2019-04-21 05:06:48 +00:00
|
|
|
#include <events/roomcreateevent.h>
|
2019-04-21 04:41:53 +00:00
|
|
|
#include <events/roommemberevent.h>
|
2019-04-21 05:06:48 +00:00
|
|
|
#include <events/roommessageevent.h>
|
2019-04-21 04:41:53 +00:00
|
|
|
#include <events/simplestateevents.h>
|
|
|
|
|
2018-08-18 08:02:47 +00:00
|
|
|
using namespace QMatrixClient;
|
|
|
|
|
2018-09-17 13:01:02 +00:00
|
|
|
class SpectralRoom : public Room {
|
2018-08-18 08:02:47 +00:00
|
|
|
Q_OBJECT
|
2018-08-20 14:40:36 +00:00
|
|
|
Q_PROPERTY(bool hasUsersTyping READ hasUsersTyping NOTIFY typingChanged)
|
2018-12-23 03:24:01 +00:00
|
|
|
Q_PROPERTY(QVariantList usersTyping READ getUsersTyping NOTIFY typingChanged)
|
2018-08-18 08:02:47 +00:00
|
|
|
Q_PROPERTY(QString cachedInput READ cachedInput WRITE setCachedInput NOTIFY
|
|
|
|
cachedInputChanged)
|
2018-10-20 14:06:44 +00:00
|
|
|
Q_PROPERTY(bool hasFileUploading READ hasFileUploading NOTIFY
|
|
|
|
hasFileUploadingChanged)
|
|
|
|
Q_PROPERTY(int fileUploadingProgress READ fileUploadingProgress NOTIFY
|
|
|
|
fileUploadingProgressChanged)
|
2018-09-30 14:13:54 +00:00
|
|
|
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
|
|
|
|
2018-08-18 08:02:47 +00:00
|
|
|
public:
|
2019-04-21 05:06:48 +00:00
|
|
|
explicit SpectralRoom(Connection* connection,
|
|
|
|
QString roomId,
|
2018-08-18 08:02:47 +00:00
|
|
|
JoinState joinState = {});
|
|
|
|
|
|
|
|
const QString& cachedInput() const { return m_cachedInput; }
|
|
|
|
void setCachedInput(const QString& input) {
|
|
|
|
if (input != m_cachedInput) {
|
|
|
|
m_cachedInput = input;
|
|
|
|
emit cachedInputChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 14:13:54 +00:00
|
|
|
bool busy() { return m_busy; }
|
|
|
|
void setBusy(bool value) {
|
|
|
|
if (m_busy != value) {
|
|
|
|
m_busy = value;
|
|
|
|
emit busyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 14:40:36 +00:00
|
|
|
bool hasUsersTyping();
|
2018-12-23 03:24:01 +00:00
|
|
|
QVariantList getUsersTyping();
|
2018-08-20 14:40:36 +00:00
|
|
|
|
2018-08-22 15:21:39 +00:00
|
|
|
QString lastEvent();
|
2018-09-06 04:34:15 +00:00
|
|
|
bool isEventHighlighted(const QMatrixClient::RoomEvent* e) const;
|
2018-08-22 15:21:39 +00:00
|
|
|
|
2018-09-18 12:57:38 +00:00
|
|
|
QDateTime lastActiveTime();
|
|
|
|
|
2018-10-20 14:06:44 +00:00
|
|
|
bool hasFileUploading() { return m_hasFileUploading; }
|
|
|
|
void setHasFileUploading(bool value) {
|
|
|
|
if (m_hasFileUploading != value) {
|
|
|
|
m_hasFileUploading = value;
|
|
|
|
emit hasFileUploadingChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int fileUploadingProgress() { return m_fileUploadingProgress; }
|
|
|
|
void setFileUploadingProgress(int value) {
|
|
|
|
if (m_fileUploadingProgress != value) {
|
|
|
|
m_fileUploadingProgress = value;
|
|
|
|
emit fileUploadingProgressChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:47:17 +00:00
|
|
|
Q_INVOKABLE int savedTopVisibleIndex() const;
|
|
|
|
Q_INVOKABLE int savedBottomVisibleIndex() const;
|
|
|
|
Q_INVOKABLE void saveViewport(int topIndex, int bottomIndex);
|
2018-09-19 23:01:55 +00:00
|
|
|
|
2018-10-07 12:38:30 +00:00
|
|
|
Q_INVOKABLE void getPreviousContent(int limit = 10);
|
|
|
|
|
2018-10-22 13:08:24 +00:00
|
|
|
Q_INVOKABLE QVariantList getUsers(const QString& prefix);
|
|
|
|
|
2019-01-18 00:46:50 +00:00
|
|
|
Q_INVOKABLE QString postMarkdownText(const QString& markdown);
|
|
|
|
|
2019-04-21 04:41:53 +00:00
|
|
|
template <typename BaseEventT>
|
|
|
|
QString eventToString(const BaseEventT& evt,
|
|
|
|
Qt::TextFormat format = Qt::PlainText) {
|
|
|
|
bool prettyPrint = (format == Qt::RichText);
|
|
|
|
|
|
|
|
using namespace QMatrixClient;
|
2019-04-21 05:06:48 +00:00
|
|
|
return visit(
|
|
|
|
evt,
|
|
|
|
[this, prettyPrint](const RoomMessageEvent& e) {
|
|
|
|
using namespace MessageEventContent;
|
2019-04-21 04:41:53 +00:00
|
|
|
|
2019-04-21 05:06:48 +00:00
|
|
|
if (prettyPrint && e.hasTextContent() &&
|
|
|
|
e.mimeType().name() != "text/plain")
|
|
|
|
return static_cast<const TextContent*>(e.content())->body;
|
|
|
|
if (e.hasFileContent()) {
|
|
|
|
auto fileCaption =
|
|
|
|
e.content()->fileInfo()->originalName.toHtmlEscaped();
|
|
|
|
if (fileCaption.isEmpty()) {
|
|
|
|
if (prettyPrint)
|
|
|
|
fileCaption = this->prettyPrint(e.plainBody());
|
|
|
|
else
|
|
|
|
fileCaption = e.plainBody();
|
2019-04-21 04:41:53 +00:00
|
|
|
}
|
2019-04-21 05:06:48 +00:00
|
|
|
return !fileCaption.isEmpty() ? fileCaption : tr("a file");
|
|
|
|
}
|
|
|
|
return prettyPrint ? this->prettyPrint(e.plainBody()) : e.plainBody();
|
|
|
|
},
|
|
|
|
[this](const RoomMemberEvent& e) {
|
|
|
|
// FIXME: Rewind to the name that was at the time of this event
|
|
|
|
auto subjectName = this->user(e.userId())->displayname();
|
|
|
|
// The below code assumes senderName output in AuthorRole
|
|
|
|
switch (e.membership()) {
|
|
|
|
case MembershipType::Invite:
|
|
|
|
if (e.repeatsState())
|
|
|
|
return tr("reinvited %1 to the room").arg(subjectName);
|
|
|
|
FALLTHROUGH;
|
|
|
|
case MembershipType::Join: {
|
|
|
|
if (e.repeatsState())
|
|
|
|
return tr("joined the room (repeated)");
|
|
|
|
if (!e.prevContent() ||
|
|
|
|
e.membership() != e.prevContent()->membership) {
|
|
|
|
return e.membership() == MembershipType::Invite
|
|
|
|
? tr("invited %1 to the room").arg(subjectName)
|
|
|
|
: tr("joined the room");
|
|
|
|
}
|
|
|
|
QString text{};
|
|
|
|
if (e.isRename()) {
|
|
|
|
if (e.displayName().isEmpty())
|
|
|
|
text = tr("cleared the display name");
|
|
|
|
else
|
|
|
|
text = tr("changed the display name to %1")
|
|
|
|
.arg(e.displayName().toHtmlEscaped());
|
|
|
|
}
|
|
|
|
if (e.isAvatarUpdate()) {
|
|
|
|
if (!text.isEmpty())
|
|
|
|
text += " and ";
|
|
|
|
if (e.avatarUrl().isEmpty())
|
|
|
|
text += tr("cleared the avatar");
|
|
|
|
else
|
|
|
|
text += tr("updated the avatar");
|
|
|
|
}
|
|
|
|
return text;
|
2019-04-21 04:41:53 +00:00
|
|
|
}
|
2019-04-21 05:06:48 +00:00
|
|
|
case MembershipType::Leave:
|
|
|
|
if (e.prevContent() &&
|
|
|
|
e.prevContent()->membership == MembershipType::Invite) {
|
|
|
|
return (e.senderId() != e.userId())
|
|
|
|
? tr("withdrew %1's invitation").arg(subjectName)
|
|
|
|
: tr("rejected the invitation");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.prevContent() &&
|
|
|
|
e.prevContent()->membership == MembershipType::Ban) {
|
|
|
|
return (e.senderId() != e.userId())
|
|
|
|
? tr("unbanned %1").arg(subjectName)
|
|
|
|
: tr("self-unbanned");
|
|
|
|
}
|
|
|
|
return (e.senderId() != e.userId())
|
|
|
|
? tr("has put %1 out of the room: %2")
|
|
|
|
.arg(subjectName, e.contentJson()["reason"_ls]
|
|
|
|
.toString()
|
|
|
|
.toHtmlEscaped())
|
|
|
|
: tr("left the room");
|
|
|
|
case MembershipType::Ban:
|
|
|
|
return (e.senderId() != e.userId())
|
|
|
|
? tr("banned %1 from the room: %2")
|
|
|
|
.arg(subjectName, e.contentJson()["reason"_ls]
|
|
|
|
.toString()
|
|
|
|
.toHtmlEscaped())
|
|
|
|
: tr("self-banned from the room");
|
|
|
|
case MembershipType::Knock:
|
|
|
|
return tr("knocked");
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
return tr("made something unknown");
|
|
|
|
},
|
|
|
|
[](const RoomAliasesEvent& e) {
|
|
|
|
return tr("has set room aliases on server %1 to: %2")
|
|
|
|
.arg(e.stateKey(), QLocale().createSeparatedList(e.aliases()));
|
|
|
|
},
|
|
|
|
[](const RoomCanonicalAliasEvent& e) {
|
|
|
|
return (e.alias().isEmpty())
|
|
|
|
? tr("cleared the room main alias")
|
|
|
|
: tr("set the room main alias to: %1").arg(e.alias());
|
|
|
|
},
|
|
|
|
[](const RoomNameEvent& e) {
|
|
|
|
return (e.name().isEmpty()) ? tr("cleared the room name")
|
|
|
|
: tr("set the room name to: %1")
|
|
|
|
.arg(e.name().toHtmlEscaped());
|
|
|
|
},
|
|
|
|
[this, prettyPrint](const RoomTopicEvent& e) {
|
|
|
|
return (e.topic().isEmpty())
|
|
|
|
? tr("cleared the topic")
|
|
|
|
: tr("set the topic to: %1")
|
|
|
|
.arg(prettyPrint ? this->prettyPrint(e.topic())
|
|
|
|
: e.topic());
|
|
|
|
},
|
|
|
|
[](const RoomAvatarEvent&) { return tr("changed the room avatar"); },
|
|
|
|
[](const EncryptionEvent&) {
|
|
|
|
return tr("activated End-to-End Encryption");
|
|
|
|
},
|
|
|
|
[](const RoomCreateEvent& e) {
|
|
|
|
return (e.isUpgrade() ? tr("upgraded the room to version %1")
|
|
|
|
: tr("created the room, version %1"))
|
|
|
|
.arg(e.version().isEmpty() ? "1" : e.version().toHtmlEscaped());
|
|
|
|
},
|
|
|
|
[](const StateEventBase& e) {
|
|
|
|
// A small hack for state events from TWIM bot
|
|
|
|
return e.stateKey() == "twim"
|
|
|
|
? tr("updated the database",
|
|
|
|
"TWIM bot updated the database")
|
|
|
|
: e.stateKey().isEmpty()
|
|
|
|
? tr("updated %1 state", "%1 - Matrix event type")
|
|
|
|
.arg(e.matrixType())
|
|
|
|
: tr("updated %1 state for %2",
|
|
|
|
"%1 - Matrix event type, %2 - state key")
|
|
|
|
.arg(e.matrixType(),
|
|
|
|
e.stateKey().toHtmlEscaped());
|
|
|
|
},
|
|
|
|
tr("Unknown event"));
|
2019-04-21 04:41:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-18 08:02:47 +00:00
|
|
|
private:
|
2018-08-19 06:32:18 +00:00
|
|
|
QString m_cachedInput;
|
2018-09-06 04:34:15 +00:00
|
|
|
QSet<const QMatrixClient::RoomEvent*> highlights;
|
2018-08-18 08:02:47 +00:00
|
|
|
|
2018-10-20 14:06:44 +00:00
|
|
|
bool m_hasFileUploading = false;
|
|
|
|
int m_fileUploadingProgress = 0;
|
|
|
|
|
2018-11-07 08:29:24 +00:00
|
|
|
bool m_busy = false;
|
2018-09-30 14:13:54 +00:00
|
|
|
|
2018-09-06 04:34:15 +00:00
|
|
|
void checkForHighlights(const QMatrixClient::TimelineItem& ti);
|
|
|
|
|
|
|
|
void onAddNewTimelineEvents(timeline_iter_t from) override;
|
|
|
|
void onAddHistoricalTimelineEvents(rev_iter_t from) override;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void countChanged();
|
|
|
|
|
2018-08-18 08:02:47 +00:00
|
|
|
signals:
|
|
|
|
void cachedInputChanged();
|
2018-09-30 14:13:54 +00:00
|
|
|
void busyChanged();
|
2018-10-20 14:06:44 +00:00
|
|
|
void hasFileUploadingChanged();
|
|
|
|
void fileUploadingProgressChanged();
|
2018-08-18 08:02:47 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void chooseAndUploadFile();
|
|
|
|
void saveFileAs(QString eventId);
|
|
|
|
void acceptInvitation();
|
|
|
|
void forget();
|
2018-08-20 14:40:36 +00:00
|
|
|
void sendTypingNotification(bool isTyping);
|
2019-04-21 05:06:48 +00:00
|
|
|
void sendReply(QString userId,
|
|
|
|
QString eventId,
|
|
|
|
QString replyContent,
|
2018-09-18 12:57:38 +00:00
|
|
|
QString sendContent);
|
2018-08-18 08:02:47 +00:00
|
|
|
};
|
|
|
|
|
2018-09-17 13:01:02 +00:00
|
|
|
#endif // SpectralRoom_H
|