Skip to content

Commit

Permalink
Support for server notices rooms (MSC1452)
Browse files Browse the repository at this point in the history
Closes #326.
  • Loading branch information
KitsuneRal committed Aug 13, 2019
1 parent 18cb395 commit fadce11
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/events/accountdataevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace Quotient {
constexpr const char* FavouriteTag = "m.favourite";
constexpr const char* LowPriorityTag = "m.lowpriority";
constexpr const char* ServerNoticeTag = "m.server_notice";

struct TagRecord {
using order_type = Omittable<float>;
Expand Down
3 changes: 3 additions & 0 deletions lib/jobs/basejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ BaseJob::Status BaseJob::parseError(QNetworkReply* reply,
? tr("Requested room version: %1")
.arg(errorJson.value("room_version"_ls).toString())
: errorJson.value("error"_ls).toString() };
if (errCode == "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM")
return { CannotLeaveRoom,
tr("It's not allowed to leave a server notices room") };

// Not localisable on the client side
if (errorJson.contains("error"_ls))
Expand Down
1 change: 1 addition & 0 deletions lib/jobs/basejob.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class BaseJob : public QObject {
NetworkAuthRequiredError = NetworkAuthRequired,
UserConsentRequired,
UserConsentRequiredError = UserConsentRequired,
CannotLeaveRoom,
UserDefinedError = 256
};

Expand Down
5 changes: 5 additions & 0 deletions lib/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,11 @@ bool Room::isFavourite() const { return d->tags.contains(FavouriteTag); }

bool Room::isLowPriority() const { return d->tags.contains(LowPriorityTag); }

bool Room::isServerNoticeRoom() const
{
return d->tags.contains(ServerNoticeTag);
}

bool Room::isDirectChat() const { return connection()->isDirectChat(id()); }

QList<User*> Room::directChatUsers() const
Expand Down
2 changes: 2 additions & 0 deletions lib/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ class Room : public QObject {
bool isFavourite() const;
/// Check whether the list of tags has m.lowpriority
bool isLowPriority() const;
/// Check whether this room is for server notices (MSC1452)
bool isServerNoticeRoom() const;

/// Check whether this room is a direct chat
Q_INVOKABLE bool isDirectChat() const;
Expand Down

0 comments on commit fadce11

Please sign in to comment.