Skip to content

Commit a1d1a90

Browse files
committed
Merge remote-tracking branch 'origin/main' into jme/update-pinned-events
2 parents b8b2cf0 + bbefad3 commit a1d1a90

File tree

48 files changed

+2137
-1026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2137
-1026
lines changed

Cargo.lock

+89-155
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/matrix-sdk-crypto-ffi/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,9 @@ pub struct EncryptionSettings {
668668
/// Should untrusted devices receive the room key, or should they be
669669
/// excluded from the conversation.
670670
pub only_allow_trusted_devices: bool,
671+
/// Should fail to send when a verified user has unverified devices, or when
672+
/// a previously verified user replaces their identity.
673+
pub error_on_verified_user_problem: bool,
671674
}
672675

673676
impl From<EncryptionSettings> for RustEncryptionSettings {
@@ -677,7 +680,10 @@ impl From<EncryptionSettings> for RustEncryptionSettings {
677680
rotation_period: Duration::from_secs(v.rotation_period),
678681
rotation_period_msgs: v.rotation_period_msgs,
679682
history_visibility: v.history_visibility.into(),
680-
sharing_strategy: CollectStrategy::new_device_based(v.only_allow_trusted_devices),
683+
sharing_strategy: CollectStrategy::DeviceBasedStrategy {
684+
only_allow_trusted_devices: v.only_allow_trusted_devices,
685+
error_on_verified_user_problem: v.error_on_verified_user_problem,
686+
},
681687
}
682688
}
683689
}

