fix so we mark new jids if they are room as room-type

This commit is contained in:
Nikos Kouremenos 2005-11-26 00:03:09 +00:00
parent 7ad4ff2878
commit c311183d57
2 changed files with 24 additions and 14 deletions

View file

@ -140,7 +140,7 @@ def visit(arg, dirname, filenames):
for filename in filenames: for filename in filenames:
# Don't take this file into account, this is dup info # Don't take this file into account, this is dup info
# notifications are also in contact log file # notifications are also in contact log file
if filename == 'notify.log': if filename in ('notify.log', 'readme'):
continue continue
filename = decode_string(filename) filename = decode_string(filename)
if not filename: if not filename:
@ -150,14 +150,14 @@ def visit(arg, dirname, filenames):
continue continue
jid = get_jid(dirname, filename) jid = get_jid(dirname, filename)
if filename == os.path.basename(dirname): # gajim@conf/gajim@conf then gajim@conf is type room if filename == os.path.basename(dirname): # gajim@conf/gajim@conf then gajim@conf is type room
type = constants.JID_ROOM_TYPE type = constants.JID_ROOM_TYPE
print 'marking jid as of type room' print 'Processing', jid, 'of type room'
else: else:
type = constants.JID_NORMAL_TYPE type = constants.JID_NORMAL_TYPE
print 'marking jid as of type normal' print 'Processing', jid, 'of type normal'
print 'Processing', jid
# jid is already in the DB, don't create a new row, just get his jid_id # jid is already in the DB, don't create a new row, just get his jid_id
if jid in jids_already_in: if jid in jids_already_in:
cur.execute('SELECT jid_id FROM jids WHERE jid = "%s"' % jid) cur.execute('SELECT jid_id FROM jids WHERE jid = "%s"' % jid)

View file

@ -118,25 +118,31 @@ class Logger:
(possible_room_jid, constants.JID_ROOM_TYPE)) (possible_room_jid, constants.JID_ROOM_TYPE))
row = cur.fetchone() row = cur.fetchone()
if row is not None: if row is not None:
print 'PM!!'
return True return True
else: else:
print ' NO PM!!'
return False return False
def get_jid_id(self, jid): def get_jid_id(self, jid, typestr = None):
'''jids table has jid and jid_id '''jids table has jid and jid_id
logs table has log_id, jid_id, contact_name, time, kind, show, message logs table has log_id, jid_id, contact_name, time, kind, show, message
so to ask logs we need jid_id that matches our jid in jids table so to ask logs we need jid_id that matches our jid in jids table
this method asks jid and returns the jid_id for later sql-ing on logs this method asks jid and returns the jid_id for later sql-ing on logs
''' '''
if jid.find('/') != -1: # if it has a / if jid.find('/') != -1: # if it has a /
is_pm = self.jid_is_from_pm(jid) jid_is_from_pm = self.jid_is_from_pm(jid)
if not is_pm: # it's normal jid with resource if not jid_is_from_pm: # it's normal jid with resource
jid = jid.split('/', 1)[0] # remove the resource jid = jid.split('/', 1)[0] # remove the resource
if jid in self.jids_already_in: # we already have jids in DB if jid in self.jids_already_in: # we already have jids in DB
cur.execute('SELECT jid_id FROM jids WHERE jid="%s"' % jid) cur.execute('SELECT jid_id FROM jids WHERE jid="%s"' % jid)
jid_id = cur.fetchone()[0] jid_id = cur.fetchone()[0]
else: # oh! a new jid :), we add it now else: # oh! a new jid :), we add it now
cur.execute('INSERT INTO jids (jid) VALUES (?)', (jid,)) if typestr == 'ROOM':
typ = constants.JID_ROOM_TYPE
else:
typ = constants.JID_NORMAL_TYPE
cur.execute('INSERT INTO jids (jid, type) VALUES (?, ?)', (jid, typ))
con.commit() con.commit()
jid_id = cur.lastrowid jid_id = cur.lastrowid
self.jids_already_in.append(jid) self.jids_already_in.append(jid)
@ -249,9 +255,9 @@ class Logger:
else: else:
time_col = int(float(time.time())) time_col = int(float(time.time()))
jid_id = self.get_jid_id(jid)
kind_col, show_col = self.convert_human_values_to_db_api_values(kind, show) kind_col, show_col = self.convert_human_values_to_db_api_values(kind,
show)
# now we may have need to do extra care for some values in columns # now we may have need to do extra care for some values in columns
if kind == 'status': # we store (not None) time, jid, show, msg if kind == 'status': # we store (not None) time, jid, show, msg
@ -259,13 +265,15 @@ class Logger:
if show is None: if show is None:
show_col = constants.SHOW_ONLINE show_col = constants.SHOW_ONLINE
jid_id = self.get_jid_id(jid)
elif kind == 'gcstatus': elif kind == 'gcstatus':
# status in ROOM (for pm status see status) # status in ROOM (for pm status see status)
if show is None: if show is None:
show_col = constants.SHOW_ONLINE show_col = constants.SHOW_ONLINE
jid, nick = jid.split('/', 1) jid, nick = jid.split('/', 1)
jid_id = self.get_jid_id(jid) # re-get jid_id for the new jid jid_id = self.get_jid_id(jid, 'ROOM') # re-get jid_id for the new jid
contact_name_col = nick contact_name_col = nick
elif kind == 'gc_msg': elif kind == 'gc_msg':
@ -275,8 +283,10 @@ class Logger:
# it's server message f.e. error message # it's server message f.e. error message
# when user tries to ban someone but he's not allowed to # when user tries to ban someone but he's not allowed to
nick = None nick = None
jid_id = self.get_jid_id(jid) # re-get jid_id for the new jid jid_id = self.get_jid_id(jid, 'ROOM') # re-get jid_id for the new jid
contact_name_col = nick contact_name_col = nick
else:
jid_id = self.get_jid_id(jid)
values = (jid_id, contact_name_col, time_col, kind_col, show_col, values = (jid_id, contact_name_col, time_col, kind_col, show_col,
message_col, subject_col) message_col, subject_col)