Skip to content

Commit

Permalink
fix #312, SAYFROM part
Browse files Browse the repository at this point in the history
  • Loading branch information
silentwings committed Feb 19, 2020
1 parent 8cf8dda commit 11a8ed1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
24 changes: 16 additions & 8 deletions SQLUsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
9 changes: 5 additions & 4 deletions protocol/Protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 11a8ed1

Please sign in to comment.