Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Add support for read room access #324

Merged
merged 6 commits into from
May 12, 2018

Conversation

twahm
Copy link
Contributor

@twahm twahm commented May 11, 2018

In Room settings you can see who can join to the room, whether it's just the inviteds, anyone or anyone including guests.

I would have liked to implement the possibility of changing it, but I am not familiar with the source code and I did not find a similar function with which I could be oriented.

src/Cache.cc Outdated
if (res) {
try {
StateEvent<GuestAccess> msg = json::parse(std::string(event.data(), event.size()));
if (msg.content.guest_access == AccessState::CanJoin)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just write is as return msg.content.guest_access == AccessState::CanJoin.

Copy link
Owner

@mujx mujx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot of the PR!

In order to change data on the server, you'll have to use the HTTP client API. The cache is read only by the client which means that only the events from /sync are written to it.

src/Cache.cc Outdated
return false;
}
catch (const json::exception &e) {
qWarning() << QString::fromStdString(e.what());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the QString::fromStdString method here.

src/Cache.cc Outdated
@@ -435,6 +435,8 @@ Cache::saveState(const mtx::responses::Sync &res)
updatedInfo.avatar_url =
getRoomAvatarUrl(txn, statesdb, membersdb, QString::fromStdString(room.first))
.toStdString();
updatedInfo.join_rule = getRoomJoinRules(txn, statesdb);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already saved in the states db. You can remove those lines.

src/Cache.cc Outdated
@@ -467,6 +469,8 @@ Cache::saveInvites(lmdb::txn &txn, const std::map<std::string, mtx::responses::I
updatedInfo.avatar_url =
getInviteRoomAvatarUrl(txn, statesdb, membersdb).toStdString();
updatedInfo.is_invite = true;
updatedInfo.join_rule = getRoomJoinRules(txn, statesdb);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

include/Cache.h Outdated
@@ -164,6 +169,9 @@ class Cache : public QObject

//! Calculate & return the name of the room.
QString getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb);
//! Get room join rules
JoinRule getRoomJoinRules(lmdb::txn &txn, lmdb::dbi &statesdb);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: getRoomJoinRule


void
RoomSettings::save_and_close() {
// TODO: Save access changes to the room
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/Cache.cc Outdated
return msg.content.join_rule;
}
catch (const json::exception &e) {
qWarning() << QString::fromStdString(e.what());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for QString::fromStdString

src/Cache.cc Outdated
@@ -604,6 +611,8 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms)
RoomInfo tmp =
json::parse(std::string(data.data(), data.size()));
tmp.member_count = getInviteMembersDb(txn, room).size(txn);
tmp.join_rule = getRoomJoinRules(txn, statesdb);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invited rooms are not viewable in nheko so we don't need those.

src/Cache.cc Outdated

// Check if the room is joined.
if (lmdb::dbi_get(txn, roomsDb_, lmdb::val(room), data)) {
try {
RoomInfo tmp = json::parse(std::string(data.data(), data.size()));
tmp.member_count = getMembersDb(txn, room).size(txn);
tmp.join_rule = getRoomJoinRules(txn, statesdb);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you copy those lines in Cache::singleRoomInfo also, and make the RoomSettings page call that method instead of Cache::getRoomInfo.

include/Cache.h Outdated
@@ -74,6 +76,9 @@ struct RoomInfo
bool is_invite = false;
//! Total number of members in the room.
int16_t member_count = 0;
//! Who can access to the room.
JoinRule join_rule = JoinRule::Public;
bool guest_access = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add those in the to_json & from_json methods also.

https://github.com/nlohmann/json#basic-usage

accessCombo = new QComboBox(this);
accessCombo->addItem(tr("Anyone and guests"));
accessCombo->addItem(tr("Anyone"));
accessCombo->addItem(tr("Inviteds"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invited users

accessCombo->setDisabled(true);
accessLabel->setStyleSheet("font-size: 15px;");

if(info_.join_rule == JoinRule::Public)
Copy link
Owner

@mujx mujx May 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some braces around the outer if/else statement.

@mujx mujx merged commit 4bd4378 into mujx:master May 12, 2018
vurpo pushed a commit to vurpo/nheko that referenced this pull request Jun 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants