diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a1a948..23d93cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Procedure when bumping the version number: - Config file - `ephemeral` config option - `data_dir` config option +- `euph.rooms..username` config option - `euph.rooms..password` config option ## v0.3.0 - 2022-08-22 diff --git a/src/config.rs b/src/config.rs index f984e14..129df20 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,6 +8,7 @@ use crate::macros::ok_or_return; #[derive(Debug, Clone, Default, Deserialize)] pub struct EuphRoom { + pub username: Option, pub password: Option, } diff --git a/src/euph/room.rs b/src/euph/room.rs index cef9321..9fc2068 100644 --- a/src/euph/room.rs +++ b/src/euph/room.rs @@ -58,6 +58,7 @@ enum Event { #[derive(Debug)] struct State { name: String, + username: Option, password: Option, vault: EuphVault, @@ -285,6 +286,17 @@ impl State { self.last_msg_id = Some(d.log.last().map(|m| m.id)); let own_user_id = self.own_user_id().await; self.vault.add_messages(d.log.clone(), None, own_user_id); + + if d.nick.is_none() { + // Avoid overwriting nicks that the euphoria backend already + // knows, e. g. because the user set it while logged in via + // the browser. This setting is mostly meant for ephemeral + // mode. Maybe I'll add a "force_nick" setting at some point + // in the future? + if let Some(username) = &self.username { + self.on_nick(username.clone()); + } + } } Data::LogReply(d) => { let own_user_id = self.own_user_id().await; @@ -421,6 +433,7 @@ pub struct Room { impl Room { pub fn new( vault: EuphVault, + username: Option, password: Option, ) -> (Self, mpsc::UnboundedReceiver) { let (canary_tx, canary_rx) = oneshot::channel(); @@ -430,6 +443,7 @@ impl Room { let state = State { name: vault.room().to_string(), + username, password, vault, conn_tx: None, diff --git a/src/ui/euph/room.rs b/src/ui/euph/room.rs index 2700b1d..b125ce0 100644 --- a/src/ui/euph/room.rs +++ b/src/ui/euph/room.rs @@ -102,7 +102,11 @@ impl EuphRoom { if self.room.is_none() { let store = self.chat.store().clone(); let name = store.room().to_string(); - let (room, euph_room_event_rx) = euph::Room::new(store, self.config.password.clone()); + let (room, euph_room_event_rx) = euph::Room::new( + store, + self.config.username.clone(), + self.config.password.clone(), + ); self.room = Some(room);