Skip to content

Commit 798e5da

Browse files
nplasterercameronvoellcodabrink
authoredMar 6, 2025··
Correctly set shouldPush for messages (#1707)
* generate the protos and the database changes * store should push * update places to set the should push * Update schema_gen.rs * Update schema_gen.rs * dont pull in the payer proto changes * undo the toml change * fix test utils * add should push mapping for content types (#1715) * add should push mapping for content types * add comment --------- Co-authored-by: cameronvoell <[email protected]> * fix the borrow * cargo fmt * add should_push * set to false for other content types * update the defaults * should push stored on inten * should push stored on inten (#1717) * add tests for it * fix the linte --------- Co-authored-by: Cameron Voell <[email protected]> Co-authored-by: cameronvoell <[email protected]> Co-authored-by: Dakota Brink <[email protected]> Co-authored-by: Dakota Brink <[email protected]>
1 parent a821d7e commit 798e5da

File tree

15 files changed

+1147
-961
lines changed

15 files changed

+1147
-961
lines changed
 

‎xmtp_api/src/test_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn build_group_messages(num_messages: usize, group_id: Vec<u8>) -> Vec<Group
4343
group_id: group_id.clone(),
4444
data: vec![i as u8],
4545
sender_hmac: vec![],
46+
should_push: Some(true),
4647
})),
4748
})
4849
}

‎xmtp_api_grpc/src/replication_client.rs

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ impl XmtpMlsClient for ClientV4 {
335335
group_id: req.group_id.clone(),
336336
data: v1_group_message.data,
337337
sender_hmac: v1_group_message.sender_hmac,
338+
should_push: v1_group_message.should_push,
338339
})),
339340
})
340341
})

‎xmtp_content_types/src/lib.rs

+60
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,66 @@ pub enum CodecError {
2121
Decode(String),
2222
}
2323

24+
pub enum ContentType {
25+
Text,
26+
GroupMembershipChange,
27+
GroupUpdated,
28+
Reaction,
29+
ReadReceipt,
30+
Reply,
31+
Attachment,
32+
RemoteAttachment,
33+
MultiRemoteAttachment,
34+
TransactionReference,
35+
}
36+
37+
impl TryFrom<&str> for ContentType {
38+
type Error = String;
39+
40+
fn try_from(type_id: &str) -> Result<Self, Self::Error> {
41+
match type_id {
42+
text::TextCodec::TYPE_ID => Ok(Self::Text),
43+
membership_change::GroupMembershipChangeCodec::TYPE_ID => {
44+
Ok(Self::GroupMembershipChange)
45+
}
46+
group_updated::GroupUpdatedCodec::TYPE_ID => Ok(Self::GroupUpdated),
47+
reaction::ReactionCodec::TYPE_ID => Ok(Self::Reaction),
48+
read_receipt::ReadReceiptCodec::TYPE_ID => Ok(Self::ReadReceipt),
49+
reply::ReplyCodec::TYPE_ID => Ok(Self::Reply),
50+
attachment::AttachmentCodec::TYPE_ID => Ok(Self::Attachment),
51+
remote_attachment::RemoteAttachmentCodec::TYPE_ID => Ok(Self::RemoteAttachment),
52+
multi_remote_attachment::MultiRemoteAttachmentCodec::TYPE_ID => {
53+
Ok(Self::MultiRemoteAttachment)
54+
}
55+
transaction_reference::TransactionReferenceCodec::TYPE_ID => {
56+
Ok(Self::TransactionReference)
57+
}
58+
_ => Err(format!("Unknown content type ID: {}", type_id)),
59+
}
60+
}
61+
}
62+
63+
// Represents whether this message type should send pushed notification when received by a user
64+
pub fn should_push(content_type_id: String) -> bool {
65+
let content_type = ContentType::try_from(content_type_id.as_str()).ok();
66+
if let Some(content_type) = content_type {
67+
match content_type {
68+
ContentType::Text => true,
69+
ContentType::GroupMembershipChange => false,
70+
ContentType::GroupUpdated => false,
71+
ContentType::Reaction => false,
72+
ContentType::ReadReceipt => false,
73+
ContentType::Reply => true,
74+
ContentType::Attachment => true,
75+
ContentType::RemoteAttachment => true,
76+
ContentType::MultiRemoteAttachment => true,
77+
ContentType::TransactionReference => true,
78+
}
79+
} else {
80+
false
81+
}
82+
}
83+
2484
pub trait ContentCodec<T> {
2585
fn content_type() -> ContentTypeId;
2686
fn encode(content: T) -> Result<EncodedContent, CodecError>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE group_messages
2+
DROP COLUMN should_push;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE group_intents
2+
ADD COLUMN should_push BOOLEAN NOT NULL DEFAULT TRUE;

‎xmtp_mls/src/groups/device_sync.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,20 @@ where
438438
let content = DeviceSyncContent::Request(request.clone());
439439
let content_bytes = serde_json::to_vec(&content)?;
440440

441-
let _message_id = sync_group.prepare_message(&content_bytes, provider, {
442-
let request = request.clone();
443-
move |now| PlaintextEnvelope {
444-
content: Some(Content::V2(V2 {
445-
message_type: Some(MessageType::DeviceSyncRequest(request)),
446-
idempotency_key: now.to_string(),
447-
})),
448-
}
449-
})?;
441+
let _message_id = sync_group.prepare_message(
442+
&content_bytes,
443+
provider,
444+
{
445+
let request = request.clone();
446+
move |now| PlaintextEnvelope {
447+
content: Some(Content::V2(V2 {
448+
message_type: Some(MessageType::DeviceSyncRequest(request)),
449+
idempotency_key: now.to_string(),
450+
})),
451+
}
452+
},
453+
false,
454+
)?;
450455

451456
// publish the intent
452457
sync_group.publish_intents(provider).await?;
@@ -507,12 +512,17 @@ where
507512
(content_bytes, contents)
508513
};
509514

