Skip to content

Commit 47a1f88

Browse files
committed
boxes: Add warning when sending message to announcement streams
Normal users are not allowed to send messages in announcement streams, currently when an unauthorised user sends message to this stream, nothing happens. This commit changes this behaviour and adds a footer warning for the same. Fixes: #682
1 parent 49d3fa5 commit 47a1f88

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

zulipterminal/ui_tools/boxes.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,43 @@ def private_box_view(self, button: Any=None, email: str='') -> None:
5858
self.focus_position = 1
5959

6060
def stream_box_view(self, caption: str='', title: str='') -> None:
61-
self.set_editor_mode()
62-
self.to_write_box = None
63-
self.msg_write_box = ReadlineEdit(multiline=True)
64-
self.msg_write_box.enable_autocomplete(
65-
func=self.generic_autocomplete,
66-
key=keys_for_command('AUTOCOMPLETE').pop(),
67-
key_reverse=keys_for_command('AUTOCOMPLETE_REVERSE').pop()
68-
)
69-
self.stream_write_box = ReadlineEdit(
70-
caption="Stream: ",
71-
edit_text=caption
72-
)
73-
self.title_write_box = ReadlineEdit(caption="Topic: ",
74-
edit_text=title)
75-
76-
header_write_box = urwid.Columns([
77-
urwid.LineBox(
78-
self.stream_write_box, tlcorner='─', tline='─', lline='',
79-
trcorner='┬', blcorner='─', rline='│',
80-
bline='─', brcorner='┴'
81-
),
82-
urwid.LineBox(
83-
self.title_write_box, tlcorner='─', tline='─', lline='',
84-
trcorner='─', blcorner='─', rline='',
85-
bline='─', brcorner='─'
86-
),
87-
])
88-
write_box = [
89-
(header_write_box, self.options()),
90-
(self.msg_write_box, self.options()),
91-
]
92-
self.contents = write_box
61+
if self.model.stream_dict[self.model.stream_id].get(
62+
'is_announcement_only', None) == 1:
63+
self.msg_footer = self.view.set_footer_text(
64+
"You are not authorised to send messages to this stream.", 5)
65+
else:
66+
self.set_editor_mode()
67+
self.to_write_box = None
68+
self.msg_write_box = ReadlineEdit(multiline=True)
69+
self.msg_write_box.enable_autocomplete(
70+
func=self.generic_autocomplete,
71+
key=keys_for_command('AUTOCOMPLETE').pop(),
72+
key_reverse=keys_for_command('AUTOCOMPLETE_REVERSE').pop()
73+
)
74+
self.stream_write_box = ReadlineEdit(
75+
caption="Stream: ",
76+
edit_text=caption
77+
)
78+
self.title_write_box = ReadlineEdit(caption="Topic: ",
79+
edit_text=title)
80+
81+
header_write_box = urwid.Columns([
82+
urwid.LineBox(
83+
self.stream_write_box, tlcorner='─', tline='─', lline='',
84+
trcorner='┬', blcorner='─', rline='│',
85+
bline='─', brcorner='┴'
86+
),
87+
urwid.LineBox(
88+
self.title_write_box, tlcorner='─', tline='─', lline='',
89+
trcorner='─', blcorner='─', rline='',
90+
bline='─', brcorner='─'
91+
),
92+
])
93+
write_box = [
94+
(header_write_box, self.options()),
95+
(self.msg_write_box, self.options()),
96+
]
97+
self.contents = write_box
9398

9499
def generic_autocomplete(self, text: str, state: int) -> Optional[str]:
95100
autocomplete_map = OrderedDict([

0 commit comments

Comments
 (0)