Skip to content
10 changes: 8 additions & 2 deletions crates/buzz-cli/src/commands/dms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ pub async fn cmd_add_dm_member(
client: &BuzzClient,
channel_id: &str,
pubkey: &str,
include_history: bool,
) -> Result<(), CliError> {
let channel_uuid = parse_uuid(channel_id)?;
validate_hex64(pubkey)?;

let builder = buzz_sdk::build_dm_add_member(channel_uuid, pubkey).map_err(sdk_err)?;
let builder =
buzz_sdk::build_dm_add_member(channel_uuid, pubkey, include_history).map_err(sdk_err)?;
let event = client.sign_event(builder).await?;

let resp = client.submit_event(event).await?;
Expand All @@ -154,7 +156,11 @@ pub async fn dispatch(cmd: crate::DmsCmd, client: &BuzzClient) -> Result<(), Cli
match cmd {
DmsCmd::List { limit } => cmd_list_dms(client, limit).await,
DmsCmd::Open { pubkeys } => cmd_open_dm(client, &pubkeys).await,
DmsCmd::AddMember { channel, pubkey } => cmd_add_dm_member(client, &channel, &pubkey).await,
DmsCmd::AddMember {
channel,
pubkey,
include_history,
} => cmd_add_dm_member(client, &channel, &pubkey, include_history).await,
DmsCmd::Hide { channel } => cmd_hide_dm(client, &channel).await,
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/buzz-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,11 @@ pub enum DmsCmd {
/// User pubkey to add (64-char hex)
#[arg(long)]
pubkey: String,
/// Add them to this DM with its history, instead of starting a new DM
/// of everyone. A person added to a DM of one person and their agents
/// always starts a new DM.
#[arg(long)]
include_history: bool,
},
/// Hide a DM conversation from your DM list
Hide {
Expand Down
14 changes: 10 additions & 4 deletions crates/buzz-db/src/store/admission_postgres_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ async fn dm_writers_require_application_admission() {
let participants: [&[u8]; 2] = [&[1; 32], &[2; 32]];
for community in &communities[1..] {
assert_fenced(
super::dm::create_dm(&db.pool, *community, &participants, participants[0])
super::dm::create_dm(&db.pool, *community, &participants, participants[0], false)
.await
.expect_err("DM create must reject"),
);
Expand All @@ -501,9 +501,15 @@ async fn dm_writers_require_application_admission() {
.expect_err("DM hide must reject"),
);
}
super::dm::create_dm(&db.pool, communities[0], &participants, participants[0])
.await
.expect("active DM create succeeds");
super::dm::create_dm(
&db.pool,
communities[0],
&participants,
participants[0],
false,
)
.await
.expect("active DM create succeeds");
}

#[tokio::test]
Expand Down
6 changes: 5 additions & 1 deletion crates/buzz-db/src/store/channel_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,10 @@ pub(crate) async fn put_members_with_event(
/// tag, the TTL reaper's single UPDATE), and none of them takes the
/// membership lock. So an archive either commits before [`put_members_on`]
/// reads `archived_at`, or waits until this write commits.
async fn lock_channel_for_member_put(tx: &mut AdmittedTx, channel_id: Uuid) -> Result<()> {
pub(crate) async fn lock_channel_for_member_put(
tx: &mut AdmittedTx,
channel_id: Uuid,
) -> Result<()> {
let community_id = tx.community();
acquire_channel_membership_lock(tx.conn(), community_id, channel_id).await?;
lock_channel_ttl_shared_in_transaction(tx, channel_id).await?;
Expand Down Expand Up @@ -1195,6 +1198,7 @@ pub async fn remove_member(
if result.rows_affected() == 0 {
return Err(DbError::MemberNotFound(channel_id));
}
crate::dm::release_dm_identity(tx.conn(), community_id, channel_id).await?;

tx.commit().await?;
Ok(())
Expand Down
Loading
Loading