510-
sync_group.prepare_message(&content_bytes, provider, |now| PlaintextEnvelope {
511-
content: Some(Content::V2(V2 {
512-
message_type: Some(MessageType::DeviceSyncReply(contents)),
513-
idempotency_key: now.to_string(),
514-
})),
515-
})?;
515+
sync_group.prepare_message(
516+
&content_bytes,
517+
provider,
518+
|now| PlaintextEnvelope {
519+
content: Some(Content::V2(V2 {
520+
message_type: Some(MessageType::DeviceSyncReply(contents)),
521+
idempotency_key: now.to_string(),
522+
})),
523+
},
524+
false,
525+
)?;
516526

517527
sync_group.publish_intents(provider).await?;
518528

‎xmtp_mls/src/groups/device_sync/preference_sync.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ impl UserPreferenceUpdate {
3131
.collect::<Result<Vec<_>, _>>()?;
3232
let update_proto = UserPreferenceUpdateProto { contents: updates };
3333
let content_bytes = serde_json::to_vec(&update_proto)?;
34-
sync_group.prepare_message(&content_bytes, &provider, |now| PlaintextEnvelope {
35-
content: Some(Content::V2(V2 {
36-
message_type: Some(MessageType::UserPreferenceUpdate(update_proto)),
37-
idempotency_key: now.to_string(),
38-
})),
39-
})?;
34+
sync_group.prepare_message(
35+
&content_bytes,
36+
&provider,
37+
|now| PlaintextEnvelope {
38+
content: Some(Content::V2(V2 {
39+
message_type: Some(MessageType::UserPreferenceUpdate(update_proto)),
40+
idempotency_key: now.to_string(),
41+
})),
42+
},
43+
false,
44+
)?;
4045

4146
sync_group.publish_intents(&provider).await?;
4247

‎xmtp_mls/src/groups/intents.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
6161
provider: &XmtpOpenMlsProvider,
6262
intent_kind: IntentKind,
6363
intent_data: Vec<u8>,
64+
should_push: bool,
6465
) -> Result<StoredGroupIntent, GroupError> {
6566
let res = provider.transaction(|provider| {
6667
let conn = provider.conn_ref();
67-
self.queue_intent_with_conn(conn, intent_kind, intent_data)
68+
self.queue_intent_with_conn(conn, intent_kind, intent_data, should_push)
6869
});
6970

7071
res
@@ -75,6 +76,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
7576
conn: &DbConnection,
7677
intent_kind: IntentKind,
7778
intent_data: Vec<u8>,
79+
should_push: bool,
7880
) -> Result<StoredGroupIntent, GroupError> {
7981
if intent_kind == IntentKind::SendMessage {
8082
self.maybe_insert_key_update_intent(conn)?;
@@ -84,6 +86,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
8486
intent_kind,
8587
self.group_id.clone(),
8688
intent_data,
89+
should_push,
8790
))?;
8891

