| @@ -317,23 +317,6 @@ pub struct UserDisplayTunables { |
| 317 | 317 | |
| 318 | 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 | 320 | fn merge_maps<K, V>( |
| 338 | 321 | profile: Option<HashMap<K, V>>, |
| 339 | 322 | global: Option<HashMap<K, V>>, |
| @@ -509,6 +492,13 @@ pub struct Encryption { |
| 509 | 492 | } |
| 510 | 493 | |
| 511 | 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 | 502 | pub fn values(self) -> EncryptionValues { |
| 513 | 503 | EncryptionValues { |
| 514 | 504 | indicator: self.indicator.unwrap_or_default(), |
| @@ -641,6 +631,16 @@ pub struct SortOverrides { |
| 641 | 631 | } |
| 642 | 632 | |
| 643 | 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 | 644 | pub fn values(self) -> SortValues { |
| 645 | 645 | let rooms = self.rooms.unwrap_or_else(|| Vec::from(DEFAULT_ROOM_SORT)); |
| 646 | 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 | 677 | #[derive(Clone)] |
| 656 | 678 | pub struct TunableValues { |
| 657 | 679 | pub encryption: EncryptionValues, |
| @@ -675,6 +697,7 @@ pub struct TunableValues { |
| 675 | 697 | pub open_command: Option<Vec<String>>, |
| 676 | 698 | pub mouse: Mouse, |
| 677 | 699 | pub notifications: Notifications, |
| 700 | pub terminal: TerminalValues, |
| 678 | 701 | pub image_preview: Option<ImagePreviewValues>, |
| 679 | 702 | pub user_gutter_width: usize, |
| 680 | 703 | pub external_edit_file_suffix: String, |
| @@ -684,8 +707,21 @@ pub struct TunableValues { |
| 684 | 707 | |
| 685 | 708 | #[derive(Clone, Default, Deserialize)] |
| 686 | 709 | pub struct Tunables { |
| 710 | /// Subsection for overriding encryption-related settings. |
| 687 | 711 | #[serde(default)] |
| 688 | 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 | 725 | pub log_level: Option<String>, |
| 690 | 726 | pub max_log_files: Option<usize>, |
| 691 | 727 | pub message_shortcode_display: Option<bool>, |
| @@ -695,12 +731,9 @@ pub struct Tunables { |
| 695 | 731 | pub read_receipt_send: Option<bool>, |
| 696 | 732 | pub read_receipt_display: Option<bool>, |
| 697 | 733 | pub request_timeout: Option<u64>, |
| 698 | | #[serde(default)] |
| 699 | | pub sort: SortOverrides, |
| 700 | 734 | pub state_event_display: Option<bool>, |
| 701 | 735 | pub typing_notice_send: Option<bool>, |
| 702 | 736 | pub typing_notice_display: Option<bool>, |
| 703 | | pub users: Option<UserOverrides>, |
| 704 | 737 | pub username_display: Option<UserDisplayStyle>, |
| 705 | 738 | pub message_user_color: Option<bool>, |
| 706 | 739 | pub default_room: Option<String>, |
| @@ -717,7 +750,11 @@ pub struct Tunables { |
| 717 | 750 | impl Tunables { |
| 718 | 751 | fn merge(self, other: Self) -> Self { |
| 719 | 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 | 758 | log_level: self.log_level.or(other.log_level), |
| 722 | 759 | max_log_files: self.max_log_files.or(other.max_log_files), |
| 723 | 760 | message_shortcode_display: self |
| @@ -731,11 +768,9 @@ impl Tunables { |
| 731 | 768 | read_receipt_send: self.read_receipt_send.or(other.read_receipt_send), |
| 732 | 769 | read_receipt_display: self.read_receipt_display.or(other.read_receipt_display), |
| 733 | 770 | request_timeout: self.request_timeout.or(other.request_timeout), |
| 734 | | sort: merge_sorts(self.sort, other.sort), |
| 735 | 771 | state_event_display: self.state_event_display.or(other.state_event_display), |
| 736 | 772 | typing_notice_send: self.typing_notice_send.or(other.typing_notice_send), |
| 737 | 773 | typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), |
| 738 | | users: merge_maps(self.users, other.users), |
| 739 | 774 | username_display: self.username_display.or(other.username_display), |
| 740 | 775 | message_user_color: self.message_user_color.or(other.message_user_color), |
| 741 | 776 | default_room: self.default_room.or(other.default_room), |
| @@ -754,8 +789,11 @@ impl Tunables { |
| 754 | 789 | |
| 755 | 790 | fn values(self) -> TunableValues { |
| 756 | 791 | TunableValues { |
| 757 | | log_level: self.log_level.unwrap_or_else(|| "warn".to_string()), |
| 758 | 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 | 797 | max_log_files: self.max_log_files.unwrap_or(7), |
| 760 | 798 | message_shortcode_display: self.message_shortcode_display.unwrap_or(false), |
| 761 | 799 | normal_after_send: self.normal_after_send.unwrap_or(false), |
| @@ -764,7 +802,6 @@ impl Tunables { |
| 764 | 802 | read_receipt_send: self.read_receipt_send.unwrap_or(true), |
| 765 | 803 | read_receipt_display: self.read_receipt_display.unwrap_or(true), |
| 766 | 804 | request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQ_TIMEOUT), |
| 767 | | sort: self.sort.values(), |
| 768 | 805 | state_event_display: self.state_event_display.unwrap_or(true), |
| 769 | 806 | typing_notice_send: self.typing_notice_send.unwrap_or(true), |
| 770 | 807 | typing_notice_display: self.typing_notice_display.unwrap_or(true), |