Commit adef78c5 authored by Philipp Hörist's avatar Philipp Hörist

Use contact instead of jid for OutgoingMessage

parent 011ed972
......@@ -923,8 +923,7 @@ class ChatControl(ChatControlBase):
message,
xhtml=None,
process_commands=True,
attention=False,
is_muc_pm=False):
attention=False):
"""
Send a message to contact
"""
......@@ -945,8 +944,7 @@ class ChatControl(ChatControlBase):
type_='chat',
xhtml=xhtml,
process_commands=process_commands,
attention=attention,
is_muc_pm=is_muc_pm)
attention=attention)
def get_our_nick(self):
return app.nicks[self.account]
......
......@@ -981,8 +981,7 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper):
resource=None,
xhtml=None,
process_commands=True,
attention=False,
is_muc_pm=False):
attention=False):
"""
Send the given message to the active tab. Doesn't return None if error
"""
......@@ -1004,10 +1003,9 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper):
self.contact)
message_ = OutgoingMessage(account=self.account,
jid=self.contact.jid,
contact=self.contact,
message=message,
type_=type_,
is_muc_pm=is_muc_pm,
chatstate=chatstate,
resource=resource,
user_nick=self.user_nick,
......
......@@ -1353,7 +1353,8 @@ class Connection(CommonConnection, ConnectionHandlers):
message.set_sent_timestamp()
message.message_id = self.connection.send(message.stanza)
app.nec.push_incoming_event(MessageSentEvent(None, **vars(message)))
app.nec.push_incoming_event(
MessageSentEvent(None, jid=message.jid, **vars(message)))
if message.is_groupchat:
return
......@@ -1367,7 +1368,7 @@ class Connection(CommonConnection, ConnectionHandlers):
for jid in jids:
message = message.copy()
message.jid = jid
message.contact = app.contacts.create_contact(jid, message.account)
stanza = self.get_module('Message').build_message_stanza(message)
message.stanza = stanza
self._send_message(message)
......
......@@ -313,7 +313,7 @@ class Chatstate(BaseModule):
def _send_chatstate(self, contact, chatstate):
type_ = 'groupchat' if contact.is_groupchat else 'chat'
message = OutgoingMessage(account=self._account,
jid=contact.jid,
contact=contact,
message=None,
type_=type_,
chatstate=chatstate)
......
......@@ -241,7 +241,7 @@ class HTTPUpload(BaseModule):
type_ = 'groupchat'
message = OutgoingMessage(account=self._account,
jid=transfer.contact.jid,
contact=transfer.contact,
message=uri,
type_=type_,
oob_url=uri)
......
......@@ -331,7 +331,7 @@ class Message(BaseModule):
stanza.setReceiptRequest()
# Mark Message as MUC PM
if message.is_muc_pm:
if message.contact.is_pm_contact:
stanza.setTag('x', namespace=nbxmpp.NS_MUC_USER)
# XEP-0085
......
......@@ -17,7 +17,6 @@ from collections import namedtuple
from nbxmpp.protocol import JID
from gajim.common import app
from gajim.common.const import MUCJoinedState
from gajim.common.const import KindConstant
......@@ -56,11 +55,10 @@ class MUCData:
class OutgoingMessage:
def __init__(self,
account,
jid,
contact,
message,
type_,
subject=None,
is_muc_pm=False,
chatstate=None,
resource=None,
user_nick=None,
......@@ -79,7 +77,7 @@ class OutgoingMessage:
raise ValueError('Trying to send message without content')
self.account = account
self.jid = jid
self.contact = contact
self.message = message
self.type_ = type_
......@@ -96,7 +94,6 @@ class OutgoingMessage:
self.additional_data = AdditionalDataDict()
self.subject = subject
self.is_muc_pm = is_muc_pm
self.chatstate = chatstate
self.resource = resource
self.user_nick = user_nick
......@@ -126,7 +123,7 @@ class OutgoingMessage:
def copy(self):
message = OutgoingMessage(self.account,
self.jid,
self.contact,
self.message,
self.type_)
for name, value in vars(self).items():
......@@ -134,6 +131,10 @@ class OutgoingMessage:
message.additional_data = self.additional_data.copy()
return message
@property
def jid(self):
return self.contact.jid
@property
def is_groupchat(self):
return self.type_ == 'groupchat'
......
......@@ -1586,7 +1586,7 @@ class GroupchatControl(ChatControlBase):
# Send the message
message_ = OutgoingMessage(account=self.account,
jid=self.room_jid,
contact=self.contact,
message=message,
type_='groupchat',
label=label,
......
......@@ -251,7 +251,7 @@ class SingleMessageWindow(Gtk.ApplicationWindow):
recipient_list.append(to_whom_jid)
message = OutgoingMessage(account=self.account,
jid=None,
contact=None,
message=message,
type_='normal',
subject=subject)
......
......@@ -206,8 +206,7 @@ class PrivateChatControl(ChatControl):
ChatControl.send_message(self, message,
xhtml=xhtml,
process_commands=process_commands,
attention=attention,
is_muc_pm=True)
attention=attention)
def update_ui(self):
if self.gc_contact.presence.is_unavailable:
......
......@@ -509,25 +509,24 @@ class GajimRemote(Server):
if not jid or not message:
return False
connected_account = self._get_account_and_contact(account, jid)[0]
if connected_account:
connection = app.connections[connected_account]
sessions = connection.get_sessions(jid)
if not sessions:
connection.make_new_session(jid)
ctrl = app.interface.msg_win_mgr.search_control(
jid, connected_account)
if ctrl:
ctrl.send_message(message)
else:
message_ = OutgoingMessage(account=connected_account,
jid=jid,
message=message,
type_=type_,
control=ctrl)
connection.send_message(message_)
return True
return False
connected_account, contact = self._get_account_and_contact(account, jid)
if not connected_account or contact is None:
return False
connection = app.connections[connected_account]
ctrl = app.interface.msg_win_mgr.search_control(
jid, connected_account)
if ctrl:
ctrl.send_message(message)
else:
message_ = OutgoingMessage(account=connected_account,
contact=contact,
message=message,
type_=type_,
subject=subject,
control=ctrl)
connection.send_message(message_)
return True
def send_chat_message(self, jid, message, account):
"""
......@@ -545,20 +544,28 @@ class GajimRemote(Server):
def send_groupchat_message(self, room_jid, message, account):
"""
Send 'message' to groupchat 'room_jid', using account (optional) 'account'
Send 'message' to groupchat 'room_jid',
using account (optional) 'account'
"""
if not room_jid or not message:
return False
connected_account = self._get_account_for_groupchat(account, room_jid)
if connected_account:
message_ = OutgoingMessage(account=connected_account,
jid=room_jid,
message=message,
type_='groupchat')
con = app.connections[connected_account]
con.send_message(message_)
return True
return False
if not connected_account:
return False
contact = app.contacts.get_groupchat_contact(connected_account,
room_jid)
if contact is None:
return False
message_ = OutgoingMessage(account=connected_account,
contact=contact,
message=message,
type_='groupchat')
con = app.connections[connected_account]
con.send_message(message_)
return True
def open_chat(self, jid, account, message):
"""
......
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