8992
if intent_kind != IntentKind::SendMessage {
@@ -99,7 +102,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
99102
let now_ns = xmtp_common::time::now_ns();
100103
let elapsed_ns = now_ns - last_rotated_at_ns;
101104
if elapsed_ns > GROUP_KEY_ROTATION_INTERVAL_NS {
102-
self.queue_intent_with_conn(conn, IntentKind::KeyUpdate, vec![])?;
105+
self.queue_intent_with_conn(conn, IntentKind::KeyUpdate, vec![], false)?;
103106
}
104107
Ok(())
105108
}

‎xmtp_mls/src/groups/mls_sync.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ struct PublishIntentData {
175175
staged_commit: Option<Vec<u8>>,
176176
post_commit_action: Option<Vec<u8>>,
177177
payload_to_publish: Vec<u8>,
178+
should_send_push_notification: bool,
178179
}
179180

180181
impl<ScopedClient> MlsGroup<ScopedClient>
@@ -1234,6 +1235,7 @@ where
12341235
payload_to_publish,
12351236
post_commit_action,
12361237
staged_commit,
1238+
should_send_push_notification
12371239
})) => {
12381240
let payload_slice = payload_to_publish.as_slice();
12391241
let has_staged_commit = staged_commit.is_some();
@@ -1255,7 +1257,7 @@ where
12551257
intent.id
12561258
);
12571259

1258-
let messages = self.prepare_group_messages(vec![payload_slice])?;
1260+
let messages = self.prepare_group_messages(vec![(payload_slice, should_send_push_notification)])?;
12591261
self.client
12601262
.api()
12611263
.send_group_messages(messages)
@@ -1330,6 +1332,7 @@ where
13301332
payload_to_publish: msg.tls_serialize_detached()?,
13311333
post_commit_action: None,
13321334
staged_commit: None,
1335+
should_send_push_notification: intent.should_push,
13331336
}))
13341337
}
13351338
IntentKind::KeyUpdate => {
@@ -1343,6 +1346,7 @@ where
13431346
payload_to_publish: commit.tls_serialize_detached()?,
13441347
staged_commit: get_and_clear_pending_commit(openmls_group, provider)?,
13451348
post_commit_action: None,
1349+
should_send_push_notification: intent.should_push,
13461350
}))
13471351
}
13481352
IntentKind::MetadataUpdate => {
@@ -1365,6 +1369,7 @@ where
13651369
payload_to_publish: commit_bytes,
13661370
staged_commit: get_and_clear_pending_commit(openmls_group, provider)?,
13671371
post_commit_action: None,
1372+
should_send_push_notification: intent.should_push,
13681373
}))
13691374
}
13701375
IntentKind::UpdateAdminList => {
@@ -1386,6 +1391,7 @@ where
13861391
payload_to_publish: commit_bytes,
13871392
staged_commit: get_and_clear_pending_commit(openmls_group, provider)?,
13881393
post_commit_action: None,
1394+
should_send_push_notification: intent.should_push,
13891395
}))
13901396
}
13911397
IntentKind::UpdatePermission => {
@@ -1405,6 +1411,7 @@ where
14051411
payload_to_publish: commit_bytes,
14061412
staged_commit: get_and_clear_pending_commit(openmls_group, provider)?,
14071413
post_commit_action: None,
1414+
should_send_push_notification: intent.should_push,
14081415
}))
14091416
}
14101417
}
@@ -1496,6 +1503,7 @@ where
14961503
provider,
14971504
IntentKind::UpdateGroupMembership,
14981505
intent_data.into(),
1506+
false,
14991507
)?;
15001508

