| @@ -165,11 +165,20 @@ impl ChatState { |
| 165 | .ok_or(IambError::NoSelectedMessage)?; |
165 | .ok_or(IambError::NoSelectedMessage)?; |
| 166 | |
166 | |
| 167 | match act { |
167 | match act { |
| 168 | MessageAction::Cancel => { |
168 | MessageAction::Cancel(skip_confirm) => { |
| 169 | self.reply_to = None; |
169 | self.reply_to = None; |
| 170 | self.editing = None; |
170 | self.editing = None; |
| 171 | |
171 | |
| 172 | Ok(None) |
172 | if skip_confirm { |
| |
173 | return Ok(None); |
| |
174 | } |
| |
175 | |
| |
176 | let msg = "Would you like to clear the message bar?"; |
| |
177 | let act = PromptAction::Abort(false); |
| |
178 | let prompt = PromptYesNo::new(msg, vec![Action::from(act)]); |
| |
179 | let prompt = Box::new(prompt); |
| |
180 | |
| |
181 | Err(UIError::NeedConfirm(prompt)) |
| 173 | }, |
182 | }, |
| 174 | MessageAction::Download(filename, flags) => { |
183 | MessageAction::Download(filename, flags) => { |
| 175 | if let MessageEvent::Original(ev) = &msg.event { |
184 | if let MessageEvent::Original(ev) = &msg.event { |
| @@ -286,6 +295,7 @@ impl ChatState { |
| 286 | }; |
295 | }; |
| 287 | |
296 | |
| 288 | self.tbox.set_text(text); |
297 | self.tbox.set_text(text); |
| |
298 | self.reply_to = msg.reply_to().and_then(|id| info.get_message_key(&id)).cloned(); |
| 289 | self.editing = self.scrollback.get_key(info); |
299 | self.editing = self.scrollback.get_key(info); |
| 290 | self.focus = RoomFocus::MessageBar; |
300 | self.focus = RoomFocus::MessageBar; |
| 291 | |
301 | |
| @@ -742,10 +752,32 @@ impl<'a> StatefulWidget for Chat<'a> { |
| 742 | type State = ChatState; |
752 | type State = ChatState; |
| 743 | |
753 | |
| 744 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { |
754 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { |
| |
755 | // Determine whether we have a description to show for the message bar. |
| |
756 | let desc_spans = match (&state.editing, &state.reply_to) { |
| |
757 | (None, None) => None, |
| |
758 | (Some(_), None) => Some(Spans::from("Editing message")), |
| |
759 | (editing, Some(_)) => { |
| |
760 | state.reply_to.as_ref().and_then(|k| { |
| |
761 | let room = self.store.application.rooms.get(state.id())?; |
| |
762 | let msg = room.messages.get(k)?; |
| |
763 | let user = self.store.application.settings.get_user_span(msg.sender.as_ref()); |
| |
764 | let prefix = if editing.is_some() { |
| |
765 | Span::from("Editing reply to ") |
| |
766 | } else { |
| |
767 | Span::from("Replying to ") |
| |
768 | }; |
| |
769 | let spans = Spans(vec![prefix, user]); |
| |
770 | |
| |
771 | spans.into() |
| |
772 | }) |
| |
773 | }, |
| |
774 | }; |
| |
775 | |
| |
776 | // Determine the region to show each UI element. |
| 745 | let lines = state.tbox.has_lines(5).max(1) as u16; |
777 | let lines = state.tbox.has_lines(5).max(1) as u16; |
| 746 | let drawh = area.height; |
778 | let drawh = area.height; |
| 747 | let texth = lines.min(drawh).clamp(1, 5); |
779 | let texth = lines.min(drawh).clamp(1, 5); |
| 748 | let desch = if state.reply_to.is_some() { |
780 | let desch = if desc_spans.is_some() { |
| 749 | drawh.saturating_sub(texth).min(1) |
781 | drawh.saturating_sub(texth).min(1) |
| 750 | } else { |
782 | } else { |
| 751 | 0 |
783 | 0 |
| @@ -756,25 +788,7 @@ impl<'a> StatefulWidget for Chat<'a> { |
| 756 | let descarea = Rect::new(area.x, scrollarea.y + scrollh, area.width, desch); |
788 | let descarea = Rect::new(area.x, scrollarea.y + scrollh, area.width, desch); |
| 757 | let textarea = Rect::new(area.x, descarea.y + desch, area.width, texth); |
789 | let textarea = Rect::new(area.x, descarea.y + desch, area.width, texth); |
| 758 | |
790 | |
| 759 | let scrollback_focused = state.focus.is_scrollback() && self.focused; |
791 | // Render the message bar and any description for it. |
| 760 | let scrollback = Scrollback::new(self.store).focus(scrollback_focused); |
| |
| 761 | scrollback.render(scrollarea, buf, &mut state.scrollback); |
| |
| 762 | |
| |
| 763 | let desc_spans = match (&state.editing, &state.reply_to) { |
| |
| 764 | (None, None) => None, |
| |
| 765 | (Some(_), _) => Some(Spans::from("Editing message")), |
| |
| 766 | (_, Some(_)) => { |
| |
| 767 | state.reply_to.as_ref().and_then(|k| { |
| |
| 768 | let room = self.store.application.rooms.get(state.id())?; |
| |
| 769 | let msg = room.messages.get(k)?; |
| |
| 770 | let user = self.store.application.settings.get_user_span(msg.sender.as_ref()); |
| |
| 771 | let spans = Spans(vec![Span::from("Replying to "), user]); |
| |
| 772 | |
| |
| 773 | spans.into() |
| |
| 774 | }) |
| |
| 775 | }, |
| |
| 776 | }; |
| |
| 777 | |
| |
| 778 | if let Some(desc_spans) = desc_spans { |
792 | if let Some(desc_spans) = desc_spans { |
| 779 | Paragraph::new(desc_spans).render(descarea, buf); |
793 | Paragraph::new(desc_spans).render(descarea, buf); |
| 780 | } |
794 | } |
| @@ -783,5 +797,10 @@ impl<'a> StatefulWidget for Chat<'a> { |
| 783 | |
797 | |
| 784 | let tbox = TextBox::new().prompt(prompt); |
798 | let tbox = TextBox::new().prompt(prompt); |
| 785 | tbox.render(textarea, buf, &mut state.tbox); |
799 | tbox.render(textarea, buf, &mut state.tbox); |
| |
800 | |
| |
801 | // Render the message scrollback. |
| |
802 | let scrollback_focused = state.focus.is_scrollback() && self.focused; |
| |
803 | let scrollback = Scrollback::new(self.store).focus(scrollback_focused); |
| |
804 | scrollback.render(scrollarea, buf, &mut state.scrollback); |
| 786 | } |
805 | } |
| 787 | } |
806 | } |