Skip to content

Commit daf0ffe

Browse files
committed
helper: Show confirmation overlay before displaying any media.
Test amended.
1 parent 2ea16d0 commit daf0ffe

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
@@ -324,9 +324,11 @@ def test_open_media(mocker, media_link, message_id, expected_path, platform,
324324
sys = mocker.patch('zulipterminal.helper.sys')
325325
sys.platform = platform
326326
open = mocker.patch('zulipterminal.helper.open')
327+
partial = mocker.patch('zulipterminal.helper.partial')
327328

328329
open_media(controller, media_link, message_id)
329330

330-
params = subprocess.run.call_args_list[0][0][0]
331+
params = partial.call_args_list[0][0][1]
331332
assert params[0] == expected_command
332333
assert params[1] == expected_path
334+
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)