15011509
self.sync_until_intent_resolved(provider, intent.id).await
@@ -1689,7 +1697,7 @@ where
16891697
#[tracing::instrument(level = "trace", skip_all)]
16901698
pub(super) fn prepare_group_messages(
16911699
&self,
1692-
payloads: Vec<&[u8]>,
1700+
payloads: Vec<(&[u8], bool)>,
16931701
) -> Result<Vec<GroupMessageInput>, GroupError> {
16941702
let hmac_key = self
16951703
.hmac_keys(0..=0)?
@@ -1699,7 +1707,7 @@ where
16991707
Hmac::<Sha256>::new_from_slice(&hmac_key.key).expect("HMAC can take key of any size");
17001708

17011709
let mut result = vec![];
1702-
for payload in payloads {
1710+
for (payload, should_push) in payloads {
17031711
let mut sender_hmac = sender_hmac.clone();
17041712
sender_hmac.update(payload);
17051713
let sender_hmac = sender_hmac.finalize();
@@ -1708,6 +1716,7 @@ where
17081716
version: Some(GroupMessageInputVersion::V1(GroupMessageInputV1 {
17091717
data: payload.to_vec(),
17101718
sender_hmac: sender_hmac.into_bytes().to_vec(),
1719+
should_push: Some(should_push),
17111720
})),
17121721
});
17131722
}
@@ -1907,6 +1916,7 @@ async fn apply_update_group_membership_intent(
19071916
payload_to_publish: commit.tls_serialize_detached()?,
19081917
post_commit_action: post_commit_action.map(|action| action.to_bytes()),
19091918
staged_commit: Some(staged_commit),
1919+
should_send_push_notification: false,
19101920
}))
19111921
}
19121922

‎xmtp_mls/src/groups/mod.rs

+39-18
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ use tokio::sync::Mutex;
9797
use xmtp_common::retry::RetryableError;
9898
use xmtp_common::time::now_ns;
9999
use xmtp_content_types::reaction::{LegacyReaction, ReactionCodec};
100+
use xmtp_content_types::should_push;
100101
use xmtp_cryptography::signature::{sanitize_evm_addresses, AddressValidationError};
101102
use xmtp_id::{InboxId, InboxIdRef};
102103
use xmtp_proto::xmtp::mls::{
@@ -337,6 +338,7 @@ pub struct QueryableContentFields {
337338
pub version_minor: i32,
338339
pub authority_id: String,
339340
pub reference_id: Option<Vec<u8>>,
341+
pub should_push: bool,
340342
}
341343

342344
impl Default for QueryableContentFields {
@@ -347,6 +349,7 @@ impl Default for QueryableContentFields {
347349
version_minor: 0,
348350
authority_id: String::new(),
349351
reference_id: None,
352+
should_push: false,
350353
}
351354
}
352355
}
@@ -356,10 +359,10 @@ impl TryFrom<EncodedContent> for QueryableContentFields {
356359

357360
fn try_from(content: EncodedContent) -> Result<Self, Self::Error> {
358361
let content_type_id = content.r#type.unwrap_or_default();
359-
let reference_id = match (
360-
content_type_id.type_id.as_str(),
361-
content_type_id.version_major,
362-
) {
362+
363+
let type_id_str = content_type_id.type_id.clone();
364+
365+
let reference_id = match (type_id_str.as_str(), content_type_id.version_major) {
363366
(ReactionCodec::TYPE_ID, major) if major >= 2 => {
364367
ReactionV2::decode(content.content.as_slice())
365368
.ok()
@@ -376,6 +379,7 @@ impl TryFrom<EncodedContent> for QueryableContentFields {
376379
version_minor: content_type_id.version_minor as i32,
377380
authority_id: content_type_id.authority_id.to_string(),
378381
reference_id,
382+
should_push: should_push(type_id_str),
379383
})
380384
}
381385
}
@@ -791,8 +795,12 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
791795
self.maybe_update_installations(provider, update_interval_ns)
792796
.await?;
793797

794-
let message_id =
795-
self.prepare_message(message, provider, |now| Self::into_envelope(message, now))?;
798+
let message_id = self.prepare_message(
799+
message,
800+
provider,
801+
|now| Self::into_envelope(message, now),
802+
true,
803+
)?;
796804

797805
self.sync_until_last_intent_resolved(provider).await?;
798806
// implicitly set group consent state to allowed
@@ -830,8 +838,12 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
830838
/// Send a message, optimistically returning the ID of the message before the result of a message publish.
831839
pub fn send_message_optimistic(&self, message: &[u8]) -> Result<Vec<u8>, GroupError> {
832840
let provider = self.mls_provider()?;
833-
let message_id =
834-
self.prepare_message(message, &provider, |now| Self::into_envelope(message, now))?;
841+
let message_id = self.prepare_message(
842+
message,
843+
&provider,
844+
|now| Self::into_envelope(message, now),
845+
true,
846+
)?;
835847
Ok(message_id)
836848
}
837849

@@ -865,6 +877,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
865877
message: &[u8],
866878
provider: &XmtpOpenMlsProvider,
867879
envelope: F,
880+
should_push: bool,
868881
) -> Result<Vec<u8>, GroupError>
869882
where
870883
F: FnOnce(i64) -> PlaintextEnvelope,
@@ -877,7 +890,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
877890
.map_err(GroupError::EncodeError)?;
878891

879892
let intent_data: Vec<u8> = SendMessageIntentData::new(encoded_envelope).into();
880-
self.queue_intent(provider, IntentKind::SendMessage, intent_data)?;
893+
self.queue_intent(provider, IntentKind::SendMessage, intent_data, should_push)?;
881894

882895
// store this unpublished message locally before sending
883896
let message_id = calculate_message_id(&self.group_id, message, &now.to_string());
@@ -1013,6 +1026,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
10131026
provider,
10141027
IntentKind::UpdateGroupMembership,
10151028
intent_data.into(),
1029+
false,
10161030
)?;
10171031

