Unverified Commit fe249417 authored by mathieui's avatar mathieui

Remove display code from command_say

Use instead the message handler as if we received the message as carbons
parent b112748d
......@@ -103,9 +103,13 @@ class ConversationTab(OneToOneTab):
def completion(self):
self.complete_commands(self.input)
@refresh_wrapper.always
@command_args_parser.raw
def command_say(self, line, attention=False, correct=False):
msg = self.core.xmpp.make_message(self.get_dest_jid())
msg = self.core.xmpp.make_message(
mto=self.get_dest_jid(),
mfrom=self.core.xmpp.boundjid
)
msg['type'] = 'chat'
msg['body'] = line
if not self.nick_sent:
......@@ -117,24 +121,10 @@ class ConversationTab(OneToOneTab):
# be converted in xhtml.
self.core.events.trigger('conversation_say', msg, self)
if not msg['body']:
self.cancel_paused_delay()
self.text_win.refresh()
self.input.refresh()
return
replaced = False
if correct or msg['replace']['id']:
msg['replace']['id'] = self.last_sent_message['id']
if config.get_by_tabname('group_corrections', self.jid.full):
try:
self.modify_message(
msg['body'],
self.last_sent_message['id'],
msg['id'],
jid=self.core.xmpp.boundjid,
nickname=self.core.own_nick)
replaced = True
except CorrectionError:
log.error('Unable to correct a message', exc_info=True)
else:
del msg['replace']
if msg['body'].find('\x19') != -1:
......@@ -148,25 +138,12 @@ class ConversationTab(OneToOneTab):
msg['attention'] = True
self.core.events.trigger('conversation_say_after', msg, self)
if not msg['body']:
self.cancel_paused_delay()
self.text_win.refresh()
self.input.refresh()
return
if not replaced:
self.add_message(
msg['body'],
nickname=self.core.own_nick,
nick_color=get_theme().COLOR_OWN_NICK,
identifier=msg['id'],
jid=self.core.xmpp.boundjid,
typ=1)
self.last_sent_message = msg
self.core.handler.on_normal_message(msg)
msg._add_receipt = True
msg.send()
self.cancel_paused_delay()
self.text_win.refresh()
self.input.refresh()
@command_args_parser.quoted(0, 1)
def command_last_activity(self, args):
......
......@@ -144,12 +144,16 @@ class PrivateTab(OneToOneTab):
and not self.input.get_text().startswith('//'))
self.send_composing_chat_state(empty_after)
@refresh_wrapper.always
@command_args_parser.raw
def command_say(self, line, attention=False, correct=False):
if not self.on:
return
echo_message = self.jid.resource != self.own_nick
msg = self.core.xmpp.make_message(self.jid.full)
msg = self.core.xmpp.make_message(
mto=self.jid.full,
mfrom=self.core.xmpp.boundjid
)
msg['type'] = 'chat'
msg['body'] = line
# trigger the event BEFORE looking for colors.
......@@ -157,27 +161,11 @@ class PrivateTab(OneToOneTab):
# be converted in xhtml.
self.core.events.trigger('private_say', msg, self)
if not msg['body']:
self.cancel_paused_delay()
self.text_win.refresh()
self.input.refresh()
return
user = self.parent_muc.get_user_by_name(self.own_nick)
replaced = False
if correct or msg['replace']['id']:
msg['replace']['id'] = self.last_sent_message['id']
if (config.get_by_tabname('group_corrections', self.jid.full)
and echo_message):
try:
self.modify_message(
msg['body'],
self.last_sent_message['id'],
msg['id'],
user=user,
jid=self.core.xmpp.boundjid,
nickname=self.own_nick)
replaced = True
except:
log.error('Unable to correct a message', exc_info=True)
else:
del msg['replace']
......@@ -192,26 +180,12 @@ class PrivateTab(OneToOneTab):
msg['attention'] = True
self.core.events.trigger('private_say_after', msg, self)
if not msg['body']:
self.cancel_paused_delay()
self.text_win.refresh()
self.input.refresh()
return
if not replaced and echo_message:
self.add_message(
msg['body'],
nickname=self.own_nick or self.core.own_nick,
forced_user=user,
nick_color=get_theme().COLOR_OWN_NICK,
identifier=msg['id'],
jid=self.core.xmpp.boundjid,
typ=1)
self.last_sent_message = msg
self.core.handler.on_normal_message(msg)
msg._add_receipt = True
msg.send()
self.cancel_paused_delay()
self.text_win.refresh()
self.input.refresh()
@command_args_parser.quoted(0, 1)
def command_version(self, args):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment