def chats(name, n): page_size = 10 chats = Channel.findByName(name).chats.offset(n * page_size).limit(page_size) for i in chats: print(i.content) next_page_url = '/channel/{}/chats/{}'.format(name, n + 1) return render_template('message.html', chats=chats, url=next_page_url)
def text(message): """Sent by a client when the user entered a new message. The message is sent to all people in the room.""" # room = message.get('channel') message['type'] = 'message' message['username'] = current_user().username message['avatar'] = current_user().avatar room = message.get('channel', Channel.default_channel().name) print(message) # Channel.findByName(room).save_chat(Chat(message)) chat = { 'content': message.get('content', ''), 'user': current_user(), 'channel': Channel.findByName(room), } Chat(chat).save() join_room(room) emit('message', message, broadcast=True)