-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow users to forget rooms #385
Changes from 2 commits
ba26eb3
bed7889
9da4c53
1cfda3d
df6824a
95c3306
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,3 +269,69 @@ def user_rooms_intersect(self, user_id_list): | |
ret = len(room_id_lists.pop(0).intersection(*room_id_lists)) > 0 | ||
|
||
defer.returnValue(ret) | ||
|
||
def forget(self, user_id, room_id): | ||
"""Indicate that user_id wishes to discard history for room_id.""" | ||
def f(txn): | ||
sql = ( | ||
"UPDATE" | ||
" room_memberships" | ||
" SET" | ||
" forgotten = 1" | ||
" WHERE" | ||
" user_id = ?" | ||
" AND" | ||
" room_id = ?" | ||
) | ||
txn.execute(sql, (user_id, room_id)) | ||
self.runInteraction("forget_membership", f) | ||
|
||
@defer.inlineCallbacks | ||
def did_forget(self, user_id, room_id): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
"""Returns whether user_id has elected to discard history for room_id. | ||
|
||
Returns False if they have since re-joined.""" | ||
def f(txn): | ||
sql = ( | ||
"SELECT" | ||
" COUNT(*)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this not just SELECT forgotten FROM room_memberships? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was doing this because it's possible no rooms will be returned, and consistently handling a COUNT is a little cleaner imo than having to handle different rowcounts in python. Now that I look at the schema, though, there are no uniqueness guarantees around room_memberships rows (which should have been obvious, I guess), so I've fixed this up to also cover the forget + re-join cases properly, and added some tests for them. Done something a little different :) |
||
"FROM" | ||
" room_memberships" | ||
" WHERE" | ||
" user_id = ?" | ||
" AND" | ||
" room_id = ?" | ||
" AND" | ||
" forgotten = 0" | ||
) | ||
txn.execute(sql, (user_id, room_id)) | ||
rows = txn.fetchall() | ||
return rows[0][0] | ||
count = yield self.runInteraction("did_forget_membership", f) | ||
defer.returnValue(count == 0) | ||
|
||
@defer.inlineCallbacks | ||
def was_forgotten_at(self, user_id, room_id, event_id): | ||
"""Returns whether user_id has elected to discard history for room_id at event_id. | ||
|
||
event_id must be a membership event.""" | ||
def f(txn): | ||
sql = ( | ||
"SELECT" | ||
" COUNT(*)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't this just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
"FROM" | ||
" room_memberships" | ||
" WHERE" | ||
" user_id = ?" | ||
" AND" | ||
" room_id = ?" | ||
" AND" | ||
" event_id = ?" | ||
" AND" | ||
" forgotten = 1" | ||
) | ||
txn.execute(sql, (user_id, room_id, event_id)) | ||
rows = txn.fetchall() | ||
return rows[0][0] | ||
count = yield self.runInteraction("did_forget_membership_at", f) | ||
defer.returnValue(count == 1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Copyright 2015 OpenMarket Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* Keeps track of what rooms users have left and don't want to be able to | ||
* access again. | ||
* | ||
* If all users on this server have left a room, we can delete the room | ||
* entirely. | ||
*/ | ||
|
||
ALTER TABLE room_memberships ADD COLUMN forgotten INTEGER(1) DEFAULT 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done