diff options
Diffstat (limited to 'poezio/tabs/basetabs.py')
-rw-r--r-- | poezio/tabs/basetabs.py | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 508465e3..793eae62 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -170,15 +170,15 @@ class Tab: return 1 @property - def info_win(self): + def info_win(self) -> windows.TextWin: return self.core.information_win @property - def color(self): + def color(self) -> Union[Tuple[int, int], Tuple[int, int, 'str']]: return STATE_COLORS[self._state]() @property - def vertical_color(self): + def vertical_color(self) -> Union[Tuple[int, int], Tuple[int, int, 'str']]: return VERTICAL_STATE_COLORS[self._state]() @property @@ -351,7 +351,7 @@ class Tab: if hasattr(self.input, "reset_completion"): self.input.reset_completion() if asyncio.iscoroutinefunction(func): - asyncio.ensure_future(func(arg)) + asyncio.create_task(func(arg)) else: func(arg) return True @@ -390,12 +390,6 @@ class Tab: """ return self.name - def get_text_window(self) -> Optional[windows.TextWin]: - """ - Returns the principal TextWin window, if there's one - """ - return None - def on_input(self, key: str, raw: bool): """ raw indicates if the key should activate the associated command or not. @@ -498,7 +492,7 @@ class GapTab(Tab): return 0 @property - def name(self): + def name(self) -> str: return '' def refresh(self): @@ -520,6 +514,7 @@ class ChatTab(Tab): timed_event_paused: Optional[DelayedEvent] timed_event_not_paused: Optional[DelayedEvent] mam_filler: Optional[MAMFiller] + e2e_encryption: Optional[str] = None def __init__(self, core, jid: Union[JID, str]): Tab.__init__(self, core) @@ -675,7 +670,9 @@ class ChatTab(Tab): if not self.execute_command(txt): if txt.startswith('//'): txt = txt[1:] - self.command_say(xhtml.convert_simple_to_full_colors(txt)) + asyncio.ensure_future( + self.command_say(xhtml.convert_simple_to_full_colors(txt)) + ) self.cancel_paused_delay() @command_args_parser.raw @@ -800,7 +797,7 @@ class ChatTab(Tab): self.last_sent_message = msg @command_args_parser.raw - def command_correct(self, line: str) -> None: + async def command_correct(self, line: str) -> None: """ /correct <fixed message> """ @@ -810,7 +807,7 @@ class ChatTab(Tab): if not self.last_sent_message: self.core.information('There is no message to correct.', 'Error') return - self.command_say(line, correct=True) + await self.command_say(line, correct=True) def completion_correct(self, the_input): if self.last_sent_message and the_input.get_argument_position() == 1: @@ -844,7 +841,7 @@ class ChatTab(Tab): self.state = 'scrolled' @command_args_parser.raw - def command_say(self, line: str, attention: bool = False, correct: bool = False): + async def command_say(self, line: str, attention: bool = False, correct: bool = False): pass def goto_build_lines(self, new_date): @@ -979,7 +976,7 @@ class ChatTab(Tab): def on_scroll_up(self): if not self.query_status: from poezio.log_loader import LogLoader - asyncio.ensure_future( + asyncio.create_task( LogLoader(logger, self, config.getbool('use_log')).scroll_requested() ) return self.text_win.scroll_up(self.text_win.height - 1) @@ -1004,6 +1001,7 @@ class OneToOneTab(ChatTab): self.__status = Status("", "") self.last_remote_message = datetime.now() + self._initial_log = asyncio.Event() # Set to true once the first disco is done self.__initial_disco = False @@ -1018,9 +1016,9 @@ class OneToOneTab(ChatTab): shortdesc='Request the attention.', desc='Attention: Request the attention of the contact. Can also ' 'send a message along with the attention.') - self.init_logs(initial=initial) + asyncio.create_task(self.init_logs(initial=initial)) - def init_logs(self, initial=None) -> None: + async def init_logs(self, initial: Optional[SMessage] = None) -> None: use_log = config.get_by_tabname('use_log', self.jid) mam_sync = config.get_by_tabname('mam_sync', self.jid) if use_log and mam_sync: @@ -1031,19 +1029,16 @@ class OneToOneTab(ChatTab): if initial is not None: # If there is an initial message, throw it back into the # text buffer if it cannot be fetched from mam - async def fallback_no_mam(): - await mam_filler.done.wait() - if mam_filler.result == 0: - self.handle_message(initial) - - asyncio.ensure_future(fallback_no_mam()) + await mam_filler.done.wait() + if mam_filler.result == 0: + await self.handle_message(initial) elif use_log and initial: - self.handle_message(initial, display=False) - asyncio.ensure_future( - LogLoader(logger, self, use_log).tab_open() - ) + await self.handle_message(initial, display=False) + elif initial: + await self.handle_message(initial) + await LogLoader(logger, self, use_log, self._initial_log).tab_open() - def handle_message(self, msg: SMessage, display: bool = True): + async def handle_message(self, msg: SMessage, display: bool = True): pass def remote_user_color(self): @@ -1116,10 +1111,10 @@ class OneToOneTab(ChatTab): self.refresh() @command_args_parser.raw - def command_attention(self, message): + async def command_attention(self, message): """/attention [message]""" if message != '': - self.command_say(message, attention=True) + await self.command_say(message, attention=True) else: msg = self.core.xmpp.make_message(self.get_dest_jid()) msg['type'] = 'chat' @@ -1127,7 +1122,7 @@ class OneToOneTab(ChatTab): msg.send() @command_args_parser.raw - def command_say(self, line: str, attention: bool = False, correct: bool = False): + async def command_say(self, line: str, attention: bool = False, correct: bool = False): pass @command_args_parser.ignored |