Skip to content

Commit 6c60a48

Browse files
committed
helper: Show confirmation overlay before displaying any media.
Test amended.
1 parent d1c32a8 commit 6c60a48

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

tests/helper/test_helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,11 @@ def test_open_media(mocker, media_link, message_id, expected_path, platform,
322322
sys = mocker.patch('zulipterminal.helper.sys')
323323
sys.platform = platform
324324
open = mocker.patch('zulipterminal.helper.open')
325+
partial = mocker.patch('zulipterminal.helper.partial')
325326

326327
open_media(controller, media_link, message_id)
327328

328-
params = subprocess.run.call_args_list[0][0][0]
329+
params = partial.call_args_list[0][0][1]
329330
assert params[0] == expected_command
330331
assert params[1] == expected_path
332+
controller.show_confirmation_overlay.called

zulipterminal/helper.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import time
66
from collections import OrderedDict, defaultdict
7-
from functools import wraps
7+
from functools import partial, wraps
88
from itertools import chain, combinations
99
from re import ASCII, match
1010
from tempfile import gettempdir
@@ -16,6 +16,7 @@
1616

1717
import lxml.html
1818
import requests
19+
import urwid
1920
from mypy_extensions import TypedDict
2021

2122

@@ -665,4 +666,7 @@ def open_media(controller: Any, media_link: str, message_id: int) -> None:
665666
'darwin': 'open',
666667
}
667668
command = image_viewers[sys.platform]
668-
subprocess.run([command, img_path])
669+
callback = partial(subprocess.run, [command, img_path])
670+
question = urwid.Text("Your requested media has been downloaded."
671+
" Do you want to view it?")
672+
controller.show_confirmation_overlay(question, callback)

0 commit comments

Comments
 (0)