Move to the upstream SleekXMPP

- remove the decline command that is not in the trunk (and mediated
  declines are supported nowhere anyway)
- change a bit xhtml-im support
- change the bookmarks management a bit
- Add a verification to avoid crashing when poezio will be launched the
  next time
- Fix the (unrelated) bug when setting a jid affiliation
This commit is contained in:
mathieui 2013-01-17 17:37:06 +01:00
parent b06240ee7b
commit c5cc462963
8 changed files with 71 additions and 43 deletions

View file

@ -316,8 +316,6 @@ their number will change if you close a tab on the left of the list).
*/invite <jid> <room> [reason]*:: Invite _jid_ to _room_ wit _reason_ (if */invite <jid> <room> [reason]*:: Invite _jid_ to _room_ wit _reason_ (if
provided). provided).
*/decline <room> [reason]*:: Decline invitation to _room_ with _reason_.
*/invitations*:: Show the pending invitations. */invitations*:: Show the pending invitations.
*/activity <jid>*:: Show the last activity of a contact or a server (its */activity <jid>*:: Show the last activity of a contact or a server (its

View file

@ -58,13 +58,9 @@ class Bookmark(object):
el['jid'] = self.jid el['jid'] = self.jid
el['autojoin'] = 'true' if self.autojoin else 'false' el['autojoin'] = 'true' if self.autojoin else 'false'
if self.nick: if self.nick:
n = Nick().xml el['nick'] = self.nick
n.text = self.nick
el.append(n)
if self.password: if self.password:
p = Password().xml el['password'] = self.password
p.text = self.password
el.append(p)
return el return el
def local(self): def local(self):
@ -113,18 +109,20 @@ def remove(value):
def stanza_storage(method): def stanza_storage(method):
"""Generate a <storage/> stanza with the conference elements.""" """Generate a <storage/> stanza with the conference elements."""
storage = Storage() storage = Bookmarks()
for b in filter(lambda b: b.method == method, bookmarks): for b in filter(lambda b: b.method == method, bookmarks):
storage.append(b.stanza()) storage.append(b.stanza())
return storage return storage
def save_pep(xmpp): def save_pep(xmpp):
"""Save the remote bookmarks via PEP.""" """Save the remote bookmarks via PEP."""
xmpp.plugin['xep_0048'].set_bookmarks(stanza_storage('pep')) xmpp.plugin['xep_0048'].set_bookmarks(stanza_storage('pep'),
method='xep_0223')
def save_privatexml(xmpp): def save_privatexml(xmpp):
""""Save the remote bookmarks with privatexml.""" """"Save the remote bookmarks with privatexml."""
xmpp.plugin['xep_0048'].set_bookmarks_old(stanza_storage('privatexml')) xmpp.plugin['xep_0048'].set_bookmarks(stanza_storage('privatexml'),
method='xep_0049')
def save_remote(xmpp, method=preferred): def save_remote(xmpp, method=preferred):
"""Save the remote bookmarks.""" """Save the remote bookmarks."""
@ -132,9 +130,11 @@ def save_remote(xmpp, method=preferred):
try: try:
if method is 'privatexml': if method is 'privatexml':
xmpp.plugin['xep_0048'].set_bookmarks_old(stanza_storage('privatexml')) xmpp.plugin['xep_0048'].set_bookmarks(stanza_storage('privatexml'),
method='xep_0049')
else: else:
xmpp.plugin['xep_0048'].set_bookmarks(stanza_storage('pep')) xmpp.plugin['xep_0048'].set_bookmarks(stanza_storage('pep'),
method='xep_0223')
except: except:
import traceback import traceback
log.debug("Could not save the bookmarks:\n%s" % traceback.format_exc()) log.debug("Could not save the bookmarks:\n%s" % traceback.format_exc())
@ -161,7 +161,7 @@ def save(xmpp, core=None):
def get_pep(xmpp): def get_pep(xmpp):
"""Add the remotely stored bookmarks via pep to the list.""" """Add the remotely stored bookmarks via pep to the list."""
try: try:
iq = xmpp.plugin['xep_0048'].get_bookmarks() iq = xmpp.plugin['xep_0048'].get_bookmarks(method='xep_0223', block=True)
except: except:
return False return False
for conf in iter(iq.xml, '{storage:bookmarks}conference'): for conf in iter(iq.xml, '{storage:bookmarks}conference'):
@ -173,7 +173,7 @@ def get_pep(xmpp):
def get_privatexml(xmpp): def get_privatexml(xmpp):
"""Add the remotely stored bookmarks via privatexml to the list.""" """Add the remotely stored bookmarks via privatexml to the list."""
try: try:
iq = xmpp.plugin['xep_0048'].get_bookmarks_old() iq = xmpp.plugin['xep_0048'].get_bookmarks(method='xep_0049', block=True)
except: except:
return False return False
for conf in iter(iq.xml, '{storage:bookmarks}conference'): for conf in iter(iq.xml, '{storage:bookmarks}conference'):
@ -186,6 +186,8 @@ def get_remote(xmpp):
"""Add the remotely stored bookmarks to the list.""" """Add the remotely stored bookmarks to the list."""
if xmpp.anon: if xmpp.anon:
return return
method = config.get('use_bookmarks_method', '')
if not method:
pep, privatexml = True, True pep, privatexml = True, True
for method in methods[1:]: for method in methods[1:]:
if method == 'pep': if method == 'pep':
@ -198,6 +200,11 @@ def get_remote(xmpp):
config.set_and_save('use_bookmarks_method', 'privatexml') config.set_and_save('use_bookmarks_method', 'privatexml')
elif not pep and not privatexml: elif not pep and not privatexml:
config.set_and_save('use_bookmarks_method', '') config.set_and_save('use_bookmarks_method', '')
else:
if method == 'pep':
get_pep(xmpp)
else:
get_privatexml(xmpp)
def get_local(): def get_local():
"""Add the locally stored bookmarks to the list.""" """Add the locally stored bookmarks to the list."""

View file

@ -16,6 +16,7 @@ from gettext import (bindtextdomain, textdomain, bind_textdomain_codeset,
gettext as _) gettext as _)
import getpass import getpass
import sys
import sleekxmpp import sleekxmpp
from config import config, options from config import config, options
@ -58,13 +59,26 @@ class Connection(sleekxmpp.ClientXMPP):
self.whitespace_keepalive_interval = int(interval) self.whitespace_keepalive_interval = int(interval)
else: else:
self.whitespace_keepalive_interval = 300 self.whitespace_keepalive_interval = 300
# Hack to check the sleekxmpp version
# TODO: Remove that when a sufficient time has passed since the move
try:
self.register_plugin('xep_0071')
wrong_version = True
except:
wrong_version = False
finally:
if wrong_version:
print("You are using the wrong sleekxmpp version. Please run "
"update.sh again or install the corresponding "
"sleekxmpp package.")
sys.exit()
self.register_plugin('xep_0012') self.register_plugin('xep_0012')
self.register_plugin('xep_0030') self.register_plugin('xep_0030')
self.register_plugin('xep_0004') self.register_plugin('xep_0004')
self.register_plugin('xep_0045') self.register_plugin('xep_0045')
self.register_plugin('xep_0060') self.register_plugin('xep_0060')
self.register_plugin('xep_0048') self.register_plugin('xep_0048')
self.register_plugin('xep_0071')
self.register_plugin('xep_0085') self.register_plugin('xep_0085')
self.register_plugin('xep_0191') self.register_plugin('xep_0191')
if config.get('send_poezio_info', 'true') == 'true': if config.get('send_poezio_info', 'true') == 'true':

View file

@ -2432,11 +2432,6 @@ class Core(object):
desc=_('Invite jid in room with reason.'), desc=_('Invite jid in room with reason.'),
shortdesc=_('Invite someone in a room.'), shortdesc=_('Invite someone in a room.'),
completion=self.completion_invite) completion=self.completion_invite)
self.register_command('decline', self.command_decline,
usage=_('<room> [reason]'),
desc=_('Decline the invitation to room with or without reason.'),
shortdesc=_('Decline an invitation.'),
completion=self.completion_decline)
self.register_command('invitations', self.command_invitations, self.register_command('invitations', self.command_invitations,
shortdesc=_('Show the pending invitations.')) shortdesc=_('Show the pending invitations.'))
self.register_command('bookmarks', self.command_bookmarks, self.register_command('bookmarks', self.command_bookmarks,

View file

@ -79,7 +79,7 @@ def join_groupchat(xmpp, jid, nick, passwd='', maxhistory=None, status=None, sho
stanza.append(x) stanza.append(x)
stanza.send() stanza.send()
xmpp.plugin['xep_0045'].rooms[jid] = {} xmpp.plugin['xep_0045'].rooms[jid] = {}
xmpp.plugin['xep_0045'].our_nicks[jid] = nick xmpp.plugin['xep_0045'].ourNicks[jid] = nick
def leave_groupchat(xmpp, jid, own_nick, msg): def leave_groupchat(xmpp, jid, own_nick, msg):
""" """
@ -119,6 +119,8 @@ def set_user_affiliation(xmpp, muc_jid, affiliation, nick=None, jid=None, reason
jid = safeJID(jid) jid = safeJID(jid)
muc_jid = safeJID(muc_jid) muc_jid = safeJID(muc_jid)
try: try:
return xmpp.plugin['xep_0045'].set_affiliation(muc_jid, jid, nick, affiliation) return xmpp.plugin['xep_0045'].setAffiliation(str(muc_jid), str(jid) if jid else None, nick, affiliation)
except: except:
import traceback
log.debug('Error setting the affiliation: %s', traceback.format_exc())
return False return False

View file

@ -526,7 +526,8 @@ class ChatTab(Tab):
msg = self.core.xmpp.make_message(self.get_name()) msg = self.core.xmpp.make_message(self.get_name())
msg['body'] = body msg['body'] = body
msg['xhtml_im'] = arg msg.enable('html')
msg['html']['body'] = arg
if isinstance(self, MucTab): if isinstance(self, MucTab):
msg['type'] = 'groupchat' msg['type'] = 'groupchat'
if isinstance(self, ConversationTab): if isinstance(self, ConversationTab):
@ -1193,7 +1194,8 @@ class MucTab(ChatTab):
# be converted in xhtml. # be converted in xhtml.
self.core.events.trigger('muc_say', msg, self) self.core.events.trigger('muc_say', msg, self)
if msg['body'].find('\x19') != -1: if msg['body'].find('\x19') != -1:
msg['xhtml_im'] = xhtml.poezio_colors_to_html(msg['body']) msg.enable('html')
msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
msg['body'] = xhtml.clean_text(msg['body']) msg['body'] = xhtml.clean_text(msg['body'])
if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False: if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False:
msg['chat_state'] = needed msg['chat_state'] = needed
@ -1820,7 +1822,8 @@ class PrivateTab(ChatTab):
nick_color=get_theme().COLOR_OWN_NICK, nick_color=get_theme().COLOR_OWN_NICK,
identifier=msg['id']) identifier=msg['id'])
if msg['body'].find('\x19') != -1: if msg['body'].find('\x19') != -1:
msg['xhtml_im'] = xhtml.poezio_colors_to_html(msg['body']) msg.enable('html')
msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
msg['body'] = xhtml.clean_text(msg['body']) msg['body'] = xhtml.clean_text(msg['body'])
if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False: if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False:
needed = 'inactive' if self.inactive else 'active' needed = 'inactive' if self.inactive else 'active'
@ -2950,7 +2953,8 @@ class ConversationTab(ChatTab):
nick_color=get_theme().COLOR_OWN_NICK, nick_color=get_theme().COLOR_OWN_NICK,
identifier=msg['id']) identifier=msg['id'])
if msg['body'].find('\x19') != -1: if msg['body'].find('\x19') != -1:
msg['xhtml_im'] = xhtml.poezio_colors_to_html(msg['body']) msg.enable('html')
msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
msg['body'] = xhtml.clean_text(msg['body']) msg['body'] = xhtml.clean_text(msg['body'])
if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False: if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False:
needed = 'inactive' if self.inactive else 'active' needed = 'inactive' if self.inactive else 'active'

