summaryrefslogtreecommitdiff
path: root/poezio/tabs/conversationtab.py
diff options
context:
space:
mode:
Diffstat (limited to 'poezio/tabs/conversationtab.py')
-rw-r--r--poezio/tabs/conversationtab.py45
1 files changed, 22 insertions, 23 deletions
diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py
index 9ddb6fc1..de1f988a 100644
--- a/poezio/tabs/conversationtab.py
+++ b/poezio/tabs/conversationtab.py
@@ -11,6 +11,7 @@ There are two different instances of a ConversationTab:
the time.
"""
+import asyncio
import curses
import logging
from datetime import datetime
@@ -21,7 +22,6 @@ from slixmpp import JID, InvalidJID, Message as SMessage
from poezio.tabs.basetabs import OneToOneTab, Tab
from poezio import common
-from poezio import tabs
from poezio import windows
from poezio import xhtml
from poezio.config import config, get_image_cache
@@ -83,8 +83,8 @@ class ConversationTab(OneToOneTab):
self.update_keys()
@property
- def general_jid(self):
- return self.jid.bare
+ def general_jid(self) -> JID:
+ return JID(self.jid.bare)
def get_info_header(self):
raise NotImplementedError
@@ -105,16 +105,25 @@ class ConversationTab(OneToOneTab):
def completion(self):
self.complete_commands(self.input)
- def handle_message(self, message: SMessage, display: bool = True):
+ async def handle_message(self, message: SMessage, display: bool = True):
"""Handle a received message.
The message can come from us (carbon copy).
"""
+
+ # Prevent messages coming from our own devices (1:1) to be reflected
+ if message['to'].bare == self.core.xmpp.boundjid.bare and \
+ message['from'].bare == self.core.xmpp.boundjid.bare:
+ _, index = self._text_buffer._find_message(message['id'])
+ if index != -1:
+ return
+
use_xhtml = config.get_by_tabname(
'enable_xhtml_im',
message['from'].bare
)
tmp_dir = get_image_cache()
+
# normal message, we are the recipient
if message['to'].bare == self.core.xmpp.boundjid.bare:
conv_jid = message['from']
@@ -132,7 +141,7 @@ class ConversationTab(OneToOneTab):
else:
return
- self.core.events.trigger('conversation_msg', message, self)
+ await self.core.events.trigger_async('conversation_msg', message, self)
if not message['body']:
return
@@ -172,7 +181,8 @@ class ConversationTab(OneToOneTab):
@refresh_wrapper.always
@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):
+ await self._initial_log.wait()
msg: SMessage = self.core.xmpp.make_message(
mto=self.get_dest_jid(),
mfrom=self.core.xmpp.boundjid
@@ -189,7 +199,6 @@ class ConversationTab(OneToOneTab):
self.core.events.trigger('conversation_say', msg, self)
if not msg['body']:
return
- replaced = False
if correct or msg['replace']['id']:
msg['replace']['id'] = self.last_sent_message['id'] # type: ignore
else:
@@ -209,10 +218,10 @@ class ConversationTab(OneToOneTab):
if not msg['body']:
return
self.set_last_sent_message(msg, correct=correct)
- self.core.handler.on_normal_message(msg)
- # Our receipts slixmpp hack
msg._add_receipt = True # type: ignore
msg.send()
+ await self.core.handler.on_normal_message(msg)
+ # Our receipts slixmpp hack
self.cancel_paused_delay()
@command_args_parser.quoted(0, 1)
@@ -277,16 +286,9 @@ class ConversationTab(OneToOneTab):
else:
resource = None
if resource:
- status = (
- 'Status: %s' % resource.status) if resource.status else ''
- self.add_message(
- InfoMessage(
- "Show: %(show)s, %(status)s" % {
- 'show': resource.presence or 'available',
- 'status': status,
- }
- ),
- )
+ status = (f', Status: {resource.status}') if resource.status else ''
+ show = f"Show: {resource.presence or 'available'}"
+ self.add_message(InfoMessage(f'{show}{status}'))
return True
self.add_message(
InfoMessage("No information available"),
@@ -436,9 +438,6 @@ class ConversationTab(OneToOneTab):
1, self.width, self.height - 2 - self.core.information_win_size -
Tab.tab_win_height(), 0)
- def get_text_window(self):
- return self.text_win
-
def on_close(self):
Tab.on_close(self)
if config.get_by_tabname('send_chat_states', self.general_jid):
@@ -543,7 +542,7 @@ class StaticConversationTab(ConversationTab):
self.update_commands()
self.update_keys()
- def init_logs(self, initial=None) -> None:
+ async def init_logs(self, initial=None) -> None:
# Disable local logs becauseā€¦
pass