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

Merge branch 'fixselfresource' into 'gajim_0.16'

Improvements for sending messages to ourself

See merge request !69
parents b4bb07a0 5e56f9c3
......@@ -2362,7 +2362,10 @@ class ChatControl(ChatControlBase):
if not keyID:
keyID = 'UNKNOWN'
chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \
if self.contact.jid == gajim.get_jid_from_account(self.account):
chatstates_on = False
else:
chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \
'disabled'
chatstate_to_send = None
if chatstates_on and contact is not None:
......@@ -2377,11 +2380,11 @@ class ChatControl(ChatControlBase):
def _on_sent(msg_stanza, message, encrypted, xhtml, label, old_txt):
id_ = msg_stanza.getID()
if self.contact.supports(NS_RECEIPTS) and gajim.config.get_per(
'accounts', self.account, 'request_receipt'):
xep0184_id = id_
else:
xep0184_id = None
xep0184_id = None
if self.contact.jid != gajim.get_jid_from_account(self.account):
if self.contact.supports(NS_RECEIPTS) and gajim.config.get_per(
'accounts', self.account, 'request_receipt'):
xep0184_id = id_
if label:
displaymarking = label.getTag('displaymarking')
else:
......@@ -2696,6 +2699,10 @@ class ChatControl(ChatControlBase):
chatstate_setting = gajim.config.get('outgoing_chat_state_notifications')
if chatstate_setting == 'disabled':
return
if self.contact.jid == gajim.get_jid_from_account(self.account):
return
elif chatstate_setting == 'composing_only' and state != 'active' and\
state != 'composing':
return
......
......@@ -298,6 +298,8 @@ class CommonConnection:
'to %s, this JID is not valid.') % j))
return
fjid = new_list
elif jid == gajim.get_jid_from_account(self.name):
fjid = jid
else:
try:
jid = self.check_jid(jid)
......@@ -502,10 +504,11 @@ class CommonConnection:
msg_iq.setTag(chatstate, namespace=nbxmpp.NS_CHATSTATES)
# XEP-0184
if msgtxt and gajim.config.get_per('accounts', self.name,
'request_receipt') and contact and contact.supports(
nbxmpp.NS_RECEIPTS):
msg_iq.setTag('request', namespace=nbxmpp.NS_RECEIPTS)
if jid != gajim.get_jid_from_account(self.name):
if msgtxt and gajim.config.get_per('accounts', self.name,
'request_receipt') and contact and contact.supports(
nbxmpp.NS_RECEIPTS):
msg_iq.setTag('request', namespace=nbxmpp.NS_RECEIPTS)
if forward_from:
addresses = msg_iq.addChild('addresses',
......
......@@ -1206,17 +1206,19 @@ class ConnectionHandlersBase:
jid_to = gajim.get_jid_without_resource(fjid_to)
if jid_to == gajim.get_jid_from_account(self.name):
reply = True
if obj.receipt_request_tag and gajim.config.get_per('accounts',
self.name, 'answer_receipts') and ((contact and contact.sub \
not in (u'to', u'none')) or gc_contact) and obj.mtype != 'error' and \
reply:
receipt = nbxmpp.Message(to=obj.fjid, typ='chat')
receipt.setTag('received', namespace='urn:xmpp:receipts',
attrs={'id': obj.id_})
if obj.thread_id:
receipt.setThread(obj.thread_id)
self.connection.send(receipt)
if obj.jid != gajim.get_jid_from_account(self.name):
if obj.receipt_request_tag and gajim.config.get_per('accounts',
self.name, 'answer_receipts') and ((contact and contact.sub \
not in (u'to', u'none')) or gc_contact) and obj.mtype != 'error' and \
reply:
receipt = nbxmpp.Message(to=obj.fjid, typ='chat')
receipt.setTag('received', namespace='urn:xmpp:receipts',
attrs={'id': obj.id_})
if obj.thread_id:
receipt.setThread(obj.thread_id)
self.connection.send(receipt)
# We got our message's receipt
if obj.receipt_received_tag and gajim.config.get_per('accounts',
......
......@@ -1129,6 +1129,15 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
account = self.conn.name
our_full_jid = gajim.get_jid_from_account(account, full=True)
if self.stanza.getFrom() == our_full_jid:
# Drop messages sent from our own full jid
# It can happen that when we sent message to our own bare jid
# that the server routes that message back to us
log.info('Received message from self: %s, message is dropped'
% self.stanza.getFrom())
return
# check if the message is a roster item exchange (XEP-0144)
if self.stanza.getTag('x', namespace=nbxmpp.NS_ROSTERX):
gajim.nec.push_incoming_event(RosterItemExchangeEvent(None,
......@@ -1184,6 +1193,17 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
to = gajim.get_jid_from_account(account)
self.stanza.setFrom(to)
self.sent = True
elif carbon_marker.getName() == 'received':
full_frm = str(self.stanza.getFrom())
frm = gajim.get_jid_without_resource(full_frm)
if frm == gajim.get_jid_from_account(account):
# Drop 'received' Carbons from ourself, we already
# got the message with the 'sent' Carbon or via the
# message itself
log.info(
'Drop "received"-Carbon from ourself: %s'
% full_frm)
return
try:
self.get_jid_resource()
except helpers.InvalidFormat:
......
......@@ -419,13 +419,16 @@ def jid_is_transport(jid):
return True
return False
def get_jid_from_account(account_name):
def get_jid_from_account(account_name, full=False):
"""
Return the jid we use in the given account
"""
name = config.get_per('accounts', account_name, 'name')
hostname = config.get_per('accounts', account_name, 'hostname')
jid = name + '@' + hostname
if full:
resource = connections[account_name].server_resource
jid += '/' + resource
return jid
def get_our_jids():
......
......@@ -234,7 +234,8 @@ class MessageControl(object):
conn = gajim.connections[self.account]
if not self.session:
if not obj.resource:
if (not obj.resource and
obj.jid != gajim.get_jid_from_account(self.account)):
if self.resource:
obj.resource = self.resource
else:
......
......@@ -2759,7 +2759,8 @@ class RosterWindow:
typ = 'error'
if obj.forwarded and obj.sent:
typ = 'out'
xep0184_id = obj.id_
if obj.jid != gajim.get_jid_from_account(obj.conn.name):
xep0184_id = obj.id_
obj.session.control.print_conversation(obj.msgtxt, typ,
tim=obj.timestamp, encrypted=obj.encrypted, subject=obj.subject,
......@@ -4167,7 +4168,7 @@ class RosterWindow:
contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
if jid == gajim.get_jid_from_account(account):
resource = contact.resource
resource = None
gajim.interface.on_open_chat_window(None, contact, account, \
resource=resource, session=session)
......
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