src/windows/room/chat.rs
787 lines · 26120 bytes
1use std::borrow::Cow;
2use std::ffi::OsStr;
3use std::fs;
4use std::ops::Deref;
5use std::path::{Path, PathBuf};
6
7use tokio;
8
9use matrix_sdk::{
10 attachment::AttachmentConfig,
11 media::{MediaFormat, MediaRequest},
12 room::{Joined, Room as MatrixRoom},
13 ruma::{
14 events::reaction::{ReactionEventContent, Relation as Reaction},
15 events::room::message::{
16 MessageType,
17 OriginalRoomMessageEvent,
18 Relation,
19 Replacement,
20 RoomMessageEventContent,
21 TextMessageEventContent,
22 },
23 EventId,
24 OwnedRoomId,
25 RoomId,
26 },
27};
28
29use modalkit::{
30 input::dialog::PromptYesNo,
31 tui::{
32 buffer::Buffer,
33 layout::Rect,
34 text::{Span, Spans},
35 widgets::{Paragraph, StatefulWidget, Widget},
36 },
37 widgets::textbox::{TextBox, TextBoxState},
38 widgets::TerminalCursor,
39 widgets::{PromptActions, WindowOps},
40};
41
42use modalkit::editing::{
43 action::{
44 Action,
45 EditError,
46 EditInfo,
47 EditResult,
48 Editable,
49 EditorAction,
50 InfoMessage,
51 Jumpable,
52 PromptAction,
53 Promptable,
54 Scrollable,
55 UIError,
56 },
57 base::{CloseFlags, Count, MoveDir1D, PositionList, ScrollStyle, WordStyle, WriteFlags},
58 completion::CompletionList,
59 context::Resolve,
60 history::{self, HistoryList},
61 rope::EditRope,
62};
63
64use crate::base::{
65 DownloadFlags,
66 IambAction,
67 IambBufferId,
68 IambError,
69 IambInfo,
70 IambResult,
71 MessageAction,
72 ProgramAction,
73 ProgramContext,
74 ProgramStore,
75 RoomFocus,
76 RoomInfo,
77 SendAction,
78};
79
80use crate::message::{text_to_message, Message, MessageEvent, MessageKey, MessageTimeStamp};
81use crate::worker::Requester;
82
83use super::scrollback::{Scrollback, ScrollbackState};
84
85pub struct ChatState {
86 room_id: OwnedRoomId,
87 room: MatrixRoom,
88
89 tbox: TextBoxState<IambInfo>,
90 sent: HistoryList<EditRope>,
91 sent_scrollback: history::ScrollbackState,
92
93 scrollback: ScrollbackState,
94 focus: RoomFocus,
95
96 reply_to: Option<MessageKey>,
97 editing: Option<MessageKey>,
98}
99
100impl ChatState {
101 pub fn new(room: MatrixRoom, store: &mut ProgramStore) -> Self {
102 let room_id = room.room_id().to_owned();
103 let scrollback = ScrollbackState::new(room_id.clone());
104 let id = IambBufferId::Room(room_id.clone(), RoomFocus::MessageBar);
105 let ebuf = store.load_buffer(id);
106 let tbox = TextBoxState::new(ebuf);
107
108 ChatState {
109 room_id,
110 room,
111
112 tbox,
113 sent: HistoryList::new(EditRope::from(""), 100),
114 sent_scrollback: history::ScrollbackState::Pending,
115
116 scrollback,
117 focus: RoomFocus::MessageBar,
118
119 reply_to: None,
120 editing: None,
121 }
122 }
123
124 fn get_joined(&self, worker: &Requester) -> Result<Joined, IambError> {
125 worker.client.get_joined_room(self.id()).ok_or(IambError::NotJoined)
126 }
127
128 fn get_reply_to<'a>(&self, info: &'a RoomInfo) -> Option<&'a OriginalRoomMessageEvent> {
129 let key = self.reply_to.as_ref()?;
130 let msg = info.messages.get(key)?;
131
132 if let MessageEvent::Original(ev) = &msg.event {
133 Some(ev)
134 } else {
135 None
136 }
137 }
138
139 fn reset(&mut self) -> EditRope {
140 self.reply_to = None;
141 self.editing = None;
142 self.tbox.reset()
143 }
144
145 pub fn refresh_room(&mut self, store: &mut ProgramStore) {
146 if let Some(room) = store.application.worker.client.get_room(self.id()) {
147 self.room = room;
148 }
149 }
150
151 pub async fn message_command(
152 &mut self,
153 act: MessageAction,
154 _: ProgramContext,
155 store: &mut ProgramStore,
156 ) -> IambResult<EditInfo> {
157 let client = &store.application.worker.client;
158
159 let settings = &store.application.settings;
160 let info = store.application.rooms.get_or_default(self.room_id.clone());
161
162 let msg = self
163 .scrollback
164 .get_mut(&mut info.messages)
165 .ok_or(IambError::NoSelectedMessage)?;
166
167 match act {
168 MessageAction::Cancel => {
169 self.reply_to = None;
170 self.editing = None;
171
172 Ok(None)
173 },
174 MessageAction::Download(filename, flags) => {
175 if let MessageEvent::Original(ev) = &msg.event {
176 let media = client.media();
177
178 let mut filename = match filename {
179 Some(f) => PathBuf::from(f),
180 None => settings.dirs.downloads.clone(),
181 };
182
183 let (source, msg_filename) = match &ev.content.msgtype {
184 MessageType::Audio(c) => (c.source.clone(), c.body.as_str()),
185 MessageType::File(c) => {
186 (c.source.clone(), c.filename.as_deref().unwrap_or(c.body.as_str()))
187 },
188 MessageType::Image(c) => (c.source.clone(), c.body.as_str()),
189 MessageType::Video(c) => (c.source.clone(), c.body.as_str()),
190 _ => {
191 return Err(IambError::NoAttachment.into());
192 },
193 };
194
195 if filename.is_dir() {
196 filename.push(msg_filename);
197 }
198
199 if filename.exists() && !flags.contains(DownloadFlags::FORCE) {
200 // Find an incrementally suffixed filename, e.g. image-2.jpg -> image-3.jpg
201 if let Some(stem) = filename.file_stem().and_then(OsStr::to_str) {
202 let ext = filename.extension();
203 let mut filename_incr = filename.clone();
204 for n in 1..=1000 {
205 if let Some(ext) = ext.and_then(OsStr::to_str) {
206 filename_incr.set_file_name(format!("{}-{}.{}", stem, n, ext));
207 } else {
208 filename_incr.set_file_name(format!("{}-{}", stem, n));
209 }
210
211 if !filename_incr.exists() {
212 filename = filename_incr;
213 break;
214 }
215 }
216 }
217 }
218
219 if !filename.exists() || flags.contains(DownloadFlags::FORCE) {
220 let req = MediaRequest { source, format: MediaFormat::File };
221
222 let bytes =
223 media.get_media_content(&req, true).await.map_err(IambError::from)?;
224
225 fs::write(filename.as_path(), bytes.as_slice())?;
226
227 msg.downloaded = true;
228 } else if !flags.contains(DownloadFlags::OPEN) {
229 let msg = format!(
230 "The file {} already exists; add ! to end of command to overwrite it.",
231 filename.display()
232 );
233 let err = UIError::Failure(msg);
234
235 return Err(err);
236 }
237
238 let info = if flags.contains(DownloadFlags::OPEN) {
239 // open::that may not return until the spawned program closes.
240 let target = filename.clone().into_os_string();
241 tokio::task::spawn_blocking(move || open::that(target));
242
243 InfoMessage::from(format!(
244 "Attachment downloaded to {} and opened",
245 filename.display()
246 ))
247 } else {
248 InfoMessage::from(format!(
249 "Attachment downloaded to {}",
250 filename.display()
251 ))
252 };
253
254 return Ok(info.into());
255 }
256
257 Err(IambError::NoAttachment.into())
258 },
259 MessageAction::Edit => {
260 if msg.sender != settings.profile.user_id {
261 let msg = "Cannot edit messages sent by someone else";
262 let err = UIError::Failure(msg.into());
263
264 return Err(err);
265 }
266
267 let ev = match &msg.event {
268 MessageEvent::Original(ev) => &ev.content,
269 MessageEvent::Local(_, ev) => ev.deref(),
270 _ => {
271 let msg = "Cannot edit a redacted message";
272 let err = UIError::Failure(msg.into());
273
274 return Err(err);
275 },
276 };
277
278 let text = match &ev.msgtype {
279 MessageType::Text(msg) => msg.body.as_str(),
280 _ => {
281 let msg = "Cannot edit a non-text message";
282 let err = UIError::Failure(msg.into());
283
284 return Err(err);
285 },
286 };
287
288 self.tbox.set_text(text);
289 self.editing = self.scrollback.get_key(info);
290 self.focus = RoomFocus::MessageBar;
291
292 Ok(None)
293 },
294 MessageAction::React(emoji) => {
295 let room = self.get_joined(&store.application.worker)?;
296 let event_id = match &msg.event {
297 MessageEvent::EncryptedOriginal(ev) => ev.event_id.clone(),
298 MessageEvent::EncryptedRedacted(ev) => ev.event_id.clone(),
299 MessageEvent::Original(ev) => ev.event_id.clone(),
300 MessageEvent::Local(event_id, _) => event_id.clone(),
301 MessageEvent::Redacted(_) => {
302 let msg = "Cannot react to a redacted message";
303 let err = UIError::Failure(msg.into());
304
305 return Err(err);
306 },
307 };
308
309 let reaction = Reaction::new(event_id, emoji);
310 let msg = ReactionEventContent::new(reaction);
311 let _ = room.send(msg, None).await.map_err(IambError::from)?;
312
313 Ok(None)
314 },
315 MessageAction::Redact(reason, skip_confirm) => {
316 if !skip_confirm {
317 let msg = "Are you sure you want to redact this message?";
318 let act = IambAction::Message(MessageAction::Redact(reason, true));
319 let prompt = PromptYesNo::new(msg, vec![Action::from(act)]);
320 let prompt = Box::new(prompt);
321
322 return Err(UIError::NeedConfirm(prompt));
323 }
324
325 let room = self.get_joined(&store.application.worker)?;
326 let event_id = match &msg.event {
327 MessageEvent::EncryptedOriginal(ev) => ev.event_id.clone(),
328 MessageEvent::EncryptedRedacted(ev) => ev.event_id.clone(),
329 MessageEvent::Original(ev) => ev.event_id.clone(),
330 MessageEvent::Local(event_id, _) => event_id.clone(),
331 MessageEvent::Redacted(_) => {
332 let msg = "Cannot redact already redacted message";
333 let err = UIError::Failure(msg.into());
334
335 return Err(err);
336 },
337 };
338
339 let event_id = event_id.as_ref();
340 let reason = reason.as_deref();
341 let _ = room.redact(event_id, reason, None).await.map_err(IambError::from)?;
342
343 Ok(None)
344 },
345 MessageAction::Reply => {
346 self.reply_to = self.scrollback.get_key(info);
347 self.focus = RoomFocus::MessageBar;
348
349 Ok(None)
350 },
351 MessageAction::Unreact(emoji) => {
352 let room = self.get_joined(&store.application.worker)?;
353 let event_id: &EventId = match &msg.event {
354 MessageEvent::EncryptedOriginal(ev) => ev.event_id.as_ref(),
355 MessageEvent::EncryptedRedacted(ev) => ev.event_id.as_ref(),
356 MessageEvent::Original(ev) => ev.event_id.as_ref(),
357 MessageEvent::Local(event_id, _) => event_id.as_ref(),
358 MessageEvent::Redacted(_) => {
359 let msg = "Cannot unreact to a redacted message";
360 let err = UIError::Failure(msg.into());
361
362 return Err(err);
363 },
364 };
365
366 let reactions = match info.reactions.get(event_id) {
367 Some(r) => r,
368 None => return Ok(None),
369 };
370
371 let reactions = reactions.iter().filter_map(|(event_id, (reaction, user_id))| {
372 if user_id != &settings.profile.user_id {
373 return None;
374 }
375
376 if let Some(emoji) = &emoji {
377 if emoji == reaction {
378 return Some(event_id);
379 } else {
380 return None;
381 }
382 } else {
383 return Some(event_id);
384 }
385 });
386
387 for reaction in reactions {
388 let _ = room.redact(reaction, None, None).await.map_err(IambError::from)?;
389 }
390
391 Ok(None)
392 },
393 }
394 }
395
396 pub async fn send_command(
397 &mut self,
398 act: SendAction,
399 _: ProgramContext,
400 store: &mut ProgramStore,
401 ) -> IambResult<EditInfo> {
402 let room = store
403 .application
404 .worker
405 .client
406 .get_joined_room(self.id())
407 .ok_or(IambError::NotJoined)?;
408 let info = store.application.rooms.get_or_default(self.id().to_owned());
409 let mut show_echo = true;
410
411 let (event_id, msg) = match act {
412 SendAction::Submit => {
413 let msg = self.tbox.get();
414
415 if msg.is_blank() {
416 return Ok(None);
417 }
418
419 let mut msg = text_to_message(msg.to_string());
420
421 if let Some((_, event_id)) = &self.editing {
422 msg.relates_to = Some(Relation::Replacement(Replacement::new(
423 event_id.clone(),
424 Box::new(msg.clone()),
425 )));
426
427 show_echo = false;
428 } else if let Some(m) = self.get_reply_to(info) {
429 // XXX: Switch to RoomMessageEventContent::reply() once it's stable?
430 msg = msg.make_reply_to(m);
431 }
432
433 // XXX: second parameter can be a locally unique transaction id.
434 // Useful for doing retries.
435 let resp = room.send(msg.clone(), None).await.map_err(IambError::from)?;
436 let event_id = resp.event_id;
437
438 // Reset message bar state now that it's been sent.
439 self.reset();
440
441 (event_id, msg)
442 },
443 SendAction::Upload(file) => {
444 let path = Path::new(file.as_str());
445 let mime = mime_guess::from_path(path).first_or(mime::APPLICATION_OCTET_STREAM);
446
447 let bytes = fs::read(path)?;
448 let name = path
449 .file_name()
450 .map(OsStr::to_string_lossy)
451 .unwrap_or_else(|| Cow::from("Attachment"));
452 let config = AttachmentConfig::new();
453
454 let resp = room
455 .send_attachment(name.as_ref(), &mime, bytes.as_ref(), config)
456 .await
457 .map_err(IambError::from)?;
458
459 // Mock up the local echo message for the scrollback.
460 let msg = TextMessageEventContent::plain(format!("[Attached File: {name}]"));
461 let msg = MessageType::Text(msg);
462 let msg = RoomMessageEventContent::new(msg);
463
464 (resp.event_id, msg)
465 },
466 };
467
468 if show_echo {
469 let user = store.application.settings.profile.user_id.clone();
470 let key = (MessageTimeStamp::LocalEcho, event_id.clone());
471 let msg = MessageEvent::Local(event_id, msg.into());
472 let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho);
473 info.messages.insert(key, msg);
474 }
475
476 // Jump to the end of the scrollback to show the message.
477 self.scrollback.goto_latest();
478
479 Ok(None)
480 }
481
482 pub fn focus_toggle(&mut self) {
483 self.focus = match self.focus {
484 RoomFocus::Scrollback => RoomFocus::MessageBar,
485 RoomFocus::MessageBar => RoomFocus::Scrollback,
486 };
487 }
488
489 pub fn room(&self) -> &MatrixRoom {
490 &self.room
491 }
492
493 pub fn id(&self) -> &RoomId {
494 &self.room_id
495 }
496
497 pub fn typing_notice(
498 &self,
499 act: &EditorAction,
500 ctx: &ProgramContext,
501 store: &mut ProgramStore,
502 ) {
503 if !self.focus.is_msgbar() || act.is_readonly(ctx) {
504 return;
505 }
506
507 if !store.application.settings.tunables.typing_notice_send {
508 return;
509 }
510
511 store.application.worker.typing_notice(self.room_id.clone());
512 }
513}
514
515macro_rules! delegate {
516 ($s: expr, $id: ident => $e: expr) => {
517 match $s.focus {
518 RoomFocus::Scrollback => {
519 match $s {
520 ChatState { scrollback: $id, .. } => $e,
521 }
522 },
523 RoomFocus::MessageBar => {
524 match $s {
525 ChatState { tbox: $id, .. } => $e,
526 }
527 },
528 }
529 };
530}
531
532impl WindowOps<IambInfo> for ChatState {
533 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) {
534 Chat::new(store).focus(focused).render(area, buf, self)
535 }
536
537 fn dup(&self, store: &mut ProgramStore) -> Self {
538 // XXX: I want each WindowSlot to have its own shared buffer, instead of each Room; need to
539 // find a good way to pass that info here so that it can be part of the content id.
540 let id = IambBufferId::Room(self.room_id.clone(), RoomFocus::MessageBar);
541 let ebuf = store.load_buffer(id);
542 let tbox = TextBoxState::new(ebuf);
543
544 ChatState {
545 room_id: self.room_id.clone(),
546 room: self.room.clone(),
547
548 tbox,
549 sent: self.sent.clone(),
550 sent_scrollback: history::ScrollbackState::Pending,
551
552 scrollback: self.scrollback.dup(store),
553 focus: self.focus,
554
555 reply_to: None,
556 editing: None,
557 }
558 }
559
560 fn close(&mut self, _: CloseFlags, _: &mut ProgramStore) -> bool {
561 // XXX: what's the right closing behaviour for a room?
562 // Should write send a message?
563 true
564 }
565
566 fn write(
567 &mut self,
568 _: Option<&str>,
569 _: WriteFlags,
570 _: &mut ProgramStore,
571 ) -> IambResult<EditInfo> {
572 // XXX: what's the right writing behaviour for a room?
573 // Should write send a message?
574 Ok(None)
575 }
576
577 fn get_completions(&self) -> Option<CompletionList> {
578 delegate!(self, w => w.get_completions())
579 }
580
581 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
582 delegate!(self, w => w.get_cursor_word(style))
583 }
584
585 fn get_selected_word(&self) -> Option<String> {
586 delegate!(self, w => w.get_selected_word())
587 }
588}
589
590impl Editable<ProgramContext, ProgramStore, IambInfo> for ChatState {
591 fn editor_command(
592 &mut self,
593 act: &EditorAction,
594 ctx: &ProgramContext,
595 store: &mut ProgramStore,
596 ) -> EditResult<EditInfo, IambInfo> {
597 self.typing_notice(act, ctx, store);
598
599 match delegate!(self, w => w.editor_command(act, ctx, store)) {
600 res @ Ok(_) => res,
601 Err(EditError::WrongBuffer(IambBufferId::Room(room_id, focus)))
602 if room_id == self.room_id && act.is_switchable(ctx) =>
603 {
604 // Switch focus.
605 self.focus = focus;
606
607 // Run command again.
608 delegate!(self, w => w.editor_command(act, ctx, store))
609 },
610 res @ Err(_) => res,
611 }
612 }
613}
614
615impl TerminalCursor for ChatState {
616 fn get_term_cursor(&self) -> Option<(u16, u16)> {
617 delegate!(self, w => w.get_term_cursor())
618 }
619}
620
621impl Jumpable<ProgramContext, IambInfo> for ChatState {
622 fn jump(
623 &mut self,
624 list: PositionList,
625 dir: MoveDir1D,
626 count: usize,
627 ctx: &ProgramContext,
628 ) -> IambResult<usize> {
629 delegate!(self, w => w.jump(list, dir, count, ctx))
630 }
631}
632
633impl Scrollable<ProgramContext, ProgramStore, IambInfo> for ChatState {
634 fn scroll(
635 &mut self,
636 style: &ScrollStyle,
637 ctx: &ProgramContext,
638 store: &mut ProgramStore,
639 ) -> EditResult<EditInfo, IambInfo> {
640 // Send all scroll commands to the scrollback.
641 //
642 // If there's enough message text for scrolling to be necessary,
643 // navigating with movement keys should be enough to do the job.
644 self.scrollback.scroll(style, ctx, store)
645 }
646}
647
648impl PromptActions<ProgramContext, ProgramStore, IambInfo> for ChatState {
649 fn submit(
650 &mut self,
651 ctx: &ProgramContext,
652 _: &mut ProgramStore,
653 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
654 let act = SendAction::Submit;
655
656 Ok(vec![(IambAction::from(act).into(), ctx.clone())])
657 }
658
659 fn abort(
660 &mut self,
661 empty: bool,
662 _: &ProgramContext,
663 _: &mut ProgramStore,
664 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
665 let text = self.tbox.get();
666
667 if empty && text.is_blank() {
668 return Ok(vec![]);
669 }
670
671 let text = self.reset().trim();
672
673 if text.is_empty() {
674 let _ = self.sent.end();
675 } else {
676 self.sent.select(text);
677 }
678
679 return Ok(vec![]);
680 }
681
682 fn recall(
683 &mut self,
684 dir: &MoveDir1D,
685 count: &Count,
686 prefixed: bool,
687 ctx: &ProgramContext,
688 _: &mut ProgramStore,
689 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
690 let count = ctx.resolve(count);
691 let rope = self.tbox.get();
692
693 let text = self.sent.recall(&rope, &mut self.sent_scrollback, *dir, prefixed, count);
694
695 if let Some(text) = text {
696 self.tbox.set_text(text);
697 }
698
699 Ok(vec![])
700 }
701}
702
703impl Promptable<ProgramContext, ProgramStore, IambInfo> for ChatState {
704 fn prompt(
705 &mut self,
706 act: &PromptAction,
707 ctx: &ProgramContext,
708 store: &mut ProgramStore,
709 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
710 if let RoomFocus::Scrollback = self.focus {
711 return Ok(vec![]);
712 }
713
714 match act {
715 PromptAction::Submit => self.submit(ctx, store),
716 PromptAction::Abort(empty) => self.abort(*empty, ctx, store),
717 PromptAction::Recall(dir, count, prefixed) => {
718 self.recall(dir, count, *prefixed, ctx, store)
719 },
720 _ => Err(EditError::Unimplemented("unknown prompt action".to_string())),
721 }
722 }
723}
724
725pub struct Chat<'a> {
726 store: &'a mut ProgramStore,
727 focused: bool,
728}
729
730impl<'a> Chat<'a> {
731 pub fn new(store: &'a mut ProgramStore) -> Chat<'a> {
732 Chat { store, focused: false }
733 }
734
735 pub fn focus(mut self, focused: bool) -> Self {
736 self.focused = focused;
737 self
738 }
739}
740
741impl<'a> StatefulWidget for Chat<'a> {
742 type State = ChatState;
743
744 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
745 let lines = state.tbox.has_lines(5).max(1) as u16;
746 let drawh = area.height;
747 let texth = lines.min(drawh).clamp(1, 5);
748 let desch = if state.reply_to.is_some() {
749 drawh.saturating_sub(texth).min(1)
750 } else {
751 0
752 };
753 let scrollh = drawh.saturating_sub(texth).saturating_sub(desch);
754
755 let scrollarea = Rect::new(area.x, area.y, area.width, scrollh);
756 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);
758
759 let scrollback_focused = state.focus.is_scrollback() && self.focused;
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 {
779 Paragraph::new(desc_spans).render(descarea, buf);
780 }
781
782 let prompt = if self.focused { "> " } else { " " };
783
784 let tbox = TextBox::new().prompt(prompt);
785 tbox.render(textarea, buf, &mut state.tbox);
786 }
787}