bindings/matrix-sdk-crypto-ffi/src/machine.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ impl OlmMachine {
285285
if let Some(identity) =
286286
self.runtime.block_on(self.inner.get_identity(&user_id, None))?
287287
{
288-
match identity {
289-
UserIdentities::Own(i) => i.is_verified(),
290-
UserIdentities::Other(i) => i.is_verified(),
291-
}
288+
identity.is_verified()
292289
} else {
293290
false
294291
},

bindings/matrix-sdk-ffi/src/platform.rs

+49-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
use tracing_appender::rolling::{RollingFileAppender, Rotation};
22
use tracing_core::Subscriber;
33
use tracing_subscriber::{
4-
fmt::{self, time::FormatTime, FormatEvent, FormatFields, FormattedFields},
4+
field::RecordFields,
5+
fmt::{
6+
self,
7+
format::{DefaultFields, Writer},
8+
time::FormatTime,
9+
FormatEvent, FormatFields, FormattedFields,
10+
},
511
layer::SubscriberExt,
612
registry::LookupSpan,
713
util::SubscriberInitExt,
@@ -97,17 +103,19 @@ where
97103

98104
if let Some(scope) = ctx.event_scope() {
99105
writer.write_str(" | spans: ")?;
106+
100107
let mut first = true;
101108

102109
for span in scope.from_root() {
103110
if !first {
104111
writer.write_str(" > ")?;
105112
}
113+
106114
first = false;
107-
write!(writer, "{}", span.metadata().name())?;
108115

109-
let ext = span.extensions();
110-
if let Some(fields) = &ext.get::<FormattedFields<N>>() {
116+
write!(writer, "{}", span.name())?;
117+
118+
if let Some(fields) = &span.extensions().get::<FormattedFields<N>>() {
111119
if !fields.is_empty() {
112120
write!(writer, "{{{fields}}}")?;
113121
}
@@ -133,7 +141,25 @@ where
133141

134142
let writer = builder.build(&c.path).expect("Failed to create a rolling file appender.");
135143

144+
// Another fields formatter is necessary because of this bug
145+
// https://github.com/tokio-rs/tracing/issues/1372. Using a new
146+
// formatter for the fields forces to record them in different span
147+
// extensions, and thus remove the duplicated fields in the span.
148+
#[derive(Default)]
149+
struct FieldsFormatterForFiles(DefaultFields);
150+
151+
impl<'writer> FormatFields<'writer> for FieldsFormatterForFiles {
152+
fn format_fields<R: RecordFields>(
153+
&self,
154+
writer: Writer<'writer>,
155+
fields: R,
156+
) -> std::fmt::Result {
157+
self.0.format_fields(writer, fields)
158+
}
159+
}
160+
136161
fmt::layer()
162+
.fmt_fields(FieldsFormatterForFiles::default())
137163
.event_format(EventFormatter::new())
138164
// EventFormatter doesn't support ANSI colors anyways, but the
139165
// default field formatter does, which is unhelpful for iOS +
@@ -145,15 +171,34 @@ where
145171
Layer::and_then(
146172
file_layer,
147173
config.write_to_stdout_or_system.then(|| {
174+
// Another fields formatter is necessary because of this bug
175+
// https://github.com/tokio-rs/tracing/issues/1372. Using a new
176+
// formatter for the fields forces to record them in different span
177+
// extensions, and thus remove the duplicated fields in the span.
178+
#[derive(Default)]
179+
struct FieldsFormatterFormStdoutOrSystem(DefaultFields);
180+
181+
impl<'writer> FormatFields<'writer> for FieldsFormatterFormStdoutOrSystem {
182+
fn format_fields<R: RecordFields>(
183+
&self,
184+
writer: Writer<'writer>,
185+
fields: R,
186+
) -> std::fmt::Result {
187+
self.0.format_fields(writer, fields)
188+
}
189+
}
190+
148191
#[cfg(not(target_os = "android"))]
149192
return fmt::layer()
193+
.fmt_fields(FieldsFormatterFormStdoutOrSystem::default())
150194
.event_format(EventFormatter::new())
151195
// See comment above.
152196
.with_ansi(false)
153197
.with_writer(std::io::stderr);
154198

155199
#[cfg(target_os = "android")]
156200
return fmt::layer()
201+
.fmt_fields(FieldsFormatterFormStdoutOrSystem::default())
157202
.event_format(EventFormatter::for_logcat())
158203
// See comment above.
159204
.with_ansi(false)

bindings/matrix-sdk-ffi/src/room_info.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct RoomInfo {
3939
user_power_levels: HashMap<String, i64>,
4040
highlight_count: u64,
4141
notification_count: u64,
42-
user_defined_notification_mode: Option<RoomNotificationMode>,
42+
cached_user_defined_notification_mode: Option<RoomNotificationMode>,
4343
has_room_call: bool,
4444
active_room_call_participants: Vec<String>,
4545
/// Whether this room has been explicitly marked as unread
@@ -98,9 +98,8 @@ impl RoomInfo {
9898
user_power_levels,
9999
highlight_count: unread_notification_counts.highlight_count,
100100
notification_count: unread_notification_counts.notification_count,
101-
user_defined_notification_mode: room
102-
.user_defined_notification_mode()
103-
.await
101+
cached_user_defined_notification_mode: room
102+
.cached_user_defined_notification_mode()
104103
.map(Into::into),
105104
has_room_call: room.has_active_room_call(),
106105
active_room_call_participants: room

crates/matrix-sdk-base/src/client.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use futures_util::Stream;
2828
use matrix_sdk_common::instant::Instant;
2929
#[cfg(feature = "e2e-encryption")]
3030
use matrix_sdk_crypto::{
31-
store::DynCryptoStore, EncryptionSettings, EncryptionSyncChanges, OlmError, OlmMachine,
32-
ToDeviceRequest,
31+
store::DynCryptoStore, CollectStrategy, EncryptionSettings, EncryptionSyncChanges, OlmError,
32+
OlmMachine, ToDeviceRequest,
3333
};
3434
#[cfg(feature = "e2e-encryption")]
3535
use ruma::events::{
@@ -840,7 +840,7 @@ impl BaseClient {
840840
let mut changes = StateChanges::default();
841841
changes.add_room(room_info.clone());
842842
self.store.save_changes(&changes).await?; // Update the store
843-
room.set_room_info(room_info, RoomInfoNotableUpdateReasons::empty());
843+
room.set_room_info(room_info, RoomInfoNotableUpdateReasons::MEMBERSHIP);
844844
}
845845

846846
Ok(room)
@@ -866,7 +866,7 @@ impl BaseClient {
866866
let mut changes = StateChanges::default();
867867
changes.add_room(room_info.clone());
868868
self.store.save_changes(&changes).await?; // Update the store
869-
room.set_room_info(room_info, RoomInfoNotableUpdateReasons::empty());
869+
room.set_room_info(room_info, RoomInfoNotableUpdateReasons::MEMBERSHIP);
870870
}
871871

872872
Ok(())
@@ -1391,7 +1391,14 @@ impl BaseClient {
13911391
let members = self.store.get_user_ids(room_id, filter).await?;
13921392

13931393
let settings = settings.ok_or(Error::EncryptionNotEnabled)?;
1394-
let settings = EncryptionSettings::new(settings, history_visibility, false);
1394+
let settings = EncryptionSettings::new(
1395+
settings,
1396+
history_visibility,
1397+
CollectStrategy::DeviceBasedStrategy {
1398+
only_allow_trusted_devices: false,
1399+
error_on_verified_user_problem: false,
1400+
},
1401+
);
13951402

13961403
Ok(o.share_room_key(room_id, members.iter().map(Deref::deref), settings).await?)
13971404
}

crates/matrix-sdk-base/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub mod deserialized_responses;
2929
mod error;
3030
pub mod latest_event;
3131
pub mod media;
32+
pub mod notification_settings;
3233
mod rooms;
3334

3435
pub mod read_receipts;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2024 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for that specific language governing permissions and
13+
// limitations under the License.
14+
15+
//! Some shared types about notification settings.
16+
17+
use serde::{Deserialize, Serialize};
18+
19+
/// Enum representing the push notification modes for a room.
20+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
21+
pub enum RoomNotificationMode {
22+
/// Receive notifications for all messages.
23+
AllMessages,
24+
/// Receive notifications for mentions and keywords only.
25+
MentionsAndKeywordsOnly,
26+
/// Do not receive any notifications.
27+
Mute,
28+
}

0 commit comments

Comments
 (0)