Commit ce1fc18e authored by louiz’'s avatar louiz’

Log messages from normal and private conversations as well

parent 22ad96e7
......@@ -519,6 +519,7 @@ class Core(object):
room.add_message(body, time=None, nickname=nick_from,
colorized=False,
forced_user=self.get_room_by_name(room_from).get_user_by_name(nick_from))
logger.log_message(jid.full.replace('/', '\\'), nick_from, body)
self.refresh_window()
self.doupdate()
......@@ -548,6 +549,7 @@ class Core(object):
else:
remote_nick = jid.user
conversation.get_room().add_message(body, None, remote_nick, False, theme.COLOR_REMOTE_USER)
logger.log_message(jid.bare, remote_nick, body)
if self.current_tab() is not conversation:
conversation.set_color_state(theme.COLOR_TAB_PRIVATE)
self.refresh_window()
......
......@@ -34,10 +34,10 @@ class Logger(object):
def __init__(self):
self.logfile = config.get('logfile', 'logs')
# a dict of 'groupchatname': file-object (opened)
self.groupchat_fds = dict()
self.fds = dict()
def __del__(self):
for opened_file in self.groupchat_fds.values():
for opened_file in self.fds.values():
opened_file.close()
def check_and_create_log_dir(self, room):
......@@ -54,19 +54,19 @@ class Logger(object):
pass
try:
fd = open(os.path.join(directory, room), 'a')
self.groupchat_fds[room] = fd
self.fds[room] = fd
return fd
except IOError:
return None
def groupchat(self, room, nick, msg):
def log_message(self, jid, nick, msg):
"""
log the message in the appropriate room's file
log the message in the appropriate jid's file
"""
if room in self.groupchat_fds.keys():
fd = self.groupchat_fds[room]
if jid in self.fds.keys():
fd = self.fds[jid]
else:
fd = self.check_and_create_log_dir(room)
fd = self.check_and_create_log_dir(jid)
if not fd:
return
if nick:
......
......@@ -52,7 +52,7 @@ class Room(TextBuffer):
to be
"""
if time is None and self.joined: # don't log the history messages
logger.groupchat(self.name, nickname, txt)
logger.log_message(self.name, nickname, txt)
def do_highlight(self, txt, time, nickname):
"""
......
......@@ -43,6 +43,7 @@ from sleekxmpp.xmlstream.stanzabase import JID
from config import config
from roster import RosterGroup, roster
from contact import Contact, Resource
from logger import logger
import multiuserchat as muc
class Tab(object):
......@@ -655,6 +656,7 @@ class PrivateTab(ChatTab):
def command_say(self, line):
muc.send_private_message(self.core.xmpp, self.get_name(), line)
self.core.add_message_to_text_buffer(self.get_room(), line, None, self.get_room().own_nick)
logger.log_message(self.get_name().replace('/', '\\'), self.get_room().own_nick, line)
def command_unquery(self, arg):
"""
......@@ -1034,6 +1036,7 @@ class ConversationTab(ChatTab):
def command_say(self, line):
muc.send_private_message(self.core.xmpp, self.get_name(), line)
self.core.add_message_to_text_buffer(self.get_room(), line, None, self.core.own_nick)
logger.log_message(JID(self.get_name()).bare, self.core.own_nick, line)
def command_unquery(self, arg):
self.core.close_tab()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment