def get(self): """ List all rooms currently available. Hangs until the number of rooms changes. This also works as a poll to keep a user in existence. """ id = self.get_id() user = self.get_user() if user: chat.touch(self.db_conn, user, TTL) try: id, rooms = timeout.with_timeout(TIMEOUT, chat.rooms, self.db_conn, id) #self.headers['Refresh'] = refresh context = { 'refresh': "0; url=?id=%d" % id, 'rooms': rooms } rooms.sort() rooms.reverse() for r in rooms: if r['name'] in shit_chans: rooms.remove(r) return self.render_template('rooms', **context) except timeout.Timeout: return self.redirect('?')
def get(self, room): """ Render 'limit' messages for this room. Should hang if there are no new messages. """ room = urllib2.unquote(room) user = self.get_user() if user: chat.touch(self.db_conn, user, TTL, room) id = self.get_id() try: limit = int(self.get_argument('limit') or 25) except ValueError: limit = 25 try: id, messages = timeout.with_timeout(TIMEOUT, chat.messages, self.db_conn, room, limit=limit, id=id) context = { 'refresh': "0; url=?id=%d#bottom" % id, 'messages': messages, 'room': room } return self.render_template('messages', **context) #self.headers['Refresh'] = refresh except timeout.Timeout: return self.redirect('?#bottom')
def get(self, room): """ Render 'limit' messages for this room. Should hang if there are no new messages. """ room = urllib.parse.unquote(room) user = self.get_user() if user: chat.touch(self.db_conn, user, TTL, room) id = self.get_id() try: limit = int(self.get_argument('limit') or 255) except ValueError: limit = 255 try: id, messages = timeout.with_timeout(TIMEOUT, chat.messages, self.db_conn, room, limit=limit, id=id) context = { 'refresh': "0; url=?id=%d#bottom" % id, 'messages': messages, 'room': room } return self.render_template('messages', **context) #self.headers['Refresh'] = refresh except timeout.Timeout: return self.redirect('?#bottom')
def get(self, room): """ Render the users currently in the room. Hangs if nothing has happened since ID. This also functions as a poll for whether a user is still in a room. """ room = urllib.parse.unquote(room) user = self.get_user() if user: chat.touch(self.db_conn, user, TTL, room) id = self.get_id() try: id, users = timeout.with_timeout(TIMEOUT, chat.users, self.db_conn, room, id=id) #self.headers['Refresh'] = refresh context = { 'room': room, 'users': users, 'refresh': "0; url=?id=%d" % id } return self.render_template('users', **context) except timeout.Timeout: return self.redirect('?')
def get(self): """ List all rooms currently available. Hangs until the number of rooms changes. This also works as a poll to keep a user in existence. """ id = self.get_id() user = self.get_user() if user: chat.touch(self.db_conn, user, TTL) try: id, rooms = timeout.with_timeout(TIMEOUT, chat.rooms, self.db_conn, id) #self.headers['Refresh'] = refresh context = {'refresh': "0; url=?id=%d" % id, 'rooms': rooms} rooms.sort() rooms.reverse() for r in rooms: if r['name'] in shit_chans: rooms.remove(r) return self.render_template('rooms', **context) except timeout.Timeout: return self.redirect('?')
def get(self): """ List all rooms currently available. Hangs until the number of rooms changes. This also works as a poll to keep a user in existence. """ id = self.get_id() user = self.get_user() if user: chat.touch(self.db_conn, user, TTL) try: id, rooms = timeout.with_timeout(TIMEOUT, chat.rooms, self.db_conn, id) # self.headers['Refresh'] = refresh context = {"refresh": "0; url=?id=%d" % id, "rooms": rooms} return self.render_template("rooms", **context) except timeout.Timeout: return self.redirect("?")
def get(self, room): """ Render the users currently in the room. Hangs if nothing has happened since ID. This also functions as a poll for whether a user is still in a room. """ room = urllib2.unquote(room) user = self.get_user() if user: chat.touch(self.db_conn, user, TTL, room) id = self.get_id() try: id, users = timeout.with_timeout(TIMEOUT, chat.users, self.db_conn, room, id=id) # self.headers['Refresh'] = refresh context = {"room": room, "users": users, "refresh": "0; url=?id=%d" % id} return self.render_template("users", **context) except timeout.Timeout: return self.redirect("?")
def post(self): """ Handle a post to the buffer form. """ context = self._get_context() register = self.get_argument('register') message = self.get_argument('message') join = self.get_argument('join') user = context['user'] status = 200 if register: if self.register_user(register): chat.touch(self.db_conn, register, TTL, context['room']) context['user'] = register else: context['error'] = "Name '%s' is taken." % register status = 403 elif not user: context['error'] = 'You are no longer logged in.' status = 403 elif message: if chat.message(self.db_conn, context['room'], user, message): #self.set_status(205) # 205 clears forms. Nobody supports it pass else: context['error'] = "Could not send message." status = 403 # Joining a room changes the frameset and URL, so it requires redirect. elif join: chat.touch(self.db_conn, user, TTL, join) return self.redirect('/%s/' % join) else: pass return self.render_template('buffer', _status_code=status, **context)