| @@ -317,23 +317,6 @@ pub struct UserDisplayTunables { |
| 317 | |
317 | |
| 318 | pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>; |
318 | pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>; |
| 319 | |
319 | |
| 320 | fn merge_encryption(profile: Encryption, global: Encryption) -> Encryption { |
| |
| 321 | Encryption { |
| |
| 322 | indicator: profile.indicator.or(global.indicator), |
| |
| 323 | indicator_location: profile.indicator_location.or(global.indicator_location), |
| |
| 324 | } |
| |
| 325 | } |
| |
| 326 | |
| |
| 327 | fn merge_sorts(profile: SortOverrides, global: SortOverrides) -> SortOverrides { |
| |
| 328 | SortOverrides { |
| |
| 329 | chats: profile.chats.or(global.chats), |
| |
| 330 | dms: profile.dms.or(global.dms), |
| |
| 331 | rooms: profile.rooms.or(global.rooms), |
| |
| 332 | spaces: profile.spaces.or(global.spaces), |
| |
| 333 | members: profile.members.or(global.members), |
| |
| 334 | } |
| |
| 335 | } |
| |
| 336 | |
| |
| 337 | fn merge_maps<K, V>( |
320 | fn merge_maps<K, V>( |
| 338 | profile: Option<HashMap<K, V>>, |
321 | profile: Option<HashMap<K, V>>, |
| 339 | global: Option<HashMap<K, V>>, |
322 | global: Option<HashMap<K, V>>, |
| @@ -509,6 +492,13 @@ pub struct Encryption { |
| 509 | } |
492 | } |
| 510 | |
493 | |
| 511 | impl Encryption { |
494 | impl Encryption { |
| |
495 | fn merge(profile: Self, global: Self) -> Self { |
| |
496 | Encryption { |
| |
497 | indicator: profile.indicator.or(global.indicator), |
| |
498 | indicator_location: profile.indicator_location.or(global.indicator_location), |
| |
499 | } |
| |
500 | } |
| |
501 | |
| 512 | pub fn values(self) -> EncryptionValues { |
502 | pub fn values(self) -> EncryptionValues { |
| 513 | EncryptionValues { |
503 | EncryptionValues { |
| 514 | indicator: self.indicator.unwrap_or_default(), |
504 | indicator: self.indicator.unwrap_or_default(), |
| @@ -641,6 +631,16 @@ pub struct SortOverrides { |
| 641 | } |
631 | } |
| 642 | |
632 | |
| 643 | impl SortOverrides { |
633 | impl SortOverrides { |
| |
634 | fn merge(profile: Self, global: Self) -> Self { |
| |
635 | Self { |
| |
636 | chats: profile.chats.or(global.chats), |
| |
637 | dms: profile.dms.or(global.dms), |
| |
638 | rooms: profile.rooms.or(global.rooms), |
| |
639 | spaces: profile.spaces.or(global.spaces), |
| |
640 | members: profile.members.or(global.members), |
| |
641 | } |
| |
642 | } |
| |
643 | |
| 644 | pub fn values(self) -> SortValues { |
644 | pub fn values(self) -> SortValues { |
| 645 | let rooms = self.rooms.unwrap_or_else(|| Vec::from(DEFAULT_ROOM_SORT)); |
645 | let rooms = self.rooms.unwrap_or_else(|| Vec::from(DEFAULT_ROOM_SORT)); |
| 646 | let chats = self.chats.unwrap_or_else(|| rooms.clone()); |
646 | let chats = self.chats.unwrap_or_else(|| rooms.clone()); |
| @@ -652,6 +652,28 @@ impl SortOverrides { |
| 652 | } |
652 | } |
| 653 | } |
653 | } |
| 654 | |
654 | |
| |
655 | #[derive(Clone, Debug, Default, Deserialize)] |
| |
656 | pub struct Terminal { |
| |
657 | pub enable_extended_keys: Option<bool>, |
| |
658 | } |
| |
659 | |
| |
660 | impl Terminal { |
| |
661 | fn merge(profile: Self, global: Self) -> Self { |
| |
662 | Self { |
| |
663 | enable_extended_keys: profile.enable_extended_keys.or(global.enable_extended_keys), |
| |
664 | } |
| |
665 | } |
| |
666 | |
| |
667 | pub fn values(self) -> TerminalValues { |
| |
668 | TerminalValues { enable_extended_keys: self.enable_extended_keys } |
| |
669 | } |
| |
670 | } |
| |
671 | |
| |
672 | #[derive(Clone, Debug)] |
| |
673 | pub struct TerminalValues { |
| |
674 | pub enable_extended_keys: Option<bool>, |
| |
675 | } |
| |
676 | |
| 655 | #[derive(Clone)] |
677 | #[derive(Clone)] |
| 656 | pub struct TunableValues { |
678 | pub struct TunableValues { |
| 657 | pub encryption: EncryptionValues, |
679 | pub encryption: EncryptionValues, |
| @@ -675,6 +697,7 @@ pub struct TunableValues { |
| 675 | pub open_command: Option<Vec<String>>, |
697 | pub open_command: Option<Vec<String>>, |
| 676 | pub mouse: Mouse, |
698 | pub mouse: Mouse, |
| 677 | pub notifications: Notifications, |
699 | pub notifications: Notifications, |
| |
700 | pub terminal: TerminalValues, |
| 678 | pub image_preview: Option<ImagePreviewValues>, |
701 | pub image_preview: Option<ImagePreviewValues>, |
| 679 | pub user_gutter_width: usize, |
702 | pub user_gutter_width: usize, |
| 680 | pub external_edit_file_suffix: String, |
703 | pub external_edit_file_suffix: String, |
| @@ -684,8 +707,21 @@ pub struct TunableValues { |
| 684 | |
707 | |
| 685 | #[derive(Clone, Default, Deserialize)] |
708 | #[derive(Clone, Default, Deserialize)] |
| 686 | pub struct Tunables { |
709 | pub struct Tunables { |
| |
710 | /// Subsection for overriding encryption-related settings. |
| 687 | #[serde(default)] |
711 | #[serde(default)] |
| 688 | pub encryption: Encryption, |
712 | pub encryption: Encryption, |
| |
713 | |
| |
714 | /// Subsection for overriding sort orders in UI lists. |
| |
715 | #[serde(default)] |
| |
716 | pub sort: SortOverrides, |
| |
717 | |
| |
718 | /// Subsection for overriding terminal settings. |
| |
719 | #[serde(default)] |
| |
720 | pub terminal: Terminal, |
| |
721 | |
| |
722 | /// Subsection for overriding how specific Matrix users are rendered. |
| |
723 | pub users: Option<UserOverrides>, |
| |
724 | |
| 689 | pub log_level: Option<String>, |
725 | pub log_level: Option<String>, |
| 690 | pub max_log_files: Option<usize>, |
726 | pub max_log_files: Option<usize>, |
| 691 | pub message_shortcode_display: Option<bool>, |
727 | pub message_shortcode_display: Option<bool>, |
| @@ -695,12 +731,9 @@ pub struct Tunables { |
| 695 | pub read_receipt_send: Option<bool>, |
731 | pub read_receipt_send: Option<bool>, |
| 696 | pub read_receipt_display: Option<bool>, |
732 | pub read_receipt_display: Option<bool>, |
| 697 | pub request_timeout: Option<u64>, |
733 | pub request_timeout: Option<u64>, |
| 698 | #[serde(default)] |
| |
| 699 | pub sort: SortOverrides, |
| |
| 700 | pub state_event_display: Option<bool>, |
734 | pub state_event_display: Option<bool>, |
| 701 | pub typing_notice_send: Option<bool>, |
735 | pub typing_notice_send: Option<bool>, |
| 702 | pub typing_notice_display: Option<bool>, |
736 | pub typing_notice_display: Option<bool>, |
| 703 | pub users: Option<UserOverrides>, |
| |
| 704 | pub username_display: Option<UserDisplayStyle>, |
737 | pub username_display: Option<UserDisplayStyle>, |
| 705 | pub message_user_color: Option<bool>, |
738 | pub message_user_color: Option<bool>, |
| 706 | pub default_room: Option<String>, |
739 | pub default_room: Option<String>, |
| @@ -717,7 +750,11 @@ pub struct Tunables { |
| 717 | impl Tunables { |
750 | impl Tunables { |
| 718 | fn merge(self, other: Self) -> Self { |
751 | fn merge(self, other: Self) -> Self { |
| 719 | Tunables { |
752 | Tunables { |
| 720 | encryption: merge_encryption(self.encryption, other.encryption), |
753 | encryption: Encryption::merge(self.encryption, other.encryption), |
| |
754 | sort: SortOverrides::merge(self.sort, other.sort), |
| |
755 | terminal: Terminal::merge(self.terminal, other.terminal), |
| |
756 | users: merge_maps(self.users, other.users), |
| |
757 | |
| 721 | log_level: self.log_level.or(other.log_level), |
758 | log_level: self.log_level.or(other.log_level), |
| 722 | max_log_files: self.max_log_files.or(other.max_log_files), |
759 | max_log_files: self.max_log_files.or(other.max_log_files), |
| 723 | message_shortcode_display: self |
760 | message_shortcode_display: self |
| @@ -731,11 +768,9 @@ impl Tunables { |
| 731 | read_receipt_send: self.read_receipt_send.or(other.read_receipt_send), |
768 | read_receipt_send: self.read_receipt_send.or(other.read_receipt_send), |
| 732 | read_receipt_display: self.read_receipt_display.or(other.read_receipt_display), |
769 | read_receipt_display: self.read_receipt_display.or(other.read_receipt_display), |
| 733 | request_timeout: self.request_timeout.or(other.request_timeout), |
770 | request_timeout: self.request_timeout.or(other.request_timeout), |
| 734 | sort: merge_sorts(self.sort, other.sort), |
| |
| 735 | state_event_display: self.state_event_display.or(other.state_event_display), |
771 | state_event_display: self.state_event_display.or(other.state_event_display), |
| 736 | typing_notice_send: self.typing_notice_send.or(other.typing_notice_send), |
772 | typing_notice_send: self.typing_notice_send.or(other.typing_notice_send), |
| 737 | typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), |
773 | typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), |
| 738 | users: merge_maps(self.users, other.users), |
| |
| 739 | username_display: self.username_display.or(other.username_display), |
774 | username_display: self.username_display.or(other.username_display), |
| 740 | message_user_color: self.message_user_color.or(other.message_user_color), |
775 | message_user_color: self.message_user_color.or(other.message_user_color), |
| 741 | default_room: self.default_room.or(other.default_room), |
776 | default_room: self.default_room.or(other.default_room), |
| @@ -754,8 +789,11 @@ impl Tunables { |
| 754 | |
789 | |
| 755 | fn values(self) -> TunableValues { |
790 | fn values(self) -> TunableValues { |
| 756 | TunableValues { |
791 | TunableValues { |
| 757 | log_level: self.log_level.unwrap_or_else(|| "warn".to_string()), |
| |
| 758 | encryption: self.encryption.values(), |
792 | encryption: self.encryption.values(), |
| |
793 | sort: self.sort.values(), |
| |
794 | terminal: self.terminal.values(), |
| |
795 | |
| |
796 | log_level: self.log_level.unwrap_or_else(|| "warn".to_string()), |
| 759 | max_log_files: self.max_log_files.unwrap_or(7), |
797 | max_log_files: self.max_log_files.unwrap_or(7), |
| 760 | message_shortcode_display: self.message_shortcode_display.unwrap_or(false), |
798 | message_shortcode_display: self.message_shortcode_display.unwrap_or(false), |
| 761 | normal_after_send: self.normal_after_send.unwrap_or(false), |
799 | normal_after_send: self.normal_after_send.unwrap_or(false), |
| @@ -764,7 +802,6 @@ impl Tunables { |
| 764 | read_receipt_send: self.read_receipt_send.unwrap_or(true), |
802 | read_receipt_send: self.read_receipt_send.unwrap_or(true), |
| 765 | read_receipt_display: self.read_receipt_display.unwrap_or(true), |
803 | read_receipt_display: self.read_receipt_display.unwrap_or(true), |
| 766 | request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQ_TIMEOUT), |
804 | request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQ_TIMEOUT), |
| 767 | sort: self.sort.values(), |
| |
| 768 | state_event_display: self.state_event_display.unwrap_or(true), |
805 | state_event_display: self.state_event_display.unwrap_or(true), |
| 769 | typing_notice_send: self.typing_notice_send.unwrap_or(true), |
806 | typing_notice_send: self.typing_notice_send.unwrap_or(true), |
| 770 | typing_notice_display: self.typing_notice_display.unwrap_or(true), |
807 | typing_notice_display: self.typing_notice_display.unwrap_or(true), |