From 11a8ed10e7b4a895c7b854609fe0470e4db6e512 Mon Sep 17 00:00:00 2001 From: silentwings <3885930+silentwings@users.noreply.github.com> Date: Wed, 19 Feb 2020 07:23:01 +0000 Subject: [PATCH] fix #312, SAYFROM part --- SQLUsers.py | 24 ++++++++++++++++-------- protocol/Protocol.py | 9 +++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/SQLUsers.py b/SQLUsers.py index 7d8e83bf..07326865 100755 --- a/SQLUsers.py +++ b/SQLUsers.py @@ -254,15 +254,17 @@ def __repr__(self): Column('id', Integer, primary_key=True), Column('channel_id', Integer, ForeignKey('channels.id', onupdate='CASCADE', ondelete='CASCADE')), Column('user_id', Integer, ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE')), + Column('bridged_id', Integer, ForeignKey('bridged_users.id', onupdate='CASCADE', ondelete='CASCADE'), nullable=True), Column('time', DateTime), Column('msg', Text), Column('ex_msg', Boolean), mysql_charset='utf8', ) class ChannelHistory(object): - def __init__(self, channel_id, user_id, time, msg, ex_msg): + def __init__(self, channel_id, user_id, bridged_id, time, msg, ex_msg): self.channel_id = channel_id self.user_id = user_id + self.bridged_id = bridged_id self.time = time self.msg = msg self.ex_msg = ex_msg @@ -783,21 +785,27 @@ def get_friend_request_list(self, user_id): users = [(req.user_id, req.msg) for req in reqs] return users - def add_channel_message(self, channel_id, user_id, msg, ex_msg, date=None): + def add_channel_message(self, channel_id, user_id, bridged_id, msg, ex_msg, date=None): if date is None: date = datetime.now() - entry = ChannelHistory(channel_id, user_id, date, msg, ex_msg) + entry = ChannelHistory(channel_id, user_id, bridged_id, date, msg, ex_msg) self.sess().add(entry) self.sess().commit() return entry.id def get_channel_messages(self, user_id, channel_id, last_msg_id): # returns a list of channel messages since last_msg_id for the specific userid when he is subscribed to the channel - # [[date, user, msg], [date, user, msg, id], ...] - reqs = self.sess().query(ChannelHistory.time, ChannelHistory.msg, ChannelHistory.ex_msg, User.username, ChannelHistory.id).filter(ChannelHistory.channel_id == channel_id).filter(ChannelHistory.id > last_msg_id).join(User, isouter=True).order_by(ChannelHistory.id).all() - msgs = [(htime, username, msg, ex_msg, id) if username else (htime, 'ChanServ', msg, ex_msg, id) for htime, msg, ex_msg, username, id in reqs ] - if len(msgs)>0: - assert(type(msgs[0][2]) == str) + # [[date, username, msg, id], ...] + res = self.sess().query(ChannelHistory.time, ChannelHistory.msg, ChannelHistory.ex_msg, User.username, BridgedUser.external_username, BridgedUser.location, ChannelHistory.id).filter(ChannelHistory.channel_id == channel_id).filter(ChannelHistory.id > last_msg_id).join(User, isouter=True).join(BridgedUser, isouter=True).order_by(ChannelHistory.id).all() + msgs = [] + for (time, msg, ex_msg, username, external_username, location, id) in res: + if not username: + msgs.append((time, "?", msg, ex_msg, id)) + elif external_username: + bridged_username = external_username + ":" + location + msgs.append((time, bridged_username, msg, ex_msg, id)) + else: + msgs.append((time, username, msg, ex_msg, id)) return msgs class OfflineBridgedClient(): diff --git a/protocol/Protocol.py b/protocol/Protocol.py index 8e846cd3..fd85f1cf 100755 --- a/protocol/Protocol.py +++ b/protocol/Protocol.py @@ -1174,7 +1174,7 @@ def in_SAY(self, client, chan, msg): client.Send('CHANNELMESSAGE %s You are %s.' % (chan, channel.getMuteMessage(client))) return if channel.store_history: - self.userdb.add_channel_message(channel.id, client.user_id, msg, False) + self.userdb.add_channel_message(channel.id, client.user_id, None, msg, False) self._root.broadcast('SAID %s %s %s' % (chan, client.username, msg), chan, set([]), client, 'u') @@ -1211,7 +1211,7 @@ def in_SAYEX(self, client, chan, msg): client.Send('CHANNELMESSAGE %s You are %s.' % (chan, channel.getMuteMessage(client))) return if channel.store_history: - self.userdb.add_channel_message(channel.id, client.user_id, msg, True) + self.userdb.add_channel_message(channel.id, client.user_id, None, msg, True) self._root.broadcast('SAIDEX %s %s %s' % (chan, client.username, msg), chan, set([]), client, 'u') @@ -1417,13 +1417,14 @@ def in_SAYFROM(self, client, chan, location, external_id, msg): if not bridgedClient.bridged_id in channel.bridged_users: self.out_FAILED(client, "SAYFROM", "Bridged user <%s> not present in channel" % bridgedClient.username, False) return + if channel.store_history: + self.userdb.add_channel_message(channel.id, client.user_id, bridgedClient.bridged_id, msg, False) + self._root.broadcast('SAIDFROM %s %s %s' % (chan, bridgedClient.username, msg), chan, set([]), client, 'u') # backwards compat msg = '<' + bridgedClient.username + '> ' + msg self._root.broadcast('SAID %s %s %s' % (chan, client.username, msg), chan, set([]), client, None, 'u') - if channel.store_history: #fixme for bridged clients - self.userdb.add_channel_message(channel.id, client.user_id, msg, False) def in_IGNORE(self, client, tags):