Skip to content

Commit 81a69f8

Browse files
committed
feat(sdk): Accept invite for latest event if it targets the current user.
1 parent f4a6d12 commit 81a69f8

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

crates/matrix-sdk/src/latest_events/latest_event.rs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{iter::once, ops::Not};
15+
use std::{
16+
iter::once,
17+
ops::{Deref, Not},
18+
};
1619

1720
use eyeball::{AsyncLock, SharedObservable, Subscriber};
1821
pub use matrix_sdk_base::latest_event::{
@@ -1015,8 +1018,16 @@ fn filter_any_sync_state_event(
10151018
}
10161019

10171020
MembershipState::Invite => {
1018-
// We can only decide whether the user is invited if the event isn't redacted.
1019-
matches!(member, SyncStateEvent::Original(_))
1021+
// The current _is_ invited (not someone else).
1022+
match member {
1023+
// We can only decide whether the user is invited if the event isn't
1024+
// redacted.
1025+
SyncStateEvent::Original(state) => {
1026+
Some(state.state_key.deref()) == own_user_id
1027+
}
1028+
1029+
_ => false,
1030+
}
10201031
}
10211032

10221033
_ => false,
@@ -1279,38 +1290,55 @@ mod tests_latest_event_content {
12791290
}
12801291

12811292
#[test]
1282-
fn test_room_message_verification_request() {
1283-
use ruma::{OwnedDeviceId, events::room::message};
1293+
fn test_invite_state_event() {
1294+
use ruma::events::room::member::MembershipState;
12841295

1296+
// The current user is receiving an invite.
12851297
assert_latest_event_content!(
12861298
event | event_factory | {
12871299
event_factory
1288-
.event(RoomMessageEventContent::new(message::MessageType::VerificationRequest(
1289-
message::KeyVerificationRequestEventContent::new(
1290-
"body".to_owned(),
1291-
vec![],
1292-
OwnedDeviceId::from("device_id"),
1293-
user_id!("@user:server.name").to_owned(),
1294-
),
1295-
)))
1300+
.member(user_id!("@mnt_io:matrix.org"))
1301+
.membership(MembershipState::Invite)
12961302
.into_event()
12971303
}
1298-
is not a candidate
1304+
is a candidate
12991305
);
13001306
}
13011307

13021308
#[test]
1303-
fn test_invite() {
1309+
fn test_invite_state_event_for_someone_else() {
13041310
use ruma::events::room::member::MembershipState;
13051311

1312+
// The current user sees an invite but for someone else.
13061313
assert_latest_event_content!(
13071314
event | event_factory | {
13081315
event_factory
1309-
.member(user_id!("@mnt_io:matrix.org"))
1316+
.member(user_id!("@other_mnt_io:server.name"))
13101317
.membership(MembershipState::Invite)
13111318
.into_event()
13121319
}
1313-
is a candidate
1320+
is not a candidate
1321+
);
1322+
}
1323+
1324+
#[test]
1325+
fn test_room_message_verification_request() {
1326+
use ruma::{OwnedDeviceId, events::room::message};
1327+
1328+
assert_latest_event_content!(
1329+
event | event_factory | {
1330+
event_factory
1331+
.event(RoomMessageEventContent::new(message::MessageType::VerificationRequest(
1332+
message::KeyVerificationRequestEventContent::new(
1333+
"body".to_owned(),
1334+
vec![],
1335+
OwnedDeviceId::from("device_id"),
1336+
user_id!("@user:server.name").to_owned(),
1337+
),
1338+
)))
1339+
.into_event()
1340+
}
1341+
is not a candidate
13141342
);
13151343
}
13161344
}

0 commit comments

Comments
 (0)