@@ -117,13 +117,14 @@ def keypress(self, size: Tuple[int, int], key: str) -> str:
117
117
118
118
class MessageBox (urwid .Pile ):
119
119
def __init__ (self , message : Dict [str , Any ], model : Any ,
120
- last_message : Any ) -> None :
120
+ last_message : Any , is_empty_narrow : bool = False ) -> None :
121
121
self .model = model
122
122
self .message = message
123
123
self .caption = ''
124
124
self .stream_id = None # type: Union[int, None]
125
125
self .title = ''
126
126
self .email = ''
127
+ self .is_in_empty_narrow = is_empty_narrow
127
128
self .user_id = None # type: Union[int, None]
128
129
self .last_message = last_message
129
130
# if this is the first message
@@ -146,6 +147,8 @@ def _time_for_message(self, message: Dict[str, Any]) -> str:
146
147
return ctime (message ['timestamp' ])[:- 8 ]
147
148
148
149
def need_recipient_header (self ) -> bool :
150
+ if self .is_in_empty_narrow :
151
+ return True
149
152
last_msg = self .last_message
150
153
if self .message ['type' ] == 'stream' :
151
154
if (last_msg ['type' ] == 'stream' and
@@ -167,6 +170,15 @@ def need_recipient_header(self) -> bool:
167
170
else :
168
171
raise RuntimeError ("Invalid message type" )
169
172
173
+ def _check_if_self_PM (self ) -> bool :
174
+ recipient_list = self .message ['display_recipient' ]
175
+ if len (recipient_list ) == 1 and \
176
+ recipient_list [0 ]['email' ] == \
177
+ self .model .user_email :
178
+ return True
179
+ else :
180
+ return False
181
+
170
182
def stream_header (self ) -> Any :
171
183
bar_color = self .model .stream_dict [self .stream_id ]['color' ]
172
184
bar_color = 's' + bar_color [:2 ] + bar_color [3 ] + bar_color [5 ]
@@ -180,11 +192,14 @@ def stream_header(self) -> Any:
180
192
return header
181
193
182
194
def private_header (self ) -> Any :
183
- self .recipients = ', ' .join (list (
184
- recipient ['full_name' ]
185
- for recipient in self .message ['display_recipient' ]
186
- if recipient ['email' ] != self .model .user_email
187
- ))
195
+ if self ._check_if_self_PM ():
196
+ self .recipients = self .message ['display_recipient' ][0 ]['full_name' ]
197
+ else :
198
+ self .recipients = ', ' .join (list (
199
+ recipient ['full_name' ]
200
+ for recipient in self .message ['display_recipient' ]
201
+ if recipient ['email' ] != self .model .user_email
202
+ ))
188
203
title_markup = ('header' , [
189
204
('custom' , 'Private Messages with' ),
190
205
('selected' , ": " ),
@@ -419,11 +434,14 @@ def mouse_event(self, size: Tuple[int, int], event: Any, button: Any,
419
434
420
435
def get_recipients (self ) -> str :
421
436
emails = []
422
- for recipient in self .message ['display_recipient' ]:
423
- email = recipient ['email' ]
424
- if email == self .model .user_email :
425
- continue
426
- emails .append (recipient ['email' ])
437
+ if self ._check_if_self_PM ():
438
+ emails .append (self .model .user_email )
439
+ else :
440
+ for recipient in self .message ['display_recipient' ]:
441
+ email = recipient ['email' ]
442
+ if email == self .model .user_email :
443
+ continue
444
+ emails .append (recipient ['email' ])
427
445
return ', ' .join (emails )
428
446
429
447
def keypress (self , size : Tuple [int , int ], key : str ) -> str :
@@ -458,19 +476,22 @@ def keypress(self, size: Tuple[int, int], key: str) -> str:
458
476
self .model .controller .narrow_to_topic (self )
459
477
elif is_command_key ('GO_BACK' , key ):
460
478
self .model .controller .show_all_messages (self )
461
- elif is_command_key ('REPLY_AUTHOR' , key ):
479
+ elif is_command_key ('REPLY_AUTHOR' , key ) and \
480
+ not self .is_in_empty_narrow :
462
481
self .model .controller .view .write_box .private_box_view (
463
482
email = self .message ['sender_email' ]
464
483
)
465
- elif is_command_key ('MENTION_REPLY' , key ):
484
+ elif is_command_key ('MENTION_REPLY' , key ) and \
485
+ not self .is_in_empty_narrow :
466
486
self .keypress (size , 'enter' )
467
487
mention = '@**' + self .message ['sender_full_name' ] + '** '
468
488
self .model .controller .view .write_box .msg_write_box .set_edit_text (
469
489
mention )
470
490
self .model .controller .view .write_box .msg_write_box .set_edit_pos (
471
491
len (mention ))
472
492
self .model .controller .view .middle_column .set_focus ('footer' )
473
- elif is_command_key ('QUOTE_REPLY' , key ):
493
+ elif is_command_key ('QUOTE_REPLY' , key ) and \
494
+ not self .is_in_empty_narrow :
474
495
self .keypress (size , 'enter' )
475
496
quote = '```quote\n ' + self .message ['content' ] + '\n ```\n '
476
497
self .model .controller .view .write_box .msg_write_box .set_edit_text (
0 commit comments