10181032
self.sync_until_intent_resolved(provider, intent.id).await?;
@@ -1063,6 +1077,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
10631077
&provider,
10641078
IntentKind::UpdateGroupMembership,
10651079
intent_data.into(),
1080+
false,
10661081
)?;
10671082

10681083
self.sync_until_intent_resolved(&provider, intent.id).await
@@ -1082,7 +1097,8 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
10821097
}
10831098
let intent_data: Vec<u8> =
10841099
UpdateMetadataIntentData::new_update_group_name(group_name).into();
1085-
let intent = self.queue_intent(&provider, IntentKind::MetadataUpdate, intent_data)?;
1100+
let intent =
1101+
self.queue_intent(&provider, IntentKind::MetadataUpdate, intent_data, false)?;
10861102

10871103
self.sync_until_intent_resolved(&provider, intent.id).await
10881104
}
@@ -1111,7 +1127,8 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
11111127
)
11121128
.into();
11131129

1114-
let intent = self.queue_intent(&provider, IntentKind::UpdatePermission, intent_data)?;
1130+
let intent =
1131+
self.queue_intent(&provider, IntentKind::UpdatePermission, intent_data, false)?;
11151132

11161133
self.sync_until_intent_resolved(&provider, intent.id).await
11171134
}
@@ -1147,7 +1164,8 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
11471164
}
11481165
let intent_data: Vec<u8> =
11491166
UpdateMetadataIntentData::new_update_group_description(group_description).into();
1150-
let intent = self.queue_intent(&provider, IntentKind::MetadataUpdate, intent_data)?;
1167+
let intent =
1168+
self.queue_intent(&provider, IntentKind::MetadataUpdate, intent_data, false)?;
11511169

11521170
self.sync_until_intent_resolved(&provider, intent.id).await
11531171
}
@@ -1183,7 +1201,8 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
11831201
let intent_data: Vec<u8> =
11841202
UpdateMetadataIntentData::new_update_group_image_url_square(group_image_url_square)
11851203
.into();
1186-
let intent = self.queue_intent(&provider, IntentKind::MetadataUpdate, intent_data)?;
1204+
let intent =
1205+
self.queue_intent(&provider, IntentKind::MetadataUpdate, intent_data, false)?;
11871206

11881207
self.sync_until_intent_resolved(&provider, intent.id).await
11891208
}
@@ -1236,7 +1255,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
12361255
expire_from_ms,
12371256
)
12381257
.into();
1239-
let intent = self.queue_intent(provider, IntentKind::MetadataUpdate, intent_data)?;
1258+
let intent = self.queue_intent(provider, IntentKind::MetadataUpdate, intent_data, false)?;
12401259
self.sync_until_intent_resolved(provider, intent.id).await
12411260
}
12421261

@@ -1248,7 +1267,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
12481267
let intent_data: Vec<u8> =
12491268
UpdateMetadataIntentData::new_update_conversation_message_disappear_in_ns(expire_in_ms)
12501269
.into();
1251-
let intent = self.queue_intent(provider, IntentKind::MetadataUpdate, intent_data)?;
1270+
let intent = self.queue_intent(provider, IntentKind::MetadataUpdate, intent_data, false)?;
12521271
self.sync_until_intent_resolved(provider, intent.id).await
12531272
}
12541273

