Skip to content

Commit

Permalink
part of #183: remove SUBSCRIBE/UNSUBSCRIBE/LISTSUBSCRIPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
abma committed Oct 11, 2017
1 parent 6f4565e commit 53ae71d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 81 deletions.
3 changes: 0 additions & 3 deletions SQLUsers.py
Expand Up @@ -816,9 +816,6 @@ def add_channel_message(self, channel_id, user_id, msg, date = None):
#returns a list of channel messages since starttime for the specific userid when he is subscribed to the channel
# [[date, user, msg], [date, user, msg], ...]
def get_channel_messages(self, user_id, channel_id, starttime):
entry = self.sess().query(ChannelHistorySubscription).filter(ChannelHistorySubscription.channel_id == channel_id).filter(ChannelHistorySubscription.user_id == user_id).first()
if not entry:
return []
reqs = self.sess().query(ChannelHistory, User).filter(ChannelHistory.channel_id == channel_id).filter(ChannelHistory.time >= starttime).filter(ChannelHistory.user_id == User.id).all()
msgs = [(history.time, user.username, history.msg) for history, user in reqs ]
if len(msgs)>0:
Expand Down
80 changes: 2 additions & 78 deletions protocol/Protocol.py
Expand Up @@ -98,11 +98,6 @@
'FRIENDLIST',
'FRIENDREQUESTLIST',
########
# channel subscriptions
'SUBSCRIBE',
'UNSUBSCRIBE',
'LISTSUBSCRIPTIONS',
########
# meta
'CHANGEPASSWORD',
'GETINGAMETIME',
Expand Down Expand Up @@ -1034,8 +1029,8 @@ def in_SAY(self, client, chan, params):
user.Send(newout)
else:
user.Send(oldout)
#if channel.store_history:
# self.userdb.add_channel_message(channel.id, client.db_id, msg)
if channel.store_history:
self.userdb.add_channel_message(channel.id, client.db_id, msg)

def in_SAYEX(self, client, chan, msg):
'''
Expand Down Expand Up @@ -1449,23 +1444,6 @@ def in_JOIN(self, client, chan, key=None):
elif client.compat['et']: # supports sendEmptyTopic
client.Send('NOCHANNELTOPIC %s' % chan)

if not channel.store_history:
return
msgs = self.userdb.get_channel_messages(client.db_id, channel.id, client.last_login)
if client.compat['o']:
for msg in msgs:
client.Send("SAID " + self._dictToTags( { "chanName": chan, "time": msg[0].isoformat(), "userName": msg[1], "msg": msg[2]} ))
else:
for msg in msgs:
client.Send("SAID %s %s %s" %(chan, msg[1], msg[2]))

# disabled because irc bridge spams JOIN commands
#
# a user can rejoin a channel to get the topic while in it
#topic = channel.topic
#if topic and user in channel.users:
# client.Send('CHANNELTOPIC %s %s %s %s'%(chan, topic['user'], topic['time'], topic['text']))

def in_SETCHANNELKEY(self, client, chan, key='*'):
'''
Lock target channel with a password, or unlocks target channel.
Expand Down Expand Up @@ -2989,60 +2967,6 @@ def in_CHANGEEMAIL(self, client, newmail = None, username = None):
self.userdb.save_user(user)
self.out_SERVERMSG(client,"changed email to %s"%(user.email))

def in_SUBSCRIBE(self, client, subscribeargs):
args = self._parseTags(subscribeargs)
if not 'chanName' in args:
self.out_FAILED(client, "SUBSCRIBE", "chanName missing")
return
chan = args['chanName']
good, reason = self._validChannelSyntax(chan)
if not good:
self.out_FAILED(client, "SUBSCRIBE", reason)
return

if chan not in self._root.channels:
self.out_FAILED(client, "SUBSCRIBE", "Channel %s doesn't exist" %(chan))
return

channel = self._root.channels[chan]
if not channel.store_history:
self.out_FAILED(client, "SUBSCRIBE", "History for channel %s is disabled, can't subscribe!" %(chan))
return
good, reason = self.userdb.add_channelhistory_subscription(channel.id, client.db_id)
if not good:
self.out_FAILED(client, "SUBSCRIBE", reason)
return
self.out_OK(client, "SUBSCRIBE")

def in_UNSUBSCRIBE(self, client, subscribeargs):
args = self._parseTags(subscribeargs)
if not 'chanName' in args:
self.out_FAILED(client, "UNSUBSCRIBE", "chanName missing")
return
chan = args['chanName']
good, reason = self._validChannelSyntax(chan)
if not good:
self.out_FAILED(client, "UNSUBSCRIBE", reason)
return

if chan not in self._root.channels:
self.out_FAILED(client, "UNSUBSCRIBE", "Channel %s doesn't exist" %(chan))
return

channel = self._root.channels[chan]
good, reason = self.userdb.remove_channelhistory_subscription(channel.id, client.db_id)
if not good:
self.out_FAILED(client, "UNSUBSCRIBE", reason)
return
self.out_OK(client, "UNSUBSCRIBE")

def in_LISTSUBSCRIPTIONS(self, client):
subscriptions = self.userdb.get_channel_subscriptions(client.db_id)
client.Send("STARTLISTSUBSCRIPTION")
for chan in subscriptions:
client.Send("LISTSUBSCRIPTION chanName=%s" % (chan))
client.Send("ENDLISTSUBSCRIPTION")

def in_STARTTLS(self, client):
#deprecated
client.StartTLS()
Expand Down

0 comments on commit 53ae71d

Please sign in to comment.