-
Notifications
You must be signed in to change notification settings - Fork 246
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
chore(room_list): allow knock state event as latest_event
#4170
Changes from all commits
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 |
---|---|---|
|
@@ -12,7 +12,17 @@ use ruma::events::{ | |
room::message::SyncRoomMessageEvent, | ||
AnySyncMessageLikeEvent, AnySyncTimelineEvent, | ||
}; | ||
use ruma::{events::sticker::SyncStickerEvent, MxcUri, OwnedEventId}; | ||
use ruma::{ | ||
events::{ | ||
room::{ | ||
member::{MembershipState, SyncRoomMemberEvent}, | ||
power_levels::RoomPowerLevels, | ||
}, | ||
sticker::SyncStickerEvent, | ||
AnySyncStateEvent, | ||
}, | ||
MxcUri, OwnedEventId, UserId, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::MinimalRoomMemberEvent; | ||
|
@@ -37,6 +47,10 @@ pub enum PossibleLatestEvent<'a> { | |
/// This message is suitable - it's a call notification | ||
YesCallNotify(&'a SyncCallNotifyEvent), | ||
|
||
/// This state event is suitable - it's a knock membership change | ||
/// that can be handled by the current user. | ||
YesKnockedStateEvent(&'a SyncRoomMemberEvent), | ||
|
||
// Later: YesState(), | ||
// Later: YesReaction(), | ||
/// Not suitable - it's a state event | ||
|
@@ -50,7 +64,10 @@ pub enum PossibleLatestEvent<'a> { | |
/// Decide whether an event could be stored as the latest event in a room. | ||
/// Returns a LatestEvent representing our decision. | ||
#[cfg(feature = "e2e-encryption")] | ||
pub fn is_suitable_for_latest_event(event: &AnySyncTimelineEvent) -> PossibleLatestEvent<'_> { | ||
pub fn is_suitable_for_latest_event<'a>( | ||
event: &'a AnySyncTimelineEvent, | ||
power_levels_info: Option<(&'a UserId, &'a RoomPowerLevels)>, | ||
) -> PossibleLatestEvent<'a> { | ||
match event { | ||
// Suitable - we have an m.room.message that was not redacted or edited | ||
AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(message)) => { | ||
|
@@ -102,8 +119,29 @@ pub fn is_suitable_for_latest_event(event: &AnySyncTimelineEvent) -> PossibleLat | |
// suitable | ||
AnySyncTimelineEvent::MessageLike(_) => PossibleLatestEvent::NoUnsupportedMessageLikeType, | ||
|
||
// We don't currently support state events | ||
AnySyncTimelineEvent::State(_) => PossibleLatestEvent::NoUnsupportedEventType, | ||
// We don't currently support most state events | ||
AnySyncTimelineEvent::State(state) => { | ||
// But we make an exception for knocked state events *if* the current user | ||
// can either accept or decline them | ||
if let AnySyncStateEvent::RoomMember(member) = state { | ||
if matches!(member.membership(), MembershipState::Knock) { | ||
let can_accept_or_decline_knocks = match power_levels_info { | ||
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. Would it make sense to move this logic to within the 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'm not sure it's worth it, since it'll only be used here (I hope). |
||
Some((own_user_id, room_power_levels)) => { | ||
room_power_levels.user_can_invite(own_user_id) | ||
|| room_power_levels.user_can_kick(own_user_id) | ||
} | ||
_ => false, | ||
}; | ||
|
||
// The current user can act on the knock changes, so they should be | ||
// displayed | ||
if can_accept_or_decline_knocks { | ||
return PossibleLatestEvent::YesKnockedStateEvent(member); | ||
} | ||
} | ||
} | ||
PossibleLatestEvent::NoUnsupportedEventType | ||
} | ||
} | ||
} | ||
|
||
|
@@ -327,7 +365,7 @@ mod tests { | |
)); | ||
assert_let!( | ||
PossibleLatestEvent::YesRoomMessage(SyncMessageLikeEvent::Original(m)) = | ||
is_suitable_for_latest_event(&event) | ||
is_suitable_for_latest_event(&event, None) | ||
); | ||
|
||
assert_eq!(m.content.msgtype.msgtype(), "m.image"); | ||
|
@@ -350,7 +388,7 @@ mod tests { | |
)); | ||
assert_let!( | ||
PossibleLatestEvent::YesPoll(SyncMessageLikeEvent::Original(m)) = | ||
is_suitable_for_latest_event(&event) | ||
is_suitable_for_latest_event(&event, None) | ||
); | ||
|
||
assert_eq!(m.content.poll_start().question.text, "do you like rust?"); | ||
|
@@ -374,7 +412,7 @@ mod tests { | |
)); | ||
assert_let!( | ||
PossibleLatestEvent::YesCallInvite(SyncMessageLikeEvent::Original(_)) = | ||
is_suitable_for_latest_event(&event) | ||
is_suitable_for_latest_event(&event, None) | ||
); | ||
} | ||
|
||
|
@@ -396,7 +434,7 @@ mod tests { | |
)); | ||
assert_let!( | ||
PossibleLatestEvent::YesCallNotify(SyncMessageLikeEvent::Original(_)) = | ||
is_suitable_for_latest_event(&event) | ||
is_suitable_for_latest_event(&event, None) | ||
); | ||
} | ||
|
||
|
@@ -417,7 +455,7 @@ mod tests { | |
)); | ||
|
||
assert_matches!( | ||
is_suitable_for_latest_event(&event), | ||
is_suitable_for_latest_event(&event, None), | ||
PossibleLatestEvent::YesSticker(SyncStickerEvent::Original(_)) | ||
); | ||
} | ||
|
@@ -439,7 +477,7 @@ mod tests { | |
)); | ||
|
||
assert_matches!( | ||
is_suitable_for_latest_event(&event), | ||
is_suitable_for_latest_event(&event, None), | ||
PossibleLatestEvent::NoUnsupportedMessageLikeType | ||
); | ||
} | ||
|
@@ -467,7 +505,7 @@ mod tests { | |
)); | ||
|
||
assert_matches!( | ||
is_suitable_for_latest_event(&event), | ||
is_suitable_for_latest_event(&event, None), | ||
PossibleLatestEvent::YesRoomMessage(SyncMessageLikeEvent::Redacted(_)) | ||
); | ||
} | ||
|
@@ -489,7 +527,10 @@ mod tests { | |
}), | ||
)); | ||
|
||
assert_matches!(is_suitable_for_latest_event(&event), PossibleLatestEvent::NoEncrypted); | ||
assert_matches!( | ||
is_suitable_for_latest_event(&event, None), | ||
PossibleLatestEvent::NoEncrypted | ||
); | ||
} | ||
|
||
#[test] | ||
|
@@ -506,7 +547,7 @@ mod tests { | |
)); | ||
|
||
assert_matches!( | ||
is_suitable_for_latest_event(&event), | ||
is_suitable_for_latest_event(&event, None), | ||
PossibleLatestEvent::NoUnsupportedEventType | ||
); | ||
} | ||
|
@@ -530,7 +571,7 @@ mod tests { | |
)); | ||
|
||
assert_matches!( | ||
is_suitable_for_latest_event(&event), | ||
is_suitable_for_latest_event(&event, None), | ||
PossibleLatestEvent::NoUnsupportedMessageLikeType | ||
); | ||
} | ||
|
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.