@@ -1348,7 +1367,8 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
13481367
};
13491368
let intent_data: Vec<u8> =
13501369
UpdateAdminListIntentData::new(intent_action_type, inbox_id).into();
1351-
let intent = self.queue_intent(&provider, IntentKind::UpdateAdminList, intent_data)?;
1370+
let intent =
1371+
self.queue_intent(&provider, IntentKind::UpdateAdminList, intent_data, false)?;
13521372

13531373
self.sync_until_intent_resolved(&provider, intent.id).await
13541374
}
@@ -1425,7 +1445,7 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
14251445
/// Update this installation's leaf key in the group by creating a key update commit
14261446
pub async fn key_update(&self) -> Result<(), GroupError> {
14271447
let provider = self.client.mls_provider()?;
1428-
let intent = self.queue_intent(&provider, IntentKind::KeyUpdate, vec![])?;
1448+
let intent = self.queue_intent(&provider, IntentKind::KeyUpdate, vec![], false)?;
14291449
self.sync_until_intent_resolved(&provider, intent.id).await
14301450
}
14311451

@@ -2034,7 +2054,7 @@ pub(crate) mod tests {
20342054
serialized_welcome,
20352055
);
20362056
let messages = sender_group
2037-
.prepare_group_messages(vec![serialized_commit.as_slice()])
2057+
.prepare_group_messages(vec![(serialized_commit.as_slice(), false)])
20382058
.unwrap();
20392059
sender_client
20402060
.api_client
@@ -4405,6 +4425,7 @@ pub(crate) mod tests {
44054425
provider,
44064426
IntentKind::UpdateGroupMembership,
44074427
intent_data.into(),
4428+
false,
44084429
)
44094430
.unwrap();
44104431
}

‎xmtp_mls/src/storage/encrypted_store/group_intent.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub struct StoredGroupIntent {
7878
pub publish_attempts: i32,
7979
pub staged_commit: Option<Vec<u8>>,
8080
pub published_in_epoch: Option<i64>,
81+
pub should_push: bool,
8182
}
8283

8384
impl std::fmt::Debug for StoredGroupIntent {
@@ -176,17 +177,19 @@ pub struct NewGroupIntent {
176177
pub group_id: Vec<u8>,
177178
pub data: Vec<u8>,
178179
pub state: IntentState,
180+
pub should_push: bool,
179181
}
180182

181183
impl_store!(NewGroupIntent, group_intents);
182184

183185
impl NewGroupIntent {
184-
pub fn new(kind: IntentKind, group_id: Vec<u8>, data: Vec<u8>) -> Self {
186+
pub fn new(kind: IntentKind, group_id: Vec<u8>, data: Vec<u8>, should_push: bool) -> Self {
185187
Self {
186188
kind,
187189
group_id,
188190
data,
189191
state: IntentState::ToPublish,
192+
should_push,
190193
}
191194
}
192195
}
@@ -469,6 +472,7 @@ pub(crate) mod tests {
469472
group_id,
470473
data,
471474
state,
475+
should_push: false,
472476
}
473477
}
474478
}
@@ -609,6 +613,7 @@ pub(crate) mod tests {
609613
IntentKind::UpdateGroupMembership,
610614
group_id.clone(),
611615
rand_vec::<24>(),
616+
false,
612617
)
613618
.store(conn)
614619
.unwrap();
@@ -652,6 +657,7 @@ pub(crate) mod tests {
652657
IntentKind::UpdateGroupMembership,
653658
group_id.clone(),
654659
rand_vec::<24>(),
660+
false,
655661
)
656662
.store(conn)
657663
.unwrap();
@@ -698,6 +704,7 @@ pub(crate) mod tests {
698704
IntentKind::UpdateGroupMembership,
699705
group_id.clone(),
700706
rand_vec::<24>(),
707+
false,
701708
)
702709
.store(conn)
703710
.unwrap();
@@ -743,6 +750,7 @@ pub(crate) mod tests {
743750
IntentKind::UpdateGroupMembership,
744751
group_id.clone(),
745752
rand_vec::<24>(),
753+
false,
746754
)
747755
.store(conn)
748756
.unwrap();
@@ -776,6 +784,7 @@ pub(crate) mod tests {
776784
IntentKind::UpdateGroupMembership,
777785
group_id.clone(),
778786
rand_vec::<24>(),
787+
false,
779788
)
780789
.store(conn)
781790
.unwrap();

