예제 #1
0
 async def create_message(self, ctx):
     user = ctx.user
     ws = ctx.extensions.get('ws')
     snowflake = ctx.services.get('snowflake')
     websocket = ctx.services.get('websocket')
     try:
         channel = Channel.nodes.first_or_none(uid=kwargs['url_data']['channel.id'])
     except KeyError:
         raise web.HTTPBadRequest()
     if not channel:
         raise web.HTTPBadRequest()
     board = channel.board_parent.single()
     role_uid = board.subscribers.relationship(user).role
     role = Role.nodes.first_or_none(uid=role_uid)
     if not role:
         raise web.HTTPBadRequest()
     if (role.permissions & 8 == 8) or (role.permissions & 2048 == 2048):
         message_data = ctx.sent_data
         content = message_data['content']
     if content == '':
         raise web.HTTPBadRequest()
     new_message = Message(uid=await snowflake(), content=content)
     new_message.save()
     new_message.author.connect(user)
     new_message.channel.connect(channel)
     await ws.event(EventType.MESSAGE_CREATE, board.subscribers, message=new_message)
     return ctx.respond(jsonify(new_message))
예제 #2
0
def group_chat(id_=None):
    form = MessageForm()
    if request.method == 'POST':
        content = form.data.content
        send2 = form.data.send2
        send2user = User.get_or_404(id=send2)
        message = Message(create_by=current_user.id,
                          content=content,
                          send2=send2)
        message.save()
    msgs = Message.objects(send2=id_)
    return render_template('/group_chat.html', msgs=msgs, form=form)