Add 'euph.rooms.<name>.force_username' config option

This commit is contained in:
Joscha 2022-08-25 23:19:40 +02:00
parent d0ba210855
commit 6150d05255
4 changed files with 9 additions and 7 deletions

View file

@ -19,6 +19,7 @@ Procedure when bumping the version number:
- `ephemeral` config option
- `data_dir` config option
- `euph.rooms.<name>.username` config option
- `euph.rooms.<name>.force_username` config option
- `euph.rooms.<name>.password` config option
## v0.3.0 - 2022-08-22

View file

@ -9,6 +9,8 @@ use crate::macros::ok_or_return;
#[derive(Debug, Clone, Default, Deserialize)]
pub struct EuphRoom {
pub username: Option<String>,
#[serde(default)]
pub force_username: bool,
pub password: Option<String>,
}

View file

@ -59,6 +59,7 @@ enum Event {
struct State {
name: String,
username: Option<String>,
force_username: bool,
password: Option<String>,
vault: EuphVault,
@ -287,13 +288,8 @@ impl State {
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 {
if let Some(username) = &self.username {
if self.force_username || d.nick.is_none() {
self.on_nick(username.clone());
}
}
@ -434,6 +430,7 @@ impl Room {
pub fn new(
vault: EuphVault,
username: Option<String>,
force_username: bool,
password: Option<String>,
) -> (Self, mpsc::UnboundedReceiver<EuphRoomEvent>) {
let (canary_tx, canary_rx) = oneshot::channel();
@ -444,6 +441,7 @@ impl Room {
let state = State {
name: vault.room().to_string(),
username,
force_username,
password,
vault,
conn_tx: None,

View file

@ -105,6 +105,7 @@ impl EuphRoom {
let (room, euph_room_event_rx) = euph::Room::new(
store,
self.config.username.clone(),
self.config.force_username,
self.config.password.clone(),
);