Skip to content

Commit

Permalink
reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
codabrink committed Dec 18, 2024
1 parent 9b894b5 commit 4296cee
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
2 changes: 0 additions & 2 deletions xmtp_mls/migrations/2024-12-18-170645_add_dm_id/down.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ALTER TABLE groups DROP COLUMN dm_id;
ALTER TABLE groups DROP COLUMN last_message_ns;
ALTER TABLE groups ADD COLUMN dm_inbox_id TEXT;

DROP TRIGGER IF EXISTS msg_inserted;
17 changes: 1 addition & 16 deletions xmtp_mls/migrations/2024-12-18-170645_add_dm_id/up.sql
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
ALTER TABLE groups ADD COLUMN dm_id TEXT;
ALTER TABLE groups ADD COLUMN last_message_ns BIGINT NOT NULL DEFAULT (created_at_ns);

-- Fill the dm_id column
UPDATE groups
SET dm_id = 'dm:' ||
LOWER(
CASE
WHEN LOWER((SELECT inbox_id FROM identity)) < LOWER(dm_inbox_id)
THEN (SELECT inbox_id FROM identity) || ':' || dm_inbox_id
ELSE dm_inbox_id || ':' || (SELECT inbox_id FROM identity)
END
)
WHERE dm_inbox_id IS NOT NULL;

ALTER TABLE groups REMOVE COLUMN dm_inbox_id;
ALTER TABLE groups ADD COLUMN last_message_ns BIGINT NOT NULL DEFAULT (strftime('%s', 'now') * 1000000000);

-- Create a trigger to auto-update group table on insert
CREATE TRIGGER msg_iserted
Expand Down
16 changes: 8 additions & 8 deletions xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ pub struct StoredGroup {
pub added_by_inbox_id: String,
/// The sequence id of the welcome message
pub welcome_id: Option<i64>,
/// The inbox_id of the DM target
pub dm_inbox_id: Option<String>,
/// 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<String>,
/// Timestamp of when the last message was sent for this group (updated automatically in a trigger)
pub last_message_ns: i64,
}
Expand All @@ -59,7 +59,7 @@ impl StoredGroup {
added_by_inbox_id: String,
welcome_id: i64,
conversation_type: ConversationType,
dm_id: Option<String>,
dm_inbox_id: Option<String>,
) -> Self {
Self {
id,
Expand All @@ -70,7 +70,7 @@ impl StoredGroup {
added_by_inbox_id,
welcome_id: Some(welcome_id),
rotated_at_ns: 0,
dm_id,
dm_inbox_id,
last_message_ns: now_ns(),
}
}
Expand All @@ -81,21 +81,21 @@ impl StoredGroup {
created_at_ns: i64,
membership_state: GroupMembershipState,
added_by_inbox_id: String,
dm_id: Option<String>,
dm_inbox_id: Option<String>,
) -> Self {
Self {
id,
created_at_ns,
membership_state,
installations_last_checked: 0,
conversation_type: match dm_id {
conversation_type: match dm_inbox_id {
Some(_) => ConversationType::Dm,
None => ConversationType::Group,
},
added_by_inbox_id,
welcome_id: None,
rotated_at_ns: 0,
dm_id: dm_id,
dm_inbox_id,
last_message_ns: now_ns(),
}
}
Expand All @@ -116,7 +116,7 @@ impl StoredGroup {
added_by_inbox_id: "".into(),
welcome_id: None,
rotated_at_ns: 0,
dm_id: None,
dm_inbox_id: None,
last_message_ns: now_ns(),
}
}
Expand Down
1 change: 0 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ diesel::table! {
dm_inbox_id -> Nullable<Text>,
rotated_at_ns -> BigInt,
conversation_type -> Integer,
dm_id -> Nullable<Text>,
last_message_ns -> BigInt,
}
}
Expand Down

0 comments on commit 4296cee

Please sign in to comment.