Пример #1
0
    def post(self, reciepent, text):
        reciepent = User.get_by_key_name(reciepent)
        sender = User.get_by_key_name(self.fb_uid)

        chatjoin = ChatJoin.get_chat(sender.fb_uid, reciepent.fb_uid)

        message = Message(chatjoin = chatjoin, sender = sender, text = text)
        message.put()

        chatjoin.put()

        chat = Chat(key_name = sender.fb_uid + '|' + reciepent.fb_uid,
                    chatjoin = chatjoin,
                    user = sender,
                    other = reciepent,
                    date = message.date,
                    last_message_text = message.text,
                    read = True)
        chat.put()

        chat = Chat(key_name = reciepent.fb_uid + '|' + sender.fb_uid,
                    chatjoin = chatjoin,
                    user = reciepent,
                    other = sender,
                    date = message.date,
                    last_message_text = message.text,
                    read = False)
        chat.put()

        self.send_message(reciepent.fb_uid, {
            'type' : 'new-chat',
            'chat' : chat,
        })
        return True
Пример #2
0
def messages(request, game_id, round_id, thread_id):
    thread = Thread.get_by_uid(thread_id)
    if thread is None:
        raise Http404

    if not thread.profile_can_view(request.profile):
        return HttpResponse('Unauthorized', status=401)

    if request.method == 'GET':
        since = request.GET.get('since', None)
        return json(Message.get_activities(request.user,
                                           thread,
                                           since=since))

    if request.method == 'POST':

        if not thread.profile_can_create(request.profile):
            return HttpResponse('Unauthorized', status=401)

        content = request.POST.get('content', None)
        if not content:
            return HttpResponse('Method Not Allowed - A message is required', status=405)

        # create the new message
        game = Game.get_by_uid(game_id)
        actor = Role.get_by_profile(game, request.profile)
        message = Message(actor=actor,
                          content=content,
                          thread=thread)
        message.put()
        return json(message)

    return HttpResponse('Method Not Allowed', status=405)