summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common.py18
-rw-r--r--src/connection.py8
-rw-r--r--src/gui.py41
-rw-r--r--src/multiuserchat.py2
-rw-r--r--src/room.py2
5 files changed, 44 insertions, 27 deletions
diff --git a/src/common.py b/src/common.py
index 421aada2..340eb213 100644
--- a/src/common.py
+++ b/src/common.py
@@ -186,3 +186,21 @@ def get_os_info():
return os_info
os_info = 'N/A'
return os_info
+
+def datetime_tuple(timestamp):
+ """
+ Convert timestamp using strptime and the format: %Y%m%dT%H:%M:%S
+
+ Because of various datetime formats are used the following exceptions
+ are handled:
+ - Optional milliseconds appened to the string are removed
+ - Optional Z (that means UTC) appened to the string are removed
+ - XEP-082 datetime strings have all '-' cahrs removed to meet
+ the above format.
+ """
+ timestamp = timestamp.split('.')[0]
+ timestamp = timestamp.replace('-', '')
+ timestamp = timestamp.replace('z', '')
+ timestamp = timestamp.replace('Z', '')
+ from datetime import datetime
+ return datetime.strptime(timestamp, '%Y%m%dT%H:%M:%S')
diff --git a/src/connection.py b/src/connection.py
index 5aa9f838..9b047da9 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -86,8 +86,8 @@ class Connection(threading.Thread):
self.client.RegisterHandler('iq', self.on_get_time, typ='get', ns="urn:xmpp:time")
self.client.RegisterHandler('iq', self.on_get_version, typ='get', ns=xmpp.NS_VERSION)
self.client.RegisterHandler('presence', self.handler_presence)
- self.client.RegisterHandler('message', self.handler_delayed_message, ns=xmpp.NS_DELAY, makefirst=True)
self.client.RegisterHandler('message', self.handler_message)
+ # self.client.RegisterHandler('message', self.handler_delayed_message, ns=xmpp.NS_DELAY)
def handler_presence(self, connection, presence):
fro = presence.getFrom()
@@ -98,12 +98,15 @@ class Connection(threading.Thread):
self.handler.emit('on-connected', jid=fro)
return
self.handler.emit('room-presence', stanza=presence)
+ raise xmpp.protocol.NodeProcessed
def handler_delayed_message(self, connection, message):
- pass
+ self.handler.emit('room-delayed-message', stanza=message)
+ raise xmpp.protocol.NodeProcessed
def handler_message(self, connection, message):
self.handler.emit('room-message', stanza=message)
+ raise xmpp.protocol.NodeProcessed
def handler_error(self, connection, error):
pass
@@ -119,5 +122,4 @@ class Connection(threading.Thread):
self.handler.emit('send-version', iq_obj=iq)
def on_get_time(self, connection, iq):
- open('caca', 'w').write('works')
self.handler.emit('send-time', iq_obj=iq)
diff --git a/src/gui.py b/src/gui.py
index 6d342114..f8ee32b5 100644
--- a/src/gui.py
+++ b/src/gui.py
@@ -20,6 +20,7 @@
from gettext import (bindtextdomain, textdomain, bind_textdomain_codeset,
gettext as _)
+
bindtextdomain('poezio')
textdomain('poezio')
bind_textdomain_codeset('poezio', 'utf-8')
@@ -29,7 +30,13 @@ locale.setlocale(locale.LC_ALL, '')
import sys
import curses
+import xmpp
from datetime import datetime
+from time import (altzone, daylight, gmtime, localtime, mktime, strftime,
+ time as time_time, timezone, tzname)
+from calendar import timegm
+
+import common
from handler import Handler
from logging import logger
@@ -98,7 +105,6 @@ class Gui(object):
self.handler.connect('join-room', self.join_room)
self.handler.connect('room-presence', self.room_presence)
self.handler.connect('room-message', self.room_message)
- self.handler.connect('room-delayed-message', self.room_delayed_message)
def main_loop(self, stdscr):
while 1:
@@ -211,16 +217,17 @@ class Gui(object):
self.rooms.insert(0, self.rooms.pop())
self.window.refresh(self.rooms)
- def room_delayed_message(self, stanza):
- self.room_message(stanza)
-
def room_message(self, stanza, date=None):
+ delay_tag = stanza.getTag('delay', namespace='urn:xmpp:delay')
+ if delay_tag and not date:
+ delayed = True
+ date = common.datetime_tuple(delay_tag.getAttr('stamp'))
+ else:
+ delayed = False
if len(sys.argv) > 1:
self.information(str(stanza).encode('utf-8'))
if stanza.getType() != 'groupchat':
return # ignore all messages not comming from a MUC
- if not date:
- date = datetime.now()
nick_from = stanza.getFrom().getResource()
room_from = stanza.getFrom().getStripped()
room = self.get_room_by_name(room_from)
@@ -241,7 +248,7 @@ class Gui(object):
if body.startswith('/me '):
self.add_info(room, nick_from + ' ' + body[4:], date)
else:
- self.add_message(room, nick_from, body, date)
+ self.add_message(room, nick_from, body, date, delayed)
self.window.input.refresh()
curses.doupdate()
@@ -332,14 +339,14 @@ class Gui(object):
self.window.input.refresh()
curses.doupdate()
- def add_message(self, room, nick_from, body, date=None):
+ def add_message(self, room, nick_from, body, date=None, delayed=False):
if not date:
date = datetime.now()
color = room.add_message(nick_from, body, date)
self.window.text_win.add_line(room, (date, nick_from.encode('utf-8'), body.encode('utf-8'), color))
if room == self.current_room():
self.window.text_win.refresh(room.name)
- else:
+ elif not delayed:
self.window.info_win.refresh(self.rooms, self.current_room())
def execute(self):
@@ -374,10 +381,7 @@ class Gui(object):
msg = self.commands[args[0]][1]
else:
msg = _('Unknown command: %s') % args[0]
- room.add_info(msg)
- self.window.text_win.add_line(room, (datetime.now(), msg))
- self.window.text_win.refresh(room.name)
- self.window.input.refresh()
+ self.add_info(room, msg)
def command_win(self, args):
if len(args) != 1:
@@ -400,7 +404,6 @@ class Gui(object):
return
self.window.refresh(self.rooms)
-
def command_kick(self, args):
if len(args) < 1:
self.command_help(['kick'])
@@ -486,10 +489,7 @@ class Gui(object):
config.set_and_save(option, value)
msg = "%s=%s" % (option, value)
room = self.current_room()
- room.add_info(msg)
- self.window.text_win.add_line(room, (datetime.now(), msg))
- self.window.text_win.refresh(room.name)
- self.window.input.refresh()
+ self.add_info(room, msg)
def command_show(self, args):
possible_show = {'avail':'None',
@@ -555,10 +555,7 @@ class Gui(object):
def information(self, msg):
room = self.get_room_by_name("Info")
info = room.add_info(msg)
- if self.current_room() == room:
- self.window.text_win.add_line(room, (datetime.now(), info))
- self.window.text_win.refresh(room.name)
- curses.doupdate()
+ self.add_info(room, msg)
def command_quit(self, args):
self.reset_curses()
diff --git a/src/multiuserchat.py b/src/multiuserchat.py
index 95ffe9b1..c8a1aafc 100644
--- a/src/multiuserchat.py
+++ b/src/multiuserchat.py
@@ -319,4 +319,4 @@ class MultiUserChat(object):
tzo = (zone / 60, abs(zone % 60))
qp.setTagData('tzo', '%+03d:%02d' % (tzo))
self.connection.send(iq_obj)
- raise common.xmpp.NodeProcessed
+ raise xmpp.protocol.NodeProcessed
diff --git a/src/room.py b/src/room.py
index 87a78107..0c3a5deb 100644
--- a/src/room.py
+++ b/src/room.py
@@ -39,7 +39,7 @@ class Room(object):
self.joined = False
self.users = []
- def add_message(self, nick, msg, date=None):
+ def add_message(self, nick, msg, date=None, delayed=False):
if not date:
date = datetime.now()
color = None