diff --git a/xmtp_mls/migrations/2024-12-18-170645_add_dm_id/up.sql b/xmtp_mls/migrations/2024-12-18-170645_add_dm_id/up.sql index 4e7fed04c..88de8b3cc 100644 --- a/xmtp_mls/migrations/2024-12-18-170645_add_dm_id/up.sql +++ b/xmtp_mls/migrations/2024-12-18-170645_add_dm_id/up.sql @@ -1,5 +1,5 @@ ALTER TABLE groups ADD COLUMN dm_id TEXT; -ALTER TABLE groups ADD COLUMN last_message_ns BIGINT; +ALTER TABLE groups ADD COLUMN last_message_ns BIGINT NOT NULL DEFAULT (created_at_ns); -- Fill the dm_id column UPDATE groups diff --git a/xmtp_mls/src/storage/encrypted_store/group.rs b/xmtp_mls/src/storage/encrypted_store/group.rs index 0fb80096c..fabb67b9b 100644 --- a/xmtp_mls/src/storage/encrypted_store/group.rs +++ b/xmtp_mls/src/storage/encrypted_store/group.rs @@ -16,6 +16,7 @@ use diesel::{ sql_types::Integer, }; use serde::{Deserialize, Serialize}; +use xmtp_common::time::now_ns; pub type ID = Vec; @@ -36,14 +37,14 @@ pub struct StoredGroup { pub added_by_inbox_id: String, /// The sequence id of the welcome message pub welcome_id: Option, - /// The inbox_id of the DM target - pub dm_id: Option, - /// Timestamp of when the last message was sent for this group (updated automatically in a trigger) - pub last_message_ns: Option, /// The last time the leaf node encryption key was rotated pub rotated_at_ns: i64, /// Enum, [`ConversationType`] signifies the group conversation type which extends to who can access it. pub conversation_type: ConversationType, + /// The inbox_id of the DM target + pub dm_id: Option, + /// Timestamp of when the last message was sent for this group (updated automatically in a trigger) + pub last_message_ns: i64, } impl_fetch!(StoredGroup, groups, Vec); @@ -70,7 +71,7 @@ impl StoredGroup { welcome_id: Some(welcome_id), rotated_at_ns: 0, dm_id, - last_message_ns: None, + last_message_ns: now_ns(), } } @@ -95,7 +96,7 @@ impl StoredGroup { welcome_id: None, rotated_at_ns: 0, dm_id: dm_id, - last_message_ns: None, + last_message_ns: now_ns(), } } @@ -116,7 +117,7 @@ impl StoredGroup { welcome_id: None, rotated_at_ns: 0, dm_id: None, - last_message_ns: None, + last_message_ns: now_ns(), } } } diff --git a/xmtp_mls/src/storage/encrypted_store/schema.rs b/xmtp_mls/src/storage/encrypted_store/schema.rs index 38b077ff4..083aa7329 100644 --- a/xmtp_mls/src/storage/encrypted_store/schema.rs +++ b/xmtp_mls/src/storage/encrypted_store/schema.rs @@ -56,7 +56,7 @@ diesel::table! { rotated_at_ns -> BigInt, conversation_type -> Integer, dm_id -> Nullable, - last_message_ns -> Nullable, + last_message_ns -> BigInt, } }