-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(room): add JoinRequest
subscriptions
#4338
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af15df0
feat(room): add 'seen request to join ids' to the stores
jmartinesp 7244d09
feat(room): add `JoinRequest` abstraction
jmartinesp 4503ed7
feat(room): allow subscribing to requests to join a room
jmartinesp 024da35
feat(ffi): add bindings for subscribing to the join requests
jmartinesp 8ff5f33
Rename `JoinRequest` in the SDK crates to `KnockRequest`, make `Room:…
jmartinesp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ use std::{ | |
|
||
use as_variant::as_variant; | ||
use bitflags::bitflags; | ||
use eyeball::{SharedObservable, Subscriber}; | ||
use eyeball::{AsyncLock, ObservableWriteGuard, SharedObservable, Subscriber}; | ||
use futures_util::{Stream, StreamExt}; | ||
#[cfg(feature = "experimental-sliding-sync")] | ||
use matrix_sdk_common::deserialized_responses::TimelineEventKind; | ||
|
@@ -52,7 +52,7 @@ use ruma::{ | |
}, | ||
tag::{TagEventContent, Tags}, | ||
AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnySyncStateEvent, | ||
RoomAccountDataEventType, SyncStateEvent, | ||
RoomAccountDataEventType, StateEventType, SyncStateEvent, | ||
}, | ||
room::RoomType, | ||
serde::Raw, | ||
|
@@ -77,7 +77,8 @@ use crate::{ | |
read_receipts::RoomReadReceipts, | ||
store::{DynStateStore, Result as StoreResult, StateStoreExt}, | ||
sync::UnreadNotificationsCount, | ||
Error, MinimalStateEvent, OriginalMinimalStateEvent, RoomMemberships, | ||
Error, MinimalStateEvent, OriginalMinimalStateEvent, RoomMemberships, StateStoreDataKey, | ||
StateStoreDataValue, StoreError, | ||
}; | ||
|
||
/// Indicates that a notable update of `RoomInfo` has been applied, and why. | ||
|
@@ -167,6 +168,12 @@ pub struct Room { | |
/// to disk but held in memory. | ||
#[cfg(all(feature = "e2e-encryption", feature = "experimental-sliding-sync"))] | ||
pub latest_encrypted_events: Arc<SyncRwLock<RingBuffer<Raw<AnySyncTimelineEvent>>>>, | ||
|
||
/// A map for ids of room membership events in the knocking state linked to | ||
/// the user id of the user affected by the member event, that the current | ||
/// user has marked as seen so they can be ignored. | ||
pub seen_knock_request_ids_map: | ||
SharedObservable<Option<BTreeMap<OwnedEventId, OwnedUserId>>, AsyncLock>, | ||
} | ||
|
||
/// The room summary containing member counts and members that should be used to | ||
|
@@ -289,6 +296,7 @@ impl Room { | |
Self::MAX_ENCRYPTED_EVENTS, | ||
))), | ||
room_info_notable_update_sender, | ||
seen_knock_request_ids_map: SharedObservable::new_async(None), | ||
} | ||
} | ||
|
||
|
@@ -1169,6 +1177,88 @@ impl Room { | |
pub fn pinned_event_ids(&self) -> Option<Vec<OwnedEventId>> { | ||
self.inner.read().pinned_event_ids() | ||
} | ||
|
||
/// Mark a list of requests to join the room as seen, given their state | ||
/// event ids. | ||
pub async fn mark_knock_requests_as_seen(&self, user_ids: &[OwnedUserId]) -> StoreResult<()> { | ||
let raw_user_ids: Vec<&str> = user_ids.iter().map(|id| id.as_str()).collect(); | ||
let member_raw_events = self | ||
.store | ||
.get_state_events_for_keys(self.room_id(), StateEventType::RoomMember, &raw_user_ids) | ||
.await?; | ||
let mut event_to_user_ids = Vec::with_capacity(member_raw_events.len()); | ||
|
||
// Map the list of events ids to their user ids, if they are event ids for knock | ||
// membership events. Log an error and continue otherwise. | ||
for raw_event in member_raw_events { | ||
let event = raw_event.cast::<RoomMemberEventContent>().deserialize()?; | ||
match event { | ||
SyncOrStrippedState::Sync(SyncStateEvent::Original(event)) => { | ||
if event.content.membership == MembershipState::Knock { | ||
event_to_user_ids.push((event.event_id, event.state_key)) | ||
} else { | ||
warn!("Could not mark knock event as seen: event {} for user {} is not in Knock membership state.", event.event_id, event.state_key); | ||
} | ||
} | ||
_ => warn!( | ||
"Could not mark knock event as seen: event for user {} is not valid.", | ||
event.state_key() | ||
), | ||
} | ||
} | ||
|
||
let mut current_seen_events_guard = self.seen_knock_request_ids_map.write().await; | ||
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. Can you add a small comment that we're not calling |
||
// We're not calling `get_seen_join_request_ids` here because we need to keep | ||
// the Mutex's guard until we've updated the data | ||
let mut current_seen_events = if current_seen_events_guard.is_none() { | ||
self.load_cached_knock_request_ids().await? | ||
} else { | ||
current_seen_events_guard.clone().unwrap() | ||
}; | ||
|
||
current_seen_events.extend(event_to_user_ids); | ||
|
||
ObservableWriteGuard::set( | ||
&mut current_seen_events_guard, | ||
Some(current_seen_events.clone()), | ||
); | ||
|
||
self.store | ||
.set_kv_data( | ||
StateStoreDataKey::SeenKnockRequests(self.room_id()), | ||
StateStoreDataValue::SeenKnockRequests(current_seen_events), | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Get the list of seen knock request event ids in this room. | ||
pub async fn get_seen_knock_request_ids( | ||
&self, | ||
) -> Result<BTreeMap<OwnedEventId, OwnedUserId>, StoreError> { | ||
let mut guard = self.seen_knock_request_ids_map.write().await; | ||
if guard.is_none() { | ||
ObservableWriteGuard::set( | ||
&mut guard, | ||
Some(self.load_cached_knock_request_ids().await?), | ||
); | ||
} | ||
Ok(guard.clone().unwrap_or_default()) | ||
} | ||
|
||
/// This loads the current list of seen knock request ids from the state | ||
/// store. | ||
async fn load_cached_knock_request_ids( | ||
&self, | ||
) -> StoreResult<BTreeMap<OwnedEventId, OwnedUserId>> { | ||
Ok(self | ||
.store | ||
.get_kv_data(StateStoreDataKey::SeenKnockRequests(self.room_id())) | ||
.await? | ||
.and_then(|v| v.into_seen_knock_requests()) | ||
.unwrap_or_default()) | ||
} | ||
} | ||
|
||
// See https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823. | ||
|
@@ -1348,6 +1438,11 @@ impl RoomInfo { | |
self.members_synced = false; | ||
} | ||
|
||
/// Returns whether the room members are synced. | ||
pub fn are_members_synced(&self) -> bool { | ||
self.members_synced | ||
} | ||
|
||
/// Mark this Room as still missing some state information. | ||
pub fn mark_state_partially_synced(&mut self) { | ||
self.sync_info = SyncInfo::PartiallySynced; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it useful to have that here, since it's accessible via a function on
Room
you can get the room id in another way?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.
It's probably not needed, since you'll have some reference to the room when subscribing to the knock requests, but it might be useful to debug if we end up with several subscribers in the clients and we don't know from which room these came from.