‎xmtp_mls/src/storage/encrypted_store/group_message.rs

+4
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ pub(crate) mod tests {
488488
};
489489
use wasm_bindgen_test::wasm_bindgen_test;
490490
use xmtp_common::{assert_err, assert_ok, rand_time, rand_vec};
491+
use xmtp_content_types::should_push;
491492

492493
pub(crate) fn generate_message(
493494
kind: Option<GroupMessageKind>,
@@ -818,6 +819,8 @@ pub(crate) mod tests {
818819
.unwrap();
819820
assert_eq!(text_messages.len(), 1);
820821
assert_eq!(text_messages[0].content_type, ContentType::Text);
822+
assert!(should_push(text_messages[0].content_type.to_string()));
823+
821824
assert_eq!(text_messages[0].sent_at_ns, 1_000);
822825

823826
// Query for membership change messages
@@ -849,6 +852,7 @@ pub(crate) mod tests {
849852
.unwrap();
850853
assert_eq!(updated_messages.len(), 1);
851854
assert_eq!(updated_messages[0].content_type, ContentType::GroupUpdated);
855+
assert!(!should_push(updated_messages[0].content_type.to_string()));
852856
assert_eq!(updated_messages[0].sent_at_ns, 3_000);
853857
})
854858
.await

‎xmtp_mls/src/storage/encrypted_store/schema_gen.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @generated automatically by Diesel CLI.
22

3-
use crate::storage::schema::conversation_list;
3+
use super::schema::conversation_list;
44

55
diesel::table! {
66
association_state (inbox_id, sequence_id) {
@@ -30,6 +30,7 @@ diesel::table! {
3030
publish_attempts -> Integer,
3131
staged_commit -> Nullable<Binary>,
3232
published_in_epoch -> Nullable<BigInt>,
33+
should_push -> Bool,
3334
}
3435
}
3536

‎xmtp_proto/src/gen/xmtp.mls.api.v1.rs

+936-915
Large diffs are not rendered by default.

‎xmtp_proto/src/gen/xmtp.mls.api.v1.serde.rs

+36
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,9 @@ impl serde::Serialize for group_message::V1 {
10441044
if !self.sender_hmac.is_empty() {
10451045
len += 1;
10461046
}
1047+
if self.should_push.is_some() {
1048+
len += 1;
1049+
}
10471050
let mut struct_ser = serializer.serialize_struct("xmtp.mls.api.v1.GroupMessage.V1", len)?;
10481051
if self.id != 0 {
10491052
#[allow(clippy::needless_borrow)]
@@ -1070,6 +1073,9 @@ impl serde::Serialize for group_message::V1 {
10701073
#[allow(clippy::needless_borrows_for_generic_args)]
10711074
struct_ser.serialize_field("senderHmac", pbjson::private::base64::encode(&self.sender_hmac).as_str())?;
10721075
}
1076+
if let Some(v) = self.should_push.as_ref() {
1077+
struct_ser.serialize_field("shouldPush", v)?;
1078+
}
10731079
struct_ser.end()
10741080
}
10751081
}
@@ -1088,6 +1094,8 @@ impl<'de> serde::Deserialize<'de> for group_message::V1 {
10881094
"data",
10891095
"sender_hmac",
10901096
"senderHmac",
1097+
"should_push",
1098+
"shouldPush",
10911099
];
10921100

10931101
#[allow(clippy::enum_variant_names)]
@@ -1097,6 +1105,7 @@ impl<'de> serde::Deserialize<'de> for group_message::V1 {
10971105
GroupId,
10981106
Data,
10991107
SenderHmac,
1108+
ShouldPush,
11001109
}
11011110
impl<'de> serde::Deserialize<'de> for GeneratedField {
11021111
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
@@ -1123,6 +1132,7 @@ impl<'de> serde::Deserialize<'de> for group_message::V1 {
11231132
"groupId" | "group_id" => Ok(GeneratedField::GroupId),
11241133
"data" => Ok(GeneratedField::Data),
11251134
"senderHmac" | "sender_hmac" => Ok(GeneratedField::SenderHmac),
1135+
"shouldPush" | "should_push" => Ok(GeneratedField::ShouldPush),
11261136
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
11271137
}
11281138
}
@@ -1147,6 +1157,7 @@ impl<'de> serde::Deserialize<'de> for group_message::V1 {
11471157
let mut group_id__ = None;
11481158
let mut data__ = None;
11491159
let mut sender_hmac__ = None;
1160+
let mut should_push__ = None;
11501161
while let Some(k) = map_.next_key()? {
11511162
match k {
11521163
GeneratedField::Id => {
@@ -1189,6 +1200,12 @@ impl<'de> serde::Deserialize<'de> for group_message::V1 {
11891200
Some(map_.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0)
11901201
;
11911202
}
1203+
GeneratedField::ShouldPush => {
1204+
if should_push__.is_some() {
1205+
return Err(serde::de::Error::duplicate_field("shouldPush"));
1206+
}
1207+
should_push__ = map_.next_value()?;
1208+
}
11921209
}
11931210
}
11941211
Ok(group_message::V1 {
@@ -1197,6 +1214,7 @@ impl<'de> serde::Deserialize<'de> for group_message::V1 {
11971214
group_id: group_id__.unwrap_or_default(),
11981215
data: data__.unwrap_or_default(),
11991216
sender_hmac: sender_hmac__.unwrap_or_default(),
1217+
should_push: should_push__,
12001218
})
12011219
}
12021220
}
@@ -1313,6 +1331,9 @@ impl serde::Serialize for group_message_input::V1 {
13131331
if !self.sender_hmac.is_empty() {
13141332
len += 1;
13151333
}
1334+
if self.should_push.is_some() {
1335+
len += 1;
1336+
}
13161337
let mut struct_ser = serializer.serialize_struct("xmtp.mls.api.v1.GroupMessageInput.V1", len)?;
13171338
if !self.data.is_empty() {
13181339
#[allow(clippy::needless_borrow)]
@@ -1324,6 +1345,9 @@ impl serde::Serialize for group_message_input::V1 {
13241345
#[allow(clippy::needless_borrows_for_generic_args)]
13251346
struct_ser.serialize_field("senderHmac", pbjson::private::base64::encode(&self.sender_hmac).as_str())?;
13261347
}
1348+
if let Some(v) = self.should_push.as_ref() {
1349+
struct_ser.serialize_field("shouldPush", v)?;
1350+
}
13271351
struct_ser.end()
13281352
}
13291353
}
@@ -1337,12 +1361,15 @@ impl<'de> serde::Deserialize<'de> for group_message_input::V1 {
13371361
"data",
13381362
"sender_hmac",
13391363
"senderHmac",
1364+
"should_push",
1365+
"shouldPush",
13401366
];
13411367

13421368
#[allow(clippy::enum_variant_names)]
13431369
enum GeneratedField {
13441370
Data,
13451371
SenderHmac,
1372+
ShouldPush,
13461373
}
13471374
impl<'de> serde::Deserialize<'de> for GeneratedField {
13481375
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
@@ -1366,6 +1393,7 @@ impl<'de> serde::Deserialize<'de> for group_message_input::V1 {
13661393
match value {
13671394
"data" => Ok(GeneratedField::Data),
13681395
"senderHmac" | "sender_hmac" => Ok(GeneratedField::SenderHmac),
1396+
"shouldPush" | "should_push" => Ok(GeneratedField::ShouldPush),
13691397
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
13701398
}
13711399
}
@@ -1387,6 +1415,7 @@ impl<'de> serde::Deserialize<'de> for group_message_input::V1 {
13871415
{
13881416
let mut data__ = None;
13891417
let mut sender_hmac__ = None;
1418+
let mut should_push__ = None;
13901419
while let Some(k) = map_.next_key()? {
13911420
match k {
13921421
GeneratedField::Data => {
@@ -1405,11 +1434,18 @@ impl<'de> serde::Deserialize<'de> for group_message_input::V1 {
14051434
Some(map_.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0)
14061435
;
14071436
}
1437+
GeneratedField::ShouldPush => {
1438+
if should_push__.is_some() {
1439+
return Err(serde::de::Error::duplicate_field("shouldPush"));
1440+
}
1441+
should_push__ = map_.next_value()?;
1442+
}
14081443
}
14091444
}
14101445
Ok(group_message_input::V1 {
14111446
data: data__.unwrap_or_default(),
14121447
sender_hmac: sender_hmac__.unwrap_or_default(),
1448+
should_push: should_push__,
14131449
})
14141450
}
14151451
}

0 commit comments

Comments
 (0)
Please sign in to comment.