diff --git a/src/common/commands.py b/src/common/commands.py index 09f93fea0bbd09a5772be04f7e8d704c696560d4..4fdb6d4d7214c6dc3c932eb0bc10bb0b8d83f550 100644 --- a/src/common/commands.py +++ b/src/common/commands.py @@ -135,7 +135,7 @@ class ChangeStatusCommand(AdHocCommand): # if going offline, we need to push response so it won't go into # queue and disappear - self.connection.connection.send(response, presencetype == 'offline') + self.connection.connection.send(response, now = presencetype == 'offline') # send new status gajim.interface.roster.send_status(self.connection.name, presencetype, diff --git a/src/common/xmpp/dispatcher_nb.py b/src/common/xmpp/dispatcher_nb.py index 9f05282f16774729899d1fdda6a5150adbab51bb..9b3cf342ce2bf700a07ccf677ca4fc5992d06a58 100644 --- a/src/common/xmpp/dispatcher_nb.py +++ b/src/common/xmpp/dispatcher_nb.py @@ -398,11 +398,11 @@ class Dispatcher(PlugIn): Additional callback arguments can be specified in args. ''' self.SendAndWaitForResponse(stanza, 0, func, args) - def send(self, stanza, is_message = False): + def send(self, stanza, is_message = False, now = False): ''' Serialise stanza and put it on the wire. Assign an unique ID to it before send. Returns assigned ID.''' if type(stanza) in [type(''), type(u'')]: - return self._owner.Connection.send(stanza) + return self._owner.Connection.send(stanza, now = now) if not isinstance(stanza, Protocol): _ID=None elif not stanza.getID(): @@ -426,9 +426,9 @@ class Dispatcher(PlugIn): stanza.setNamespace(self._owner.Namespace) stanza.setParent(self._metastream) if is_message: - self._owner.Connection.send(stanza, True) + self._owner.Connection.send(stanza, True, now = now) else: - self._owner.Connection.send(stanza) + self._owner.Connection.send(stanza, now = now) return _ID def disconnect(self): diff --git a/src/common/xmpp/transports_nb.py b/src/common/xmpp/transports_nb.py index e10845faa266eca665b93272c2b4740aae7546b1..c2dfd1924cd2481a326b10b4befd7d01e12b8cfe 100644 --- a/src/common/xmpp/transports_nb.py +++ b/src/common/xmpp/transports_nb.py @@ -138,7 +138,7 @@ class SSLWrapper: raise NotImplementedException() - def send(self, data, flags=None): + def send(self, data, flags=None, now = False): raise NotImplementedException() class PyOpenSSLWrapper(SSLWrapper): @@ -178,7 +178,7 @@ class PyOpenSSLWrapper(SSLWrapper): raise SSLWrapper.Error(self.sock or self.sslobj, e) return retval - def send(self, data, flags=None): + def send(self, data, flags=None, now = False): try: if flags is None: return self.sslobj.send(data) else: return self.sslobj.send(data, flags) @@ -219,7 +219,7 @@ class StdlibSSLWrapper(SSLWrapper): raise SSLWrapper.Error(self.sock or self.sslobj, e) return None - def send(self, data, flags=None): + def send(self, data, flags=None, now = False): # we simply ignore flags since ssl object doesn't support it try: return self.sslobj.write(data) @@ -574,7 +574,7 @@ class NonBlockingTcp(PlugIn, IdleObject): self.on_connect = None return True - def send(self, raw_data): + def send(self, raw_data, now = False): '''Append raw_data to the queue of messages to be send. If supplied data is unicode string, encode it to utf-8. ''' @@ -585,7 +585,11 @@ class NonBlockingTcp(PlugIn, IdleObject): r = r.encode('utf-8') elif not isinstance(r, str): r = ustr(r).encode('utf-8') - self.sendqueue.append(r) + if now: + self.sendqueue.insert(0, r) + self._do_send() + else: + self.sendqueue.append(r) self._plug_idle() def _on_send(self):