Commit 2ac71da9a6
Unregistered key
Layout: unified · split
src/base.rs +77 −2
| @@ -45,6 +45,7 @@ use matrix_sdk::{ | |||
| 45 | RoomMessageEventContent, | 45 | RoomMessageEventContent, |
| 46 | RoomMessageEventContentWithoutRelation, | 46 | RoomMessageEventContentWithoutRelation, |
| 47 | }, | 47 | }, |
| 48 | room::redaction::{OriginalSyncRoomRedactionEvent, SyncRoomRedactionEvent}, | ||
| 48 | tag::{TagName, Tags}, | 49 | tag::{TagName, Tags}, |
| 49 | MessageLikeEvent, | 50 | MessageLikeEvent, |
| 50 | }, | 51 | }, |
| @@ -54,6 +55,7 @@ use matrix_sdk::{ | |||
| 54 | OwnedRoomId, | 55 | OwnedRoomId, |
| 55 | OwnedUserId, | 56 | OwnedUserId, |
| 56 | RoomId, | 57 | RoomId, |
| 58 | RoomVersionId, | ||
| 57 | UserId, | 59 | UserId, |
| 58 | }, | 60 | }, |
| 59 | RoomState as MatrixRoomState, | 61 | RoomState as MatrixRoomState, |
| @@ -729,7 +731,7 @@ pub struct RoomInfo { | |||
| 729 | pub keys: HashMap<OwnedEventId, EventLocation>, | 731 | pub keys: HashMap<OwnedEventId, EventLocation>, |
| 730 | 732 | ||
| 731 | /// The messages loaded for this room. | 733 | /// The messages loaded for this room. |
| 732 | pub messages: Messages, | 734 | messages: Messages, |
| 733 | 735 | ||
| 734 | /// A map of read markers to display on different events. | 736 | /// A map of read markers to display on different events. |
| 735 | pub event_receipts: HashMap<OwnedEventId, HashSet<OwnedUserId>>, | 737 | pub event_receipts: HashMap<OwnedEventId, HashSet<OwnedUserId>>, |
| @@ -745,7 +747,7 @@ pub struct RoomInfo { | |||
| 745 | pub reactions: HashMap<OwnedEventId, MessageReactions>, | 747 | pub reactions: HashMap<OwnedEventId, MessageReactions>, |
| 746 | 748 | ||
| 747 | /// A map of message identifiers to thread replies. | 749 | /// A map of message identifiers to thread replies. |
| 748 | pub threads: HashMap<OwnedEventId, Messages>, | 750 | threads: HashMap<OwnedEventId, Messages>, |
| 749 | 751 | ||
| 750 | /// Whether the scrollback for this room is currently being fetched. | 752 | /// Whether the scrollback for this room is currently being fetched. |
| 751 | pub fetching: bool, | 753 | pub fetching: bool, |
| @@ -767,6 +769,48 @@ pub struct RoomInfo { | |||
| 767 | } | 769 | } |
| 768 | 770 | ||
| 769 | impl RoomInfo { | 771 | impl RoomInfo { |
| 772 | pub fn get_thread(&self, root: Option<&EventId>) -> Option<&Messages> { | ||
| 773 | if let Some(thread_root) = root { | ||
| 774 | self.threads.get(thread_root) | ||
| 775 | } else { | ||
| 776 | Some(&self.messages) | ||
| 777 | } | ||
| 778 | } | ||
| 779 | |||
| 780 | pub fn get_thread_mut(&mut self, root: Option<OwnedEventId>) -> &mut Messages { | ||
| 781 | if let Some(thread_root) = root { | ||
| 782 | self.threads.entry(thread_root).or_default() | ||
| 783 | } else { | ||
| 784 | &mut self.messages | ||
| 785 | } | ||
| 786 | } | ||
| 787 | |||
| 788 | /// Get the event for the last message in a thread (or the thread root if there are no | ||
| 789 | /// in-thread replies yet). | ||
| 790 | /// | ||
| 791 | /// This returns `None` if the event identifier isn't in the room. | ||
| 792 | pub fn get_thread_last<'a>( | ||
| 793 | &'a self, | ||
| 794 | thread_root: &OwnedEventId, | ||
| 795 | ) -> Option<&'a OriginalRoomMessageEvent> { | ||
| 796 | let last = self.threads.get(thread_root).and_then(|t| Some(t.last_key_value()?.1)); | ||
| 797 | |||
| 798 | let msg = if let Some(last) = last { | ||
| 799 | &last.event | ||
| 800 | } else if let EventLocation::Message(_, key) = self.keys.get(thread_root)? { | ||
| 801 | let msg = self.messages.get(key)?; | ||
| 802 | &msg.event | ||
| 803 | } else { | ||
| 804 | return None; | ||
| 805 | }; | ||
| 806 | |||
| 807 | if let MessageEvent::Original(ev) = &msg { | ||
| 808 | Some(ev) | ||
| 809 | } else { | ||
| 810 | None | ||
| 811 | } | ||
| 812 | } | ||
| 813 | |||
| 770 | /// Get the reactions and their counts for a message. | 814 | /// Get the reactions and their counts for a message. |
| 771 | pub fn get_reactions(&self, event_id: &EventId) -> Vec<(&str, usize)> { | 815 | pub fn get_reactions(&self, event_id: &EventId) -> Vec<(&str, usize)> { |
| 772 | if let Some(reacts) = self.reactions.get(event_id) { | 816 | if let Some(reacts) = self.reactions.get(event_id) { |
| @@ -801,6 +845,37 @@ impl RoomInfo { | |||
| 801 | self.messages.get_mut(self.keys.get(event_id)?.to_message_key()?) | 845 | self.messages.get_mut(self.keys.get(event_id)?.to_message_key()?) |
| 802 | } | 846 | } |
| 803 | 847 | ||
| 848 | pub fn redact(&mut self, ev: OriginalSyncRoomRedactionEvent, room_version: &RoomVersionId) { | ||
| 849 | let Some(redacts) = &ev.redacts else { | ||
| 850 | return; | ||
| 851 | }; | ||
| 852 | |||
| 853 | match self.keys.get(redacts) { | ||
| 854 | None => return, | ||
| 855 | Some(EventLocation::Message(None, key)) => { | ||
| 856 | if let Some(msg) = self.messages.get_mut(key) { | ||
| 857 | let ev = SyncRoomRedactionEvent::Original(ev); | ||
| 858 | msg.redact(ev, room_version); | ||
| 859 | } | ||
| 860 | }, | ||
| 861 | Some(EventLocation::Message(Some(root), key)) => { | ||
| 862 | if let Some(thread) = self.threads.get_mut(root) { | ||
| 863 | if let Some(msg) = thread.get_mut(key) { | ||
| 864 | let ev = SyncRoomRedactionEvent::Original(ev); | ||
| 865 | msg.redact(ev, room_version); | ||
| 866 | } | ||
| 867 | } | ||
| 868 | }, | ||
| 869 | Some(EventLocation::Reaction(event_id)) => { | ||
| 870 | if let Some(reactions) = self.reactions.get_mut(event_id) { | ||
| 871 | reactions.remove(redacts); | ||
| 872 | } | ||
| 873 | |||
| 874 | self.keys.remove(redacts); | ||
| 875 | }, | ||
| 876 | } | ||
| 877 | } | ||
| 878 | |||
| 804 | /// Insert a reaction to a message. | 879 | /// Insert a reaction to a message. |
| 805 | pub fn insert_reaction(&mut self, react: ReactionEvent) { | 880 | pub fn insert_reaction(&mut self, react: ReactionEvent) { |
| 806 | match react { | 881 | match react { |
src/message/mod.rs +105 −82
| @@ -638,6 +638,106 @@ impl<'a> MessageFormatter<'a> { | |||
| 638 | self.push_spans(line, style, text); | 638 | self.push_spans(line, style, text); |
| 639 | } | 639 | } |
| 640 | } | 640 | } |
| 641 | |||
| 642 | fn push_in_reply( | ||
| 643 | &mut self, | ||
| 644 | msg: &'a Message, | ||
| 645 | style: Style, | ||
| 646 | text: &mut Text<'a>, | ||
| 647 | info: &'a RoomInfo, | ||
| 648 | ) { | ||
| 649 | let width = self.width(); | ||
| 650 | let w = width.saturating_sub(2); | ||
| 651 | let shortcodes = self.settings.tunables.message_shortcode_display; | ||
| 652 | let mut replied = msg.show_msg(w, style, true, shortcodes); | ||
| 653 | let mut sender = msg.sender_span(info, self.settings); | ||
| 654 | let sender_width = UnicodeWidthStr::width(sender.content.as_ref()); | ||
| 655 | let trailing = w.saturating_sub(sender_width + 1); | ||
| 656 | |||
| 657 | sender.style = sender.style.patch(style); | ||
| 658 | |||
| 659 | self.push_spans( | ||
| 660 | Line::from(vec![ | ||
| 661 | Span::styled(" ", style), | ||
| 662 | Span::styled(THICK_VERTICAL, style), | ||
| 663 | sender, | ||
| 664 | Span::styled(":", style), | ||
| 665 | space_span(trailing, style), | ||
| 666 | ]), | ||
| 667 | style, | ||
| 668 | text, | ||
| 669 | ); | ||
| 670 | |||
| 671 | for line in replied.lines.iter_mut() { | ||
| 672 | line.spans.insert(0, Span::styled(THICK_VERTICAL, style)); | ||
| 673 | line.spans.insert(0, Span::styled(" ", style)); | ||
| 674 | } | ||
| 675 | |||
| 676 | self.push_text(replied, style, text); | ||
| 677 | } | ||
| 678 | |||
| 679 | fn push_reactions(&mut self, counts: Vec<(&'a str, usize)>, style: Style, text: &mut Text<'a>) { | ||
| 680 | let mut emojis = printer::TextPrinter::new(self.width(), style, false, false); | ||
| 681 | let mut reactions = 0; | ||
| 682 | |||
| 683 | for (key, count) in counts { | ||
| 684 | if reactions != 0 { | ||
| 685 | emojis.push_str(" ", style); | ||
| 686 | } | ||
| 687 | |||
| 688 | let name = if self.settings.tunables.reaction_shortcode_display { | ||
| 689 | if let Some(emoji) = emojis::get(key) { | ||
| 690 | if let Some(short) = emoji.shortcode() { | ||
| 691 | short | ||
| 692 | } else { | ||
| 693 | // No ASCII shortcode name to show. | ||
| 694 | continue; | ||
| 695 | } | ||
| 696 | } else if key.chars().all(|c| c.is_ascii_alphanumeric()) { | ||
| 697 | key | ||
| 698 | } else { | ||
| 699 | // Not an Emoji or a printable ASCII string. | ||
| 700 | continue; | ||
| 701 | } | ||
| 702 | } else { | ||
| 703 | key | ||
| 704 | }; | ||
| 705 | |||
| 706 | emojis.push_str("[", style); | ||
| 707 | emojis.push_str(name, style); | ||
| 708 | emojis.push_str(" ", style); | ||
| 709 | emojis.push_span_nobreak(Span::styled(count.to_string(), style)); | ||
| 710 | emojis.push_str("]", style); | ||
| 711 | |||
| 712 | reactions += 1; | ||
| 713 | } | ||
| 714 | |||
| 715 | if reactions > 0 { | ||
| 716 | self.push_text(emojis.finish(), style, text); | ||
| 717 | } | ||
| 718 | } | ||
| 719 | |||
| 720 | fn push_thread_reply_count(&mut self, len: usize, text: &mut Text<'a>) { | ||
| 721 | if len == 0 { | ||
| 722 | return; | ||
| 723 | } | ||
| 724 | |||
| 725 | // If we have threaded replies to this message, show how many. | ||
| 726 | let plural = len != 1; | ||
| 727 | let style = Style::default(); | ||
| 728 | let mut threaded = | ||
| 729 | printer::TextPrinter::new(self.width(), style, false, false).literal(true); | ||
| 730 | let len = Span::styled(len.to_string(), style.add_modifier(StyleModifier::BOLD)); | ||
| 731 | threaded.push_str(" \u{2937} ", style); | ||
| 732 | threaded.push_span_nobreak(len); | ||
| 733 | if plural { | ||
| 734 | threaded.push_str(" replies in thread", style); | ||
| 735 | } else { | ||
| 736 | threaded.push_str(" reply in thread", style); | ||
| 737 | } | ||
| 738 | |||
| 739 | self.push_text(threaded.finish(), style, text); | ||
| 740 | } | ||
| 641 | } | 741 | } |
| 642 | 742 | ||
| 643 | pub enum ImageStatus { | 743 | pub enum ImageStatus { |
| @@ -835,33 +935,7 @@ impl Message { | |||
| 835 | .and_then(|e| info.get_event(&e)); | 935 | .and_then(|e| info.get_event(&e)); |
| 836 | 936 | ||
| 837 | if let Some(r) = &reply { | 937 | if let Some(r) = &reply { |
| 838 | let w = width.saturating_sub(2); | 938 | fmt.push_in_reply(r, style, &mut text, info); |
| 839 | let mut replied = | ||
| 840 | r.show_msg(w, style, true, settings.tunables.message_shortcode_display); | ||
| 841 | let mut sender = r.sender_span(info, settings); | ||
| 842 | let sender_width = UnicodeWidthStr::width(sender.content.as_ref()); | ||
| 843 | let trailing = w.saturating_sub(sender_width + 1); | ||
| 844 | |||
| 845 | sender.style = sender.style.patch(style); | ||
| 846 | |||
| 847 | fmt.push_spans( | ||
| 848 | Line::from(vec![ | ||
| 849 | Span::styled(" ", style), | ||
| 850 | Span::styled(THICK_VERTICAL, style), | ||
| 851 | sender, | ||
| 852 | Span::styled(":", style), | ||
| 853 | space_span(trailing, style), | ||
| 854 | ]), | ||
| 855 | style, | ||
| 856 | &mut text, | ||
| 857 | ); | ||
| 858 | |||
| 859 | for line in replied.lines.iter_mut() { | ||
| 860 | line.spans.insert(0, Span::styled(THICK_VERTICAL, style)); | ||
| 861 | line.spans.insert(0, Span::styled(" ", style)); | ||
| 862 | } | ||
| 863 | |||
| 864 | fmt.push_text(replied, style, &mut text); | ||
| 865 | } | 939 | } |
| 866 | 940 | ||
| 867 | // Now show the message contents, and the inlined reply if we couldn't find it above. | 941 | // Now show the message contents, and the inlined reply if we couldn't find it above. |
| @@ -879,63 +953,12 @@ impl Message { | |||
| 879 | } | 953 | } |
| 880 | 954 | ||
| 881 | if settings.tunables.reaction_display { | 955 | if settings.tunables.reaction_display { |
| 882 | // Pass false for emoji_shortcodes parameter because we handle shortcodes ourselves | 956 | let reactions = info.get_reactions(self.event.event_id()); |
| 883 | // before pushing to the printer. | 957 | fmt.push_reactions(reactions, style, &mut text); |
| 884 | let mut emojis = printer::TextPrinter::new(width, style, false, false); | ||
| 885 | let mut reactions = 0; | ||
| 886 | |||
| 887 | for (key, count) in info.get_reactions(self.event.event_id()).into_iter() { | ||
| 888 | if reactions != 0 { | ||
| 889 | emojis.push_str(" ", style); | ||
| 890 | } | ||
| 891 | |||
| 892 | let name = if settings.tunables.reaction_shortcode_display { | ||
| 893 | if let Some(emoji) = emojis::get(key) { | ||
| 894 | if let Some(short) = emoji.shortcode() { | ||
| 895 | short | ||
| 896 | } else { | ||
| 897 | // No ASCII shortcode name to show. | ||
| 898 | continue; | ||
| 899 | } | ||
| 900 | } else if key.chars().all(|c| c.is_ascii_alphanumeric()) { | ||
| 901 | key | ||
| 902 | } else { | ||
| 903 | // Not an Emoji or a printable ASCII string. | ||
| 904 | continue; | ||
| 905 | } | ||
| 906 | } else { | ||
| 907 | key | ||
| 908 | }; | ||
| 909 | |||
| 910 | emojis.push_str("[", style); | ||
| 911 | emojis.push_str(name, style); | ||
| 912 | emojis.push_str(" ", style); | ||
| 913 | emojis.push_span_nobreak(Span::styled(count.to_string(), style)); | ||
| 914 | emojis.push_str("]", style); | ||
| 915 | |||
| 916 | reactions += 1; | ||
| 917 | } | ||
| 918 | |||
| 919 | if reactions > 0 { | ||
| 920 | fmt.push_text(emojis.finish(), style, &mut text); | ||
| 921 | } | ||
| 922 | } | 958 | } |
| 923 | 959 | ||
| 924 | if let Some(thread) = info.threads.get(self.event.event_id()) { | 960 | if let Some(thread) = info.get_thread(Some(self.event.event_id())) { |
| 925 | // If we have threaded replies to this message, show how many. | 961 | fmt.push_thread_reply_count(thread.len(), &mut text); |
| 926 | let len = thread.len(); | ||
| 927 | |||
| 928 | if len > 0 { | ||
| 929 | let style = Style::default(); | ||
| 930 | let emoji_shortcodes = settings.tunables.message_shortcode_display; | ||
| 931 | let mut threaded = | ||
| 932 | printer::TextPrinter::new(width, style, false, emoji_shortcodes).literal(true); | ||
| 933 | let len = Span::styled(len.to_string(), style.add_modifier(StyleModifier::BOLD)); | ||
| 934 | threaded.push_str(" \u{2937} ", style); | ||
| 935 | threaded.push_span_nobreak(len); | ||
| 936 | threaded.push_str(" replies in thread", style); | ||
| 937 | fmt.push_text(threaded.finish(), style, &mut text); | ||
| 938 | } | ||
| 939 | } | 962 | } |
| 940 | 963 | ||
| 941 | text | 964 | text |
src/tests.rs +6 −20
| @@ -21,7 +21,7 @@ use tracing::Level; | |||
| 21 | use url::Url; | 21 | use url::Url; |
| 22 | 22 | ||
| 23 | use crate::{ | 23 | use crate::{ |
| 24 | base::{ChatStore, EventLocation, ProgramStore, RoomFetchStatus, RoomInfo}, | 24 | base::{ChatStore, EventLocation, ProgramStore, RoomInfo}, |
| 25 | config::{ | 25 | config::{ |
| 26 | user_color, | 26 | user_color, |
| 27 | user_style_from_color, | 27 | user_style_from_color, |
| @@ -148,25 +148,11 @@ pub fn mock_messages() -> Messages { | |||
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | pub fn mock_room() -> RoomInfo { | 150 | pub fn mock_room() -> RoomInfo { |
| 151 | RoomInfo { | 151 | let mut room = RoomInfo::default(); |
| 152 | name: Some("Watercooler Discussion".into()), | 152 | room.name = Some("Watercooler Discussion".into()); |
| 153 | tags: None, | 153 | room.keys = mock_keys(); |
| 154 | 154 | *room.get_thread_mut(None) = mock_messages(); | |
| 155 | keys: mock_keys(), | 155 | room |
| 156 | messages: mock_messages(), | ||
| 157 | threads: HashMap::default(), | ||
| 158 | |||
| 159 | event_receipts: HashMap::new(), | ||
| 160 | user_receipts: HashMap::new(), | ||
| 161 | reactions: HashMap::new(), | ||
| 162 | |||
| 163 | fetching: false, | ||
| 164 | fetch_id: RoomFetchStatus::NotStarted, | ||
| 165 | fetch_last: None, | ||
| 166 | users_typing: None, | ||
| 167 | display_names: HashMap::new(), | ||
| 168 | draw_last: None, | ||
| 169 | } | ||
| 170 | } | 156 | } |
| 171 | 157 | ||
| 172 | pub fn mock_dirs() -> DirectoryValues { | 158 | pub fn mock_dirs() -> DirectoryValues { |
src/windows/room/chat.rs +23 −48
| @@ -28,7 +28,6 @@ use matrix_sdk::{ | |||
| 28 | RoomMessageEventContent, | 28 | RoomMessageEventContent, |
| 29 | TextMessageEventContent, | 29 | TextMessageEventContent, |
| 30 | }, | 30 | }, |
| 31 | EventId, | ||
| 32 | OwnedEventId, | 31 | OwnedEventId, |
| 33 | OwnedRoomId, | 32 | OwnedRoomId, |
| 34 | RoomId, | 33 | RoomId, |
| @@ -72,7 +71,6 @@ use modalkit::prelude::*; | |||
| 72 | 71 | ||
| 73 | use crate::base::{ | 72 | use crate::base::{ |
| 74 | DownloadFlags, | 73 | DownloadFlags, |
| 75 | EventLocation, | ||
| 76 | IambAction, | 74 | IambAction, |
| 77 | IambBufferId, | 75 | IambBufferId, |
| 78 | IambError, | 76 | IambError, |
| @@ -148,32 +146,10 @@ impl ChatState { | |||
| 148 | } | 146 | } |
| 149 | } | 147 | } |
| 150 | 148 | ||
| 151 | fn get_thread_last<'a>( | ||
| 152 | &self, | ||
| 153 | thread_root: &OwnedEventId, | ||
| 154 | info: &'a RoomInfo, | ||
| 155 | ) -> Option<&'a OriginalRoomMessageEvent> { | ||
| 156 | let last = info.threads.get(thread_root).and_then(|t| Some(t.last_key_value()?.1)); | ||
| 157 | |||
| 158 | let msg = if let Some(last) = last { | ||
| 159 | &last.event | ||
| 160 | } else if let EventLocation::Message(_, key) = info.keys.get(thread_root)? { | ||
| 161 | let msg = info.messages.get(key)?; | ||
| 162 | &msg.event | ||
| 163 | } else { | ||
| 164 | return None; | ||
| 165 | }; | ||
| 166 | |||
| 167 | if let MessageEvent::Original(ev) = &msg { | ||
| 168 | Some(ev) | ||
| 169 | } else { | ||
| 170 | None | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | fn get_reply_to<'a>(&self, info: &'a RoomInfo) -> Option<&'a OriginalRoomMessageEvent> { | 149 | fn get_reply_to<'a>(&self, info: &'a RoomInfo) -> Option<&'a OriginalRoomMessageEvent> { |
| 150 | let thread = self.scrollback.get_thread(info)?; | ||
| 175 | let key = self.reply_to.as_ref()?; | 151 | let key = self.reply_to.as_ref()?; |
| 176 | let msg = info.messages.get(key)?; | 152 | let msg = thread.get(key)?; |
| 177 | 153 | ||
| 178 | if let MessageEvent::Original(ev) = &msg.event { | 154 | if let MessageEvent::Original(ev) = &msg.event { |
| 179 | Some(ev) | 155 | Some(ev) |
| @@ -205,10 +181,7 @@ impl ChatState { | |||
| 205 | let settings = &store.application.settings; | 181 | let settings = &store.application.settings; |
| 206 | let info = store.application.rooms.get_or_default(self.room_id.clone()); | 182 | let info = store.application.rooms.get_or_default(self.room_id.clone()); |
| 207 | 183 | ||
| 208 | let msg = self | 184 | let msg = self.scrollback.get_mut(info).ok_or(IambError::NoSelectedMessage)?; |
| 209 | .scrollback | ||
| 210 | .get_mut(&mut info.messages) | ||
| 211 | .ok_or(IambError::NoSelectedMessage)?; | ||
| 212 | 185 | ||
| 213 | match act { | 186 | match act { |
| 214 | MessageAction::Cancel(skip_confirm) => { | 187 | MessageAction::Cancel(skip_confirm) => { |
| @@ -441,11 +414,11 @@ impl ChatState { | |||
| 441 | }, | 414 | }, |
| 442 | MessageAction::Unreact(emoji) => { | 415 | MessageAction::Unreact(emoji) => { |
| 443 | let room = self.get_joined(&store.application.worker)?; | 416 | let room = self.get_joined(&store.application.worker)?; |
| 444 | let event_id: &EventId = match &msg.event { | 417 | let event_id = match &msg.event { |
| 445 | MessageEvent::EncryptedOriginal(ev) => ev.event_id.as_ref(), | 418 | MessageEvent::EncryptedOriginal(ev) => ev.event_id.clone(), |
| 446 | MessageEvent::EncryptedRedacted(ev) => ev.event_id.as_ref(), | 419 | MessageEvent::EncryptedRedacted(ev) => ev.event_id.clone(), |
| 447 | MessageEvent::Original(ev) => ev.event_id.as_ref(), | 420 | MessageEvent::Original(ev) => ev.event_id.clone(), |
| 448 | MessageEvent::Local(event_id, _) => event_id.as_ref(), | 421 | MessageEvent::Local(event_id, _) => event_id.clone(), |
| 449 | MessageEvent::Redacted(_) => { | 422 | MessageEvent::Redacted(_) => { |
| 450 | let msg = "Cannot unreact to a redacted message"; | 423 | let msg = "Cannot unreact to a redacted message"; |
| 451 | let err = UIError::Failure(msg.into()); | 424 | let err = UIError::Failure(msg.into()); |
| @@ -454,7 +427,7 @@ impl ChatState { | |||
| 454 | }, | 427 | }, |
| 455 | }; | 428 | }; |
| 456 | 429 | ||
| 457 | let reactions = match info.reactions.get(event_id) { | 430 | let reactions = match info.reactions.get(&event_id) { |
| 458 | Some(r) => r, | 431 | Some(r) => r, |
| 459 | None => return Ok(None), | 432 | None => return Ok(None), |
| 460 | }; | 433 | }; |
| @@ -518,7 +491,7 @@ impl ChatState { | |||
| 518 | } else if let Some(thread_root) = self.scrollback.thread() { | 491 | } else if let Some(thread_root) = self.scrollback.thread() { |
| 519 | if let Some(m) = self.get_reply_to(info) { | 492 | if let Some(m) = self.get_reply_to(info) { |
| 520 | msg = msg.make_for_thread(m, ReplyWithinThread::Yes, AddMentions::No); | 493 | msg = msg.make_for_thread(m, ReplyWithinThread::Yes, AddMentions::No); |
| 521 | } else if let Some(m) = self.get_thread_last(thread_root, info) { | 494 | } else if let Some(m) = info.get_thread_last(thread_root) { |
| 522 | msg = msg.make_for_thread(m, ReplyWithinThread::No, AddMentions::No); | 495 | msg = msg.make_for_thread(m, ReplyWithinThread::No, AddMentions::No); |
| 523 | } else { | 496 | } else { |
| 524 | // Internal state is wonky? | 497 | // Internal state is wonky? |
| @@ -884,19 +857,21 @@ impl<'a> StatefulWidget for Chat<'a> { | |||
| 884 | 857 | ||
| 885 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { | 858 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { |
| 886 | // Determine whether we have a description to show for the message bar. | 859 | // Determine whether we have a description to show for the message bar. |
| 887 | let desc_spans = match (&state.editing, &state.reply_to) { | 860 | let desc_spans = match (&state.editing, &state.reply_to, state.thread()) { |
| 888 | (None, None) => None, | 861 | (None, None, None) => None, |
| 889 | (Some(_), None) => Some(Line::from("Editing message")), | 862 | (None, None, Some(_)) => Some(Line::from("Replying in thread")), |
| 890 | (editing, Some(_)) => { | 863 | (Some(_), None, None) => Some(Line::from("Editing message")), |
| 891 | state.reply_to.as_ref().and_then(|k| { | 864 | (Some(_), None, Some(_)) => Some(Line::from("Editing message in thread")), |
| 892 | let room = self.store.application.rooms.get(state.id())?; | 865 | (editing, Some(_), thread) => { |
| 893 | let msg = room.messages.get(k)?; | 866 | self.store.application.rooms.get(state.id()).and_then(|room| { |
| 867 | let msg = state.get_reply_to(room)?; | ||
| 894 | let user = | 868 | let user = |
| 895 | self.store.application.settings.get_user_span(msg.sender.as_ref(), room); | 869 | self.store.application.settings.get_user_span(msg.sender.as_ref(), room); |
| 896 | let prefix = if editing.is_some() { | 870 | let prefix = match (editing.is_some(), thread.is_some()) { |
| 897 | Span::from("Editing reply to ") | 871 | (true, false) => Span::from("Editing reply to "), |
| 898 | } else { | 872 | (true, true) => Span::from("Editing reply in thread to "), |
| 899 | Span::from("Replying to ") | 873 | (false, false) => Span::from("Replying to "), |
| 874 | (false, true) => Span::from("Replying in thread to "), | ||
| 900 | }; | 875 | }; |
| 901 | let spans = Line::from(vec![prefix, user]); | 876 | let spans = Line::from(vec![prefix, user]); |
| 902 | 877 | ||
src/windows/room/scrollback.rs +49 −55
| @@ -1,5 +1,4 @@ | |||
| 1 | //! Message scrollback | 1 | //! Message scrollback |
| 2 | |||
| 3 | use ratatui_image::Image; | 2 | use ratatui_image::Image; |
| 4 | use regex::Regex; | 3 | use regex::Regex; |
| 5 | 4 | ||
| @@ -59,6 +58,11 @@ use crate::{ | |||
| 59 | message::{Message, MessageCursor, MessageKey, Messages}, | 58 | message::{Message, MessageCursor, MessageKey, Messages}, |
| 60 | }; | 59 | }; |
| 61 | 60 | ||
| 61 | fn no_msgs() -> EditError<IambInfo> { | ||
| 62 | let msg = "No messages to select."; | ||
| 63 | EditError::Failure(msg.to_string()) | ||
| 64 | } | ||
| 65 | |||
| 62 | fn nth_key_before(pos: MessageKey, n: usize, thread: &Messages) -> MessageKey { | 66 | fn nth_key_before(pos: MessageKey, n: usize, thread: &Messages) -> MessageKey { |
| 63 | let mut end = &pos; | 67 | let mut end = &pos; |
| 64 | let iter = thread.range(..=&pos).rev().enumerate(); | 68 | let iter = thread.range(..=&pos).rev().enumerate(); |
| @@ -159,14 +163,16 @@ impl ScrollbackState { | |||
| 159 | self.cursor | 163 | self.cursor |
| 160 | .timestamp | 164 | .timestamp |
| 161 | .clone() | 165 | .clone() |
| 162 | .or_else(|| self.get_thread(info).last_key_value().map(|kv| kv.0.clone())) | 166 | .or_else(|| self.get_thread(info)?.last_key_value().map(|kv| kv.0.clone())) |
| 163 | } | 167 | } |
| 164 | 168 | ||
| 165 | pub fn get_mut<'a>(&mut self, messages: &'a mut Messages) -> Option<&'a mut Message> { | 169 | pub fn get_mut<'a>(&mut self, info: &'a mut RoomInfo) -> Option<&'a mut Message> { |
| 170 | let thread = self.get_thread_mut(info); | ||
| 171 | |||
| 166 | if let Some(k) = &self.cursor.timestamp { | 172 | if let Some(k) = &self.cursor.timestamp { |
| 167 | messages.get_mut(k) | 173 | thread.get_mut(k) |
| 168 | } else { | 174 | } else { |
| 169 | messages.last_entry().map(|o| o.into_mut()) | 175 | thread.last_entry().map(|o| o.into_mut()) |
| 170 | } | 176 | } |
| 171 | } | 177 | } |
| 172 | 178 | ||
| @@ -174,20 +180,12 @@ impl ScrollbackState { | |||
| 174 | self.thread.as_ref() | 180 | self.thread.as_ref() |
| 175 | } | 181 | } |
| 176 | 182 | ||
| 177 | pub fn get_thread<'a>(&self, info: &'a RoomInfo) -> &'a Messages { | 183 | pub fn get_thread<'a>(&self, info: &'a RoomInfo) -> Option<&'a Messages> { |
| 178 | if let Some(thread_root) = self.thread.as_ref() { | 184 | info.get_thread(self.thread.as_deref()) |
| 179 | info.threads.get(thread_root).unwrap_or(&info.messages) | ||
| 180 | } else { | ||
| 181 | &info.messages | ||
| 182 | } | ||
| 183 | } | 185 | } |
| 184 | 186 | ||
| 185 | pub fn get_thread_mut<'a>(&self, info: &'a mut RoomInfo) -> &'a mut Messages { | 187 | pub fn get_thread_mut<'a>(&self, info: &'a mut RoomInfo) -> &'a mut Messages { |
| 186 | if let Some(thread_root) = self.thread.as_ref() { | 188 | info.get_thread_mut(self.thread.clone()) |
| 187 | info.threads.get_mut(thread_root).unwrap_or(&mut info.messages) | ||
| 188 | } else { | ||
| 189 | &mut info.messages | ||
| 190 | } | ||
| 191 | } | 189 | } |
| 192 | 190 | ||
| 193 | pub fn messages<'a>( | 191 | pub fn messages<'a>( |
| @@ -195,7 +193,10 @@ impl ScrollbackState { | |||
| 195 | range: EditRange<MessageCursor>, | 193 | range: EditRange<MessageCursor>, |
| 196 | info: &'a RoomInfo, | 194 | info: &'a RoomInfo, |
| 197 | ) -> impl Iterator<Item = (&'a MessageKey, &'a Message)> { | 195 | ) -> impl Iterator<Item = (&'a MessageKey, &'a Message)> { |
| 198 | let thread = self.get_thread(info); | 196 | let Some(thread) = self.get_thread(info) else { |
| 197 | return Default::default(); | ||
| 198 | }; | ||
| 199 | |||
| 199 | let start = range.start.to_key(thread); | 200 | let start = range.start.to_key(thread); |
| 200 | let end = range.end.to_key(thread); | 201 | let end = range.end.to_key(thread); |
| 201 | 202 | ||
| @@ -223,7 +224,7 @@ impl ScrollbackState { | |||
| 223 | _ => {}, | 224 | _ => {}, |
| 224 | } | 225 | } |
| 225 | 226 | ||
| 226 | let first_key = self.get_thread(info).first_key_value().map(|(k, _)| k); | 227 | let first_key = self.get_thread(info).and_then(|t| t.first_key_value()).map(|(k, _)| k); |
| 227 | let at_top = first_key == self.viewctx.corner.timestamp.as_ref(); | 228 | let at_top = first_key == self.viewctx.corner.timestamp.as_ref(); |
| 228 | 229 | ||
| 229 | match (at_top, self.thread.as_ref()) { | 230 | match (at_top, self.thread.as_ref()) { |
| @@ -254,7 +255,10 @@ impl ScrollbackState { | |||
| 254 | info: &RoomInfo, | 255 | info: &RoomInfo, |
| 255 | settings: &ApplicationSettings, | 256 | settings: &ApplicationSettings, |
| 256 | ) { | 257 | ) { |
| 257 | let thread = self.get_thread(info); | 258 | let Some(thread) = self.get_thread(info) else { |
| 259 | return; | ||
| 260 | }; | ||
| 261 | |||
| 258 | let selidx = if let Some(key) = self.cursor.to_key(thread) { | 262 | let selidx = if let Some(key) = self.cursor.to_key(thread) { |
| 259 | key | 263 | key |
| 260 | } else { | 264 | } else { |
| @@ -319,7 +323,9 @@ impl ScrollbackState { | |||
| 319 | } | 323 | } |
| 320 | 324 | ||
| 321 | fn shift_cursor(&mut self, info: &RoomInfo, settings: &ApplicationSettings) { | 325 | fn shift_cursor(&mut self, info: &RoomInfo, settings: &ApplicationSettings) { |
| 322 | let thread = self.get_thread(info); | 326 | let Some(thread) = self.get_thread(info) else { |
| 327 | return; | ||
| 328 | }; | ||
| 323 | 329 | ||
| 324 | let last_key = if let Some(k) = thread.last_key_value() { | 330 | let last_key = if let Some(k) = thread.last_key_value() { |
| 325 | k.0 | 331 | k.0 |
| @@ -389,7 +395,7 @@ impl ScrollbackState { | |||
| 389 | MoveType::BufferLineOffset => None, | 395 | MoveType::BufferLineOffset => None, |
| 390 | MoveType::BufferLinePercent => None, | 396 | MoveType::BufferLinePercent => None, |
| 391 | MoveType::BufferPos(MovePosition::Beginning) => { | 397 | MoveType::BufferPos(MovePosition::Beginning) => { |
| 392 | let start = self.get_thread(info).first_key_value()?.0.clone(); | 398 | let start = self.get_thread(info)?.first_key_value()?.0.clone(); |
| 393 | 399 | ||
| 394 | Some(start.into()) | 400 | Some(start.into()) |
| 395 | }, | 401 | }, |
| @@ -402,7 +408,7 @@ impl ScrollbackState { | |||
| 402 | MoveType::ParagraphBegin(dir) | | 408 | MoveType::ParagraphBegin(dir) | |
| 403 | MoveType::SectionBegin(dir) | | 409 | MoveType::SectionBegin(dir) | |
| 404 | MoveType::SectionEnd(dir) => { | 410 | MoveType::SectionEnd(dir) => { |
| 405 | let thread = self.get_thread(info); | 411 | let thread = self.get_thread(info)?; |
| 406 | 412 | ||
| 407 | match dir { | 413 | match dir { |
| 408 | MoveDir1D::Previous => nth_before(pos, count, thread).into(), | 414 | MoveDir1D::Previous => nth_before(pos, count, thread).into(), |
| @@ -455,14 +461,14 @@ impl ScrollbackState { | |||
| 455 | RangeType::XmlTag => None, | 461 | RangeType::XmlTag => None, |
| 456 | 462 | ||
| 457 | RangeType::Buffer => { | 463 | RangeType::Buffer => { |
| 458 | let thread = self.get_thread(info); | 464 | let thread = self.get_thread(info)?; |
| 459 | let start = thread.first_key_value()?.0.clone(); | 465 | let start = thread.first_key_value()?.0.clone(); |
| 460 | let end = thread.last_key_value()?.0.clone(); | 466 | let end = thread.last_key_value()?.0.clone(); |
| 461 | 467 | ||
| 462 | Some(EditRange::inclusive(start.into(), end.into(), TargetShape::LineWise)) | 468 | Some(EditRange::inclusive(start.into(), end.into(), TargetShape::LineWise)) |
| 463 | }, | 469 | }, |
| 464 | RangeType::Line | RangeType::Paragraph | RangeType::Sentence => { | 470 | RangeType::Line | RangeType::Paragraph | RangeType::Sentence => { |
| 465 | let thread = self.get_thread(info); | 471 | let thread = self.get_thread(info)?; |
| 466 | let count = ctx.resolve(count); | 472 | let count = ctx.resolve(count); |
| 467 | 473 | ||
| 468 | if count == 0 { | 474 | if count == 0 { |
| @@ -496,7 +502,7 @@ impl ScrollbackState { | |||
| 496 | mut count: usize, | 502 | mut count: usize, |
| 497 | info: &RoomInfo, | 503 | info: &RoomInfo, |
| 498 | ) -> Option<MessageCursor> { | 504 | ) -> Option<MessageCursor> { |
| 499 | let thread = self.get_thread(info); | 505 | let thread = self.get_thread(info)?; |
| 500 | let mut mc = None; | 506 | let mut mc = None; |
| 501 | 507 | ||
| 502 | for (key, msg) in thread.range(&start..) { | 508 | for (key, msg) in thread.range(&start..) { |
| @@ -524,9 +530,12 @@ impl ScrollbackState { | |||
| 524 | mut count: usize, | 530 | mut count: usize, |
| 525 | info: &RoomInfo, | 531 | info: &RoomInfo, |
| 526 | ) -> (Option<MessageCursor>, bool) { | 532 | ) -> (Option<MessageCursor>, bool) { |
| 527 | let thread = self.get_thread(info); | ||
| 528 | let mut mc = None; | 533 | let mut mc = None; |
| 529 | 534 | ||
| 535 | let Some(thread) = self.get_thread(info) else { | ||
| 536 | return (None, false); | ||
| 537 | }; | ||
| 538 | |||
| 530 | for (key, msg) in thread.range(..&end).rev() { | 539 | for (key, msg) in thread.range(..&end).rev() { |
| 531 | if count == 0 { | 540 | if count == 0 { |
| 532 | break; | 541 | break; |
| @@ -614,14 +623,8 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 614 | store: &mut ProgramStore, | 623 | store: &mut ProgramStore, |
| 615 | ) -> EditResult<EditInfo, IambInfo> { | 624 | ) -> EditResult<EditInfo, IambInfo> { |
| 616 | let info = store.application.rooms.get_or_default(self.room_id.clone()); | 625 | let info = store.application.rooms.get_or_default(self.room_id.clone()); |
| 617 | let thread = self.get_thread(info); | 626 | let thread = self.get_thread(info).ok_or_else(no_msgs)?; |
| 618 | let key = if let Some(k) = self.cursor.to_key(thread) { | 627 | let key = self.cursor.to_key(thread).ok_or_else(no_msgs)?.clone(); |
| 619 | k.clone() | ||
| 620 | } else { | ||
| 621 | let msg = "No messages to select."; | ||
| 622 | let err = EditError::Failure(msg.to_string()); | ||
| 623 | return Err(err); | ||
| 624 | }; | ||
| 625 | 628 | ||
| 626 | match operation { | 629 | match operation { |
| 627 | EditAction::Motion => { | 630 | EditAction::Motion => { |
| @@ -644,7 +647,6 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 644 | EditTarget::CharJump(mark) | EditTarget::LineJump(mark) => { | 647 | EditTarget::CharJump(mark) | EditTarget::LineJump(mark) => { |
| 645 | let mark = ctx.resolve(mark); | 648 | let mark = ctx.resolve(mark); |
| 646 | let cursor = store.cursors.get_mark(self.id.clone(), mark)?; | 649 | let cursor = store.cursors.get_mark(self.id.clone(), mark)?; |
| 647 | let thread = self.get_thread(info); | ||
| 648 | 650 | ||
| 649 | if let Some(mc) = MessageCursor::from_cursor(&cursor, thread) { | 651 | if let Some(mc) = MessageCursor::from_cursor(&cursor, thread) { |
| 650 | Some(mc) | 652 | Some(mc) |
| @@ -723,7 +725,6 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 723 | EditTarget::CharJump(mark) | EditTarget::LineJump(mark) => { | 725 | EditTarget::CharJump(mark) | EditTarget::LineJump(mark) => { |
| 724 | let mark = ctx.resolve(mark); | 726 | let mark = ctx.resolve(mark); |
| 725 | let cursor = store.cursors.get_mark(self.id.clone(), mark)?; | 727 | let cursor = store.cursors.get_mark(self.id.clone(), mark)?; |
| 726 | let thread = self.get_thread(info); | ||
| 727 | 728 | ||
| 728 | if let Some(c) = MessageCursor::from_cursor(&cursor, thread) { | 729 | if let Some(c) = MessageCursor::from_cursor(&cursor, thread) { |
| 729 | self._range_to(c).into() | 730 | self._range_to(c).into() |
| @@ -821,18 +822,11 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 821 | store: &mut ProgramStore, | 822 | store: &mut ProgramStore, |
| 822 | ) -> EditResult<EditInfo, IambInfo> { | 823 | ) -> EditResult<EditInfo, IambInfo> { |
| 823 | let info = store.application.get_room_info(self.room_id.clone()); | 824 | let info = store.application.get_room_info(self.room_id.clone()); |
| 824 | let thread = self.get_thread(info); | 825 | let thread = self.get_thread(info).ok_or_else(no_msgs)?; |
| 825 | 826 | let cursor = self.cursor.to_cursor(thread).ok_or_else(no_msgs)?; | |
| 826 | if let Some(cursor) = self.cursor.to_cursor(thread) { | 827 | store.cursors.set_mark(self.id.clone(), name, cursor); |
| 827 | store.cursors.set_mark(self.id.clone(), name, cursor); | ||
| 828 | |||
| 829 | Ok(None) | ||
| 830 | } else { | ||
| 831 | let msg = "Failed to set mark for message"; | ||
| 832 | let err = EditError::Failure(msg.into()); | ||
| 833 | 828 | ||
| 834 | Err(err) | 829 | Ok(None) |
| 835 | } | ||
| 836 | } | 830 | } |
| 837 | 831 | ||
| 838 | fn complete( | 832 | fn complete( |
| @@ -884,6 +878,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 884 | store: &mut ProgramStore, | 878 | store: &mut ProgramStore, |
| 885 | ) -> EditResult<EditInfo, IambInfo> { | 879 | ) -> EditResult<EditInfo, IambInfo> { |
| 886 | let info = store.application.get_room_info(self.room_id.clone()); | 880 | let info = store.application.get_room_info(self.room_id.clone()); |
| 881 | let thread = self.get_thread(info).ok_or_else(no_msgs)?; | ||
| 887 | 882 | ||
| 888 | match act { | 883 | match act { |
| 889 | CursorAction::Close(_) => Ok(None), | 884 | CursorAction::Close(_) => Ok(None), |
| @@ -901,8 +896,6 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 901 | self.push_jump(); | 896 | self.push_jump(); |
| 902 | } | 897 | } |
| 903 | 898 | ||
| 904 | let thread = self.get_thread(info); | ||
| 905 | |||
| 906 | if let Some(mc) = MessageCursor::from_cursor(ngroup.leader.cursor(), thread) { | 899 | if let Some(mc) = MessageCursor::from_cursor(ngroup.leader.cursor(), thread) { |
| 907 | self.cursor = mc; | 900 | self.cursor = mc; |
| 908 | 901 | ||
| @@ -916,7 +909,6 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 916 | }, | 909 | }, |
| 917 | CursorAction::Save(_) => { | 910 | CursorAction::Save(_) => { |
| 918 | let reg = ctx.get_register().unwrap_or(Register::UnnamedCursorGroup); | 911 | let reg = ctx.get_register().unwrap_or(Register::UnnamedCursorGroup); |
| 919 | let thread = self.get_thread(info); | ||
| 920 | 912 | ||
| 921 | // Lists don't have groups; override any previously saved group. | 913 | // Lists don't have groups; override any previously saved group. |
| 922 | let cursor = self.cursor.to_cursor(thread).ok_or_else(|| { | 914 | let cursor = self.cursor.to_cursor(thread).ok_or_else(|| { |
| @@ -1019,7 +1011,7 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 1019 | store: &mut ProgramStore, | 1011 | store: &mut ProgramStore, |
| 1020 | ) -> EditResult<Vec<(Action<IambInfo>, ProgramContext)>, IambInfo> { | 1012 | ) -> EditResult<Vec<(Action<IambInfo>, ProgramContext)>, IambInfo> { |
| 1021 | let info = store.application.get_room_info(self.room_id.clone()); | 1013 | let info = store.application.get_room_info(self.room_id.clone()); |
| 1022 | let thread = self.get_thread(info); | 1014 | let thread = self.get_thread(info).ok_or_else(no_msgs)?; |
| 1023 | 1015 | ||
| 1024 | let Some(key) = self.cursor.to_key(thread) else { | 1016 | let Some(key) = self.cursor.to_key(thread) else { |
| 1025 | let msg = "No message currently selected"; | 1017 | let msg = "No message currently selected"; |
| @@ -1068,7 +1060,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 1068 | let info = store.application.rooms.get_or_default(self.room_id.clone()); | 1060 | let info = store.application.rooms.get_or_default(self.room_id.clone()); |
| 1069 | let settings = &store.application.settings; | 1061 | let settings = &store.application.settings; |
| 1070 | let mut corner = self.viewctx.corner.clone(); | 1062 | let mut corner = self.viewctx.corner.clone(); |
| 1071 | let thread = self.get_thread(info); | 1063 | let thread = self.get_thread(info).ok_or_else(no_msgs)?; |
| 1072 | 1064 | ||
| 1073 | let last_key = if let Some(k) = thread.last_key_value() { | 1065 | let last_key = if let Some(k) = thread.last_key_value() { |
| 1074 | k.0 | 1066 | k.0 |
| @@ -1182,7 +1174,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | |||
| 1182 | Axis::Vertical => { | 1174 | Axis::Vertical => { |
| 1183 | let info = store.application.rooms.get_or_default(self.room_id.clone()); | 1175 | let info = store.application.rooms.get_or_default(self.room_id.clone()); |
| 1184 | let settings = &store.application.settings; | 1176 | let settings = &store.application.settings; |
| 1185 | let thread = self.get_thread(info); | 1177 | let thread = self.get_thread(info).ok_or_else(no_msgs)?; |
| 1186 | 1178 | ||
| 1187 | if let Some(key) = self.cursor.to_key(thread).cloned() { | 1179 | if let Some(key) = self.cursor.to_key(thread).cloned() { |
| 1188 | self.scrollview(key, pos, info, settings); | 1180 | self.scrollview(key, pos, info, settings); |
| @@ -1315,12 +1307,14 @@ impl<'a> StatefulWidget for Scrollback<'a> { | |||
| 1315 | return; | 1307 | return; |
| 1316 | } | 1308 | } |
| 1317 | 1309 | ||
| 1310 | let Some(thread) = state.get_thread(info) else { | ||
| 1311 | return; | ||
| 1312 | }; | ||
| 1313 | |||
| 1318 | if state.cursor.timestamp < state.viewctx.corner.timestamp { | 1314 | if state.cursor.timestamp < state.viewctx.corner.timestamp { |
| 1319 | state.viewctx.corner = state.cursor.clone(); | 1315 | state.viewctx.corner = state.cursor.clone(); |
| 1320 | } | 1316 | } |
| 1321 | 1317 | ||
| 1322 | let thread = state.get_thread(info); | ||
| 1323 | |||
| 1324 | let cursor = &state.cursor; | 1318 | let cursor = &state.cursor; |
| 1325 | let cursor_key = if let Some(k) = cursor.to_key(thread) { | 1319 | let cursor_key = if let Some(k) = cursor.to_key(thread) { |
| 1326 | k | 1320 | k |
src/worker.rs +2 −31
| @@ -52,7 +52,7 @@ use matrix_sdk::{ | |||
| 52 | member::OriginalSyncRoomMemberEvent, | 52 | member::OriginalSyncRoomMemberEvent, |
| 53 | message::{MessageType, RoomMessageEventContent}, | 53 | message::{MessageType, RoomMessageEventContent}, |
| 54 | name::RoomNameEventContent, | 54 | name::RoomNameEventContent, |
| 55 | redaction::{OriginalSyncRoomRedactionEvent, SyncRoomRedactionEvent}, | 55 | redaction::OriginalSyncRoomRedactionEvent, |
| 56 | }, | 56 | }, |
| 57 | tag::Tags, | 57 | tag::Tags, |
| 58 | typing::SyncTypingEvent, | 58 | typing::SyncTypingEvent, |
| @@ -94,7 +94,6 @@ use crate::{ | |||
| 94 | ChatStore, | 94 | ChatStore, |
| 95 | CreateRoomFlags, | 95 | CreateRoomFlags, |
| 96 | CreateRoomType, | 96 | CreateRoomType, |
| 97 | EventLocation, | ||
| 98 | IambError, | 97 | IambError, |
| 99 | IambResult, | 98 | IambResult, |
| 100 | ProgramStore, | 99 | ProgramStore, |
| @@ -1063,35 +1062,7 @@ impl ClientWorker { | |||
| 1063 | 1062 | ||
| 1064 | let mut locked = store.lock().await; | 1063 | let mut locked = store.lock().await; |
| 1065 | let info = locked.application.get_room_info(room_id.to_owned()); | 1064 | let info = locked.application.get_room_info(room_id.to_owned()); |
| 1066 | 1065 | info.redact(ev, room_version); | |
| 1067 | let Some(redacts) = &ev.redacts else { | ||
| 1068 | return; | ||
| 1069 | }; | ||
| 1070 | |||
| 1071 | match info.keys.get(redacts) { | ||
| 1072 | None => return, | ||
| 1073 | Some(EventLocation::Message(None, key)) => { | ||
| 1074 | if let Some(msg) = info.messages.get_mut(key) { | ||
| 1075 | let ev = SyncRoomRedactionEvent::Original(ev); | ||
| 1076 | msg.redact(ev, room_version); | ||
| 1077 | } | ||
| 1078 | }, | ||
| 1079 | Some(EventLocation::Message(Some(root), key)) => { | ||
| 1080 | if let Some(thread) = info.threads.get_mut(root) { | ||
| 1081 | if let Some(msg) = thread.get_mut(key) { | ||
| 1082 | let ev = SyncRoomRedactionEvent::Original(ev); | ||
| 1083 | msg.redact(ev, room_version); | ||
| 1084 | } | ||
| 1085 | } | ||
| 1086 | }, | ||
| 1087 | Some(EventLocation::Reaction(event_id)) => { | ||
| 1088 | if let Some(reactions) = info.reactions.get_mut(event_id) { | ||
| 1089 | reactions.remove(redacts); | ||
| 1090 | } | ||
| 1091 | |||
| 1092 | info.keys.remove(redacts); | ||
| 1093 | }, | ||
| 1094 | } | ||
| 1095 | } | 1066 | } |
| 1096 | }, | 1067 | }, |
| 1097 | ); | 1068 | ); |