View file

@ -191,7 +191,7 @@ def get_body_from_message_stanza(message):
the body (without any color) otherwise the body (without any color) otherwise
""" """
if config.get('enable_xhtml_im', 'true') == 'true': if config.get('enable_xhtml_im', 'true') == 'true':
xhtml_body = message['xhtml_im'] xhtml_body = message['html']['body']
if xhtml_body: if xhtml_body:
content = xhtml_to_poezio_colors(xhtml_body) content = xhtml_to_poezio_colors(xhtml_body)
content = content if content else message['body'] content = content if content else message['body']
@ -224,7 +224,7 @@ def ncurses_color_to_html(color):
r = g = b = color / 24 * 6 r = g = b = color / 24 * 6
return '#%02X%02X%02X' % (r*256/6, g*256/6, b*256/6) return '#%02X%02X%02X' % (r*256/6, g*256/6, b*256/6)
def xhtml_to_poezio_colors(text): def xhtml_to_poezio_colors(xml):
def parse_css(css): def parse_css(css):
def get_color(value): def get_color(value):
if value[0] == '#': if value[0] == '#':
@ -283,7 +283,6 @@ def xhtml_to_poezio_colors(text):
def trim(string): def trim(string):
return re.sub(whitespace_re, ' ', string) return re.sub(whitespace_re, ' ', string)
xml = ET.fromstring(text)
message = '' message = ''
if version_info[1] == 2: if version_info[1] == 2:
elems = xml.iter() elems = xml.iter()

