mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
feat: add regex option for username_display
This commit is contained in:
parent
33d3407694
commit
7f752da89d
2 changed files with 22 additions and 0 deletions
|
@ -397,6 +397,9 @@ pub enum UserDisplayStyle {
|
||||||
// it can wind up being the Matrix username if there are display name collisions in the room,
|
// it can wind up being the Matrix username if there are display name collisions in the room,
|
||||||
// in order to avoid any confusion.
|
// in order to avoid any confusion.
|
||||||
DisplayName,
|
DisplayName,
|
||||||
|
|
||||||
|
// Acts like Username, except when the username matches given regex, then acts like DisplayName
|
||||||
|
Regex,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
|
@ -566,6 +569,7 @@ pub struct TunableValues {
|
||||||
pub typing_notice_display: bool,
|
pub typing_notice_display: bool,
|
||||||
pub users: UserOverrides,
|
pub users: UserOverrides,
|
||||||
pub username_display: UserDisplayStyle,
|
pub username_display: UserDisplayStyle,
|
||||||
|
pub username_display_regex: Option<String>,
|
||||||
pub message_user_color: bool,
|
pub message_user_color: bool,
|
||||||
pub default_room: Option<String>,
|
pub default_room: Option<String>,
|
||||||
pub open_command: Option<Vec<String>>,
|
pub open_command: Option<Vec<String>>,
|
||||||
|
@ -592,6 +596,7 @@ pub struct Tunables {
|
||||||
pub typing_notice_display: Option<bool>,
|
pub typing_notice_display: Option<bool>,
|
||||||
pub users: Option<UserOverrides>,
|
pub users: Option<UserOverrides>,
|
||||||
pub username_display: Option<UserDisplayStyle>,
|
pub username_display: Option<UserDisplayStyle>,
|
||||||
|
pub username_display_regex: Option<String>,
|
||||||
pub message_user_color: Option<bool>,
|
pub message_user_color: Option<bool>,
|
||||||
pub default_room: Option<String>,
|
pub default_room: Option<String>,
|
||||||
pub open_command: Option<Vec<String>>,
|
pub open_command: Option<Vec<String>>,
|
||||||
|
@ -622,6 +627,7 @@ impl Tunables {
|
||||||
typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
|
typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
|
||||||
users: merge_maps(self.users, other.users),
|
users: merge_maps(self.users, other.users),
|
||||||
username_display: self.username_display.or(other.username_display),
|
username_display: self.username_display.or(other.username_display),
|
||||||
|
username_display_regex: self.username_display_regex.or(other.username_display_regex),
|
||||||
message_user_color: self.message_user_color.or(other.message_user_color),
|
message_user_color: self.message_user_color.or(other.message_user_color),
|
||||||
default_room: self.default_room.or(other.default_room),
|
default_room: self.default_room.or(other.default_room),
|
||||||
open_command: self.open_command.or(other.open_command),
|
open_command: self.open_command.or(other.open_command),
|
||||||
|
@ -650,6 +656,7 @@ impl Tunables {
|
||||||
typing_notice_display: self.typing_notice_display.unwrap_or(true),
|
typing_notice_display: self.typing_notice_display.unwrap_or(true),
|
||||||
users: self.users.unwrap_or_default(),
|
users: self.users.unwrap_or_default(),
|
||||||
username_display: self.username_display.unwrap_or_default(),
|
username_display: self.username_display.unwrap_or_default(),
|
||||||
|
username_display_regex: self.username_display_regex,
|
||||||
message_user_color: self.message_user_color.unwrap_or(false),
|
message_user_color: self.message_user_color.unwrap_or(false),
|
||||||
default_room: self.default_room,
|
default_room: self.default_room,
|
||||||
open_command: self.open_command,
|
open_command: self.open_command,
|
||||||
|
@ -1042,6 +1049,20 @@ impl ApplicationSettings {
|
||||||
Cow::Borrowed(user_id.as_str())
|
Cow::Borrowed(user_id.as_str())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
(None, UserDisplayStyle::Regex) => {
|
||||||
|
let re = regex::Regex::new(
|
||||||
|
&self.tunables.username_display_regex.clone().unwrap_or("*".into()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if !re.is_match(user_id.as_str()) {
|
||||||
|
Cow::Borrowed(user_id.as_str())
|
||||||
|
} else if let Some(display) = info.display_names.get(user_id) {
|
||||||
|
Cow::Borrowed(display.as_str())
|
||||||
|
} else {
|
||||||
|
Cow::Borrowed(user_id.as_str())
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Span::styled(name, style)
|
Span::styled(name, style)
|
||||||
|
|
|
@ -189,6 +189,7 @@ pub fn mock_tunables() -> TunableValues {
|
||||||
open_command: None,
|
open_command: None,
|
||||||
external_edit_file_suffix: String::from(".md"),
|
external_edit_file_suffix: String::from(".md"),
|
||||||
username_display: UserDisplayStyle::Username,
|
username_display: UserDisplayStyle::Username,
|
||||||
|
username_display_regex: Some(String::from(".*")),
|
||||||
message_user_color: false,
|
message_user_color: false,
|
||||||
mouse: Default::default(),
|
mouse: Default::default(),
|
||||||
notifications: Notifications {
|
notifications: Notifications {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue