summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-04-05 05:27:52 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-04-05 05:27:52 +0200
commitf4c138e444bb5913e3d9a940999949c43dc25825 (patch)
tree2480b3ec4160f03d2fe7f6b5ce36bf06abfbbb65
parentcb1abbd9451af2062cc8f71f51e0ba903fa2f749 (diff)
downloadpoezio-f4c138e444bb5913e3d9a940999949c43dc25825.tar.gz
poezio-f4c138e444bb5913e3d9a940999949c43dc25825.tar.bz2
poezio-f4c138e444bb5913e3d9a940999949c43dc25825.tar.xz
poezio-f4c138e444bb5913e3d9a940999949c43dc25825.zip
Save the last presence. Fix #2133
-rw-r--r--src/core.py26
-rw-r--r--src/multiuserchat.py8
-rw-r--r--src/tabs.py3
3 files changed, 30 insertions, 7 deletions
diff --git a/src/core.py b/src/core.py
index 04f51b7c..ce256fe0 100644
--- a/src/core.py
+++ b/src/core.py
@@ -31,6 +31,7 @@ import common
import theme
import logging
import singleton
+import collections
from sleekxmpp.xmlstream.stanzabase import JID
@@ -76,6 +77,8 @@ possible_show = {'available':None,
resize_lock = threading.Lock()
+Status = collections.namedtuple('Status', 'show message')
+
class Core(object):
"""
User interface using ncurses
@@ -83,6 +86,7 @@ class Core(object):
def __init__(self):
# All uncaught exception are given to this callback, instead
# of being displayed on the screen and exiting the program.
+ self.status = Status(show=None, message='')
sys.excepthook = self.on_exception
self.running = True
self.xmpp = singleton.Singleton(connection.Connection)
@@ -225,6 +229,20 @@ class Core(object):
tab.on_info_win_size_changed()
self.refresh_window()
+ def get_status(self):
+ """
+ Get the last status that was previously set
+ """
+ return self.status
+
+ def set_status(self, pres, msg):
+ """
+ Set our current status so we can remember
+ it and use it back when needed (for example to display it
+ or to use it when joining a new muc)
+ """
+ self.status = Status(show=pres, message=msg)
+
def on_data_form(self, message):
"""
When a data form is received
@@ -948,6 +966,7 @@ class Core(object):
for tab in self.tabs:
if isinstance(tab, tabs.MucTab) and tab.get_room().joined:
muc.change_show(self.xmpp, tab.get_room().name, tab.get_room().own_nick, show, msg)
+ self.set_status(show, msg)
def completion_status(self, the_input):
return the_input.auto_completion([status for status in list(possible_show.keys())], ' ')
@@ -1143,11 +1162,14 @@ class Core(object):
if room.startswith('@'):
room = room[1:]
room = room.lower()
+ current_status = self.get_status()
if r and not r.joined:
- muc.join_groupchat(self.xmpp, room, nick, password, histo_length)
+ muc.join_groupchat(self.xmpp, room, nick, password,
+ histo_length, current_status.message, current_status.show)
if not r: # if the room window exists, we don't recreate it.
self.open_new_room(room, nick)
- muc.join_groupchat(self.xmpp, room, nick, password, histo_length)
+ muc.join_groupchat(self.xmpp, room, nick, password,
+ histo_length, current_status.message, current_status.show)
else:
r.own_nick = nick
r.users = []
diff --git a/src/multiuserchat.py b/src/multiuserchat.py
index d28c6712..87443e07 100644
--- a/src/multiuserchat.py
+++ b/src/multiuserchat.py
@@ -57,14 +57,14 @@ def change_subject(xmpp, jid, subject):
msg['subject'] = subject
msg.send()
-def change_nick(xmpp, jid, nick):
+def change_nick(xmpp, jid, nick, status=None, show=None):
"""
Change our own nick in a room
"""
- xmpp.make_presence(pto='%s/%s' % (jid, nick)).send()
+ xmpp.make_presence(pshow=show, pstatus=status, pto='%s/%s' % (jid, nick)).send()
-def join_groupchat(xmpp, jid, nick, passwd='', maxhistory=None):
- xmpp.plugin['xep_0045'].joinMUC(jid, nick, maxhistory=maxhistory, password=passwd)
+def join_groupchat(xmpp, jid, nick, passwd='', maxhistory=None, status=None, show=None):
+ xmpp.plugin['xep_0045'].joinMUC(jid, nick, maxhistory=maxhistory, password=passwd, pstatus=status, pshow=show)
def leave_groupchat(xmpp, jid, own_nick, msg):
"""
diff --git a/src/tabs.py b/src/tabs.py
index 832aa281..c84ba0fa 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -487,7 +487,8 @@ class MucTab(ChatTab):
room = self.get_room()
if not room.joined:
return
- muc.change_nick(self.core.xmpp, room.name, nick)
+ current_status = self.core.get_status()
+ muc.change_nick(self.core.xmpp, room.name, nick, current_status.message, current_status.show)
def command_part(self, arg):
"""