View file

@ -19,15 +19,24 @@ then
fi fi
if [ -e "SleekXMPP" ] if [ -e "SleekXMPP" ]
then
echo "Removing the old SleekXMPP"
rm -rf SleekXMPP
rm src/sleekxmpp
git clone https://github.com/fritzy/SleekXMPP.git Sleek
fi
if [ -e "Sleek" ]
then then
echo "Updating SleekXMPP" echo "Updating SleekXMPP"
cd SleekXMPP cd Sleek
git pull git pull
cd .. cd ..
else else
echo "Downloading SleekXMPP" echo "Downloading SleekXMPP"
git clone git://github.com/louiz/SleekXMPP.git git clone https://github.com/fritzy/SleekXMPP.git Sleek
fi fi
if [ -e ".dnspython.tgz" ] if [ -e ".dnspython.tgz" ]
then then
if [ -e "dnspython" ] if [ -e "dnspython" ]
@ -59,5 +68,5 @@ then
echo 'Link src/sleekxmpp already exists' echo 'Link src/sleekxmpp already exists'
else else
echo "Creating link src/sleekxmpp" echo "Creating link src/sleekxmpp"
ln -s ../SleekXMPP/sleekxmpp sleekxmpp ln -s ../Sleek/sleekxmpp sleekxmpp
fi fi