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): ...@@ -519,6 +519,7 @@ class Core(object):
room.add_message(body, time=None, nickname=nick_from, room.add_message(body, time=None, nickname=nick_from,
colorized=False, colorized=False,
forced_user=self.get_room_by_name(room_from).get_user_by_name(nick_from)) 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.refresh_window()
self.doupdate() self.doupdate()
...@@ -548,6 +549,7 @@ class Core(object): ...@@ -548,6 +549,7 @@ class Core(object):
else: else:
remote_nick = jid.user remote_nick = jid.user
conversation.get_room().add_message(body, None, remote_nick, False, theme.COLOR_REMOTE_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: if self.current_tab() is not conversation:
conversation.set_color_state(theme.COLOR_TAB_PRIVATE) conversation.set_color_state(theme.COLOR_TAB_PRIVATE)
self.refresh_window() self.refresh_window()
......
...@@ -34,10 +34,10 @@ class Logger(object): ...@@ -34,10 +34,10 @@ class Logger(object):
def __init__(self): def __init__(self):
self.logfile = config.get('logfile', 'logs') self.logfile = config.get('logfile', 'logs')
# a dict of 'groupchatname': file-object (opened) # a dict of 'groupchatname': file-object (opened)
self.groupchat_fds = dict() self.fds = dict()
def __del__(self): def __del__(self):
for opened_file in self.groupchat_fds.values(): for opened_file in self.fds.values():
opened_file.close() opened_file.close()
def check_and_create_log_dir(self, room): def check_and_create_log_dir(self, room):
...@@ -54,19 +54,19 @@ class Logger(object): ...@@ -54,19 +54,19 @@ class Logger(object):
pass pass
try: try:
fd = open(os.path.join(directory, room), 'a') fd = open(os.path.join(directory, room), 'a')
self.groupchat_fds[room] = fd self.fds[room] = fd
return fd return fd
except IOError: except IOError:
return None 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(): if jid in self.fds.keys():
fd = self.groupchat_fds[room] fd = self.fds[jid]
else: else:
fd = self.check_and_create_log_dir(room) fd = self.check_and_create_log_dir(jid)
if not fd: if not fd:
return return
if nick: if nick:
......
...@@ -52,7 +52,7 @@ class Room(TextBuffer): ...@@ -52,7 +52,7 @@ class Room(TextBuffer):
to be to be
""" """
if time is None and self.joined: # don't log the history messages 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): def do_highlight(self, txt, time, nickname):
""" """
......
...@@ -43,6 +43,7 @@ from sleekxmpp.xmlstream.stanzabase import JID ...@@ -43,6 +43,7 @@ from sleekxmpp.xmlstream.stanzabase import JID
from config import config from config import config
from roster import RosterGroup, roster from roster import RosterGroup, roster
from contact import Contact, Resource from contact import Contact, Resource
from logger import logger
import multiuserchat as muc import multiuserchat as muc
class Tab(object): class Tab(object):
...@@ -655,6 +656,7 @@ class PrivateTab(ChatTab): ...@@ -655,6 +656,7 @@ class PrivateTab(ChatTab):
def command_say(self, line): def command_say(self, line):
muc.send_private_message(self.core.xmpp, self.get_name(), 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) 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): def command_unquery(self, arg):
""" """
...@@ -1034,6 +1036,7 @@ class ConversationTab(ChatTab): ...@@ -1034,6 +1036,7 @@ class ConversationTab(ChatTab):
def command_say(self, line): def command_say(self, line):
muc.send_private_message(self.core.xmpp, self.get_name(), 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) 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): def command_unquery(self, arg):
self.core.close_tab() 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