-# Copyright 2004 James Bunton <james@delx.cjb.net>
+# Copyright 2004-2005 James Bunton <james@delx.cjb.net>
# Licensed for distribution under the GPL version 2, check COPYING for details
import utils
from twisted.internet import reactor
-if(utils.checkTwisted()):
- from twisted.xish.domish import Element
-else:
- from tlib.domish import Element
+from tlib.xmlw import Element
+from debug import LogEvent, INFO, WARN, ERROR
+import disco
import jabw
import config
-import debug
import lang
import string
import time
self.messageBuffer = []
self.contacts = []
- self.checkTimer = reactor.callLater(60.0*2, self.checkUserJoined, None)
+ self.checkTimer = reactor.callLater(float(config.groupchatTimeout), self.checkUserJoined, None)
- debug.log("BaseGroupchat: \"%s\" created" % (self.roomJID()))
+ LogEvent(INFO, self.roomJID())
def removeMe(self):
""" Cleanly removes the object """
self.checkTimer.cancel()
self.checkTimer = None
- utils.mutilateMe(self)
-
- debug.log("BaseGroupchat: \"%s\" destroyed" % (self.roomJID()))
-
+ LogEvent(INFO, self.roomJID())
+
def roomJID(self):
""" Returns the room JID """
return self.ID + "@" + config.jid
def checkUserJoined(self, ignored=None):
self.checkTimer = None
if(not self.ready):
- debug.log("BaseGroupchat: \"%s\" User hasn't joined after two minutes. Removing them from the room.")
+ LogEvent(INFO, self.roomJID(), "User hasn't joined after two minutes. Removing them from the room.")
text = []
text.append(lang.get(self.session.lang).groupchatFailJoin1 % (self.roomJID()))
def sendUserInvite(self, fro):
""" Sends the invitation out to the Jabber user to join this room """
+ LogEvent(INFO, self.roomJID(), "Sending invitation to user")
el = Element((None, "message"))
el.attributes["from"] = fro
el.attributes["to"] = self.user()
body.addContent(text)
x = el.addElement("x")
x.attributes["jid"] = self.roomJID()
- x.attributes["xmlns"] = "jabber:x:conference"
- debug.log("BaseGroupchat: \"%s\" sending invitation to \"%s\" to join" % (self.roomJID(), self.user()))
+ x.attributes["xmlns"] = disco.XCONFERENCE
self.session.pytrans.send(el)
def userJoined(self, nick):
self.nick = self.session.username
self.session.sendPresence(to=self.user(), fro=self.roomJID() + "/" + self.nick)
if(not self.ready):
- debug.log("BaseGroupchat: \"%s\" user has joined us!" % (self.roomJID()))
+ LogEvent(INFO, self.roomJID())
self.ready = True
for (source, text, timestamp) in self.messageBuffer:
self.messageReceived(source, text, timestamp)
def contactJoined(self, contact):
if(self.contacts.count(contact) == 0):
self.contacts.append(contact)
- debug.log("BaseGroupchat: \"%s\" Legacy contact has joined \"%s\"" % (self.roomJID(), contact))
+ LogEvent(INFO, self.roomJID())
self.contactPresenceChanged(contact)
self.messageReceived(None, "%s has joined the conference." % (contact))
def contactLeft(self, contact):
if(self.contacts.count(contact) > 0):
self.contacts.remove(contact)
- debug.log("BaseGroupchat: \"%s\" Legacy contact has left \"%s\"" % (self.roomJID(), contact))
+ LogEvent(INFO, self.roomJID())
self.contactPresenceChanged(contact, ptype="unavailable")
self.messageReceived(None, "%s has left the conference." % (contact))
timestamp = time.strftime("%Y%m%dT%H:%M:%S")
self.messageBuffer.append((source, message, timestamp))
else:
+ self.session.pytrans.statistics.stats["MessageCount"] += 1
fro = self.roomJID()
if(source):
fro += "/" + source
- debug.log("BaseGroupchat: \"%s\" messageReceived(\"%s\", \"%s\", \"%s\")" % (self.roomJID(), source, message, timestamp))
+ LogEvent(INFO, self.roomJID())
self.session.sendMessage(to=self.user(), fro=fro, body=message, mtype="groupchat", delay=timestamp)
def contactPresenceChanged(self, contact, ptype=None):
self.session.sendPresence(to=self.user(), fro=fro, ptype=ptype)
def sendMessage(self, text, noerror):
- debug.log("BaseGroupchat: \"%s\" sendMessage(\"%s\")" % (self.roomJID(), text))
+ LogEvent(INFO, self.roomJID())
self.messageReceived(self.nick, text)
self.sendLegacyMessage(text, noerror)
def sendContactInvite(self, contact):
""" Reimplement this to send the packet to the legacy service """
pass
+
+