コード例 #1
0
ファイル: message.py プロジェクト: samhains/plutoc
def conversation(database, user, admin_user):
    conversation = Conversation(user_id=user.id,
                                from_user_id=user.id,
                                to_user_id=admin_user.id,
                                shared_id=uuid.uuid4())
    conversation.save()
    return conversation
コード例 #2
0
ファイル: forms.py プロジェクト: PPPython/flaskbb
    def save(self, from_user, to_user, user_id, unread, as_draft=False,
             shared_id=None):

        conversation = Conversation(
            subject=self.subject.data,
            draft=as_draft,
            shared_id=shared_id,
            from_user_id=from_user,
            to_user_id=to_user,
            user_id=user_id
        )
        message = Message(message=self.message.data)
        return conversation.save(message=message)
コード例 #3
0
ファイル: forms.py プロジェクト: zming619/flaskbb
    def save(self, from_user, to_user, user_id, unread, as_draft=False,
             shared_id=None):

        conversation = Conversation(
            subject=self.subject.data,
            draft=as_draft,
            shared_id=shared_id,
            from_user_id=from_user,
            to_user_id=to_user,
            user_id=user_id,
            unread=unread
        )
        message = Message(message=self.message.data, user_id=from_user)
        return conversation.save(message=message)
コード例 #4
0
    def post(self, conversation_id):
        conversation = Conversation.query.filter_by(
            id=conversation_id, user_id=current_user.id).first_or_404()

        form = self.form()
        if form.validate_on_submit():
            to_user_id = None
            # If the current_user is the user who recieved the message
            # then we have to change the id's a bit.
            if current_user.id == conversation.to_user_id:
                to_user_id = conversation.from_user_id
                to_user = conversation.from_user
            else:
                to_user_id = conversation.to_user_id
                to_user = conversation.to_user

            form.save(conversation=conversation, user_id=current_user.id)

            # save the message in the recievers conversation
            old_conv = conversation
            conversation = Conversation.query.filter(
                Conversation.user_id == to_user_id,
                Conversation.shared_id == conversation.shared_id).first()

            # user deleted the conversation, start a new conversation with just
            # the recieving message
            if conversation is None:
                conversation = Conversation(subject=old_conv.subject,
                                            from_user=real(current_user),
                                            to_user=to_user,
                                            user_id=to_user_id,
                                            shared_id=old_conv.shared_id)
                conversation.save()

            form.save(conversation=conversation,
                      user_id=current_user.id,
                      unread=True)
            conversation.to_user.invalidate_cache(permissions=False)

            return redirect(
                url_for("message.view_conversation",
                        conversation_id=old_conv.id))

        return render_template("message/conversation.html",
                               conversation=conversation,
                               form=form)
コード例 #5
0
ファイル: views.py プロジェクト: 0xsKu/flaskbb
def view_conversation(conversation_id):
    conversation = Conversation.query.filter_by(
        id=conversation_id,
        user_id=current_user.id
    ).first_or_404()

    if conversation.unread:
        conversation.unread = False
        current_user.invalidate_cache(permissions=False)
        conversation.save()

    form = MessageForm()
    if form.validate_on_submit():

        message_count = Conversation.query.\
            filter(Conversation.user_id == current_user.id).\
            count()

        if message_count >= flaskbb_config["MESSAGE_QUOTA"]:
            flash(_("You cannot send any messages anymore because you have"
                    "reached your message limit."), "danger")
            return redirect(url_for("message.view_conversation",
                                    conversation_id=conversation.id))

        to_user_id = None
        # If the current_user is the user who recieved the message
        # then we have to change the id's a bit.
        if current_user.id == conversation.to_user_id:
            to_user_id = conversation.from_user_id
        else:
            to_user_id = conversation.to_user_id

        form.save(conversation=conversation, user_id=current_user.id)

        # save the message in the recievers conversation
        old_conv = conversation
        conversation = Conversation.query.\
            filter(
                Conversation.user_id == to_user_id,
                Conversation.shared_id == conversation.shared_id
            ).first()

        # user deleted the conversation, start a new conversation with just
        # the recieving message
        if conversation is None:
            conversation = Conversation(
                subject=old_conv.subject,
                from_user_id=current_user.id,
                to_user=to_user_id,
                user_id=to_user_id,
                shared_id=old_conv.shared_id
            )
            conversation.save()

        form.save(conversation=conversation, user_id=current_user.id,
                  unread=True)

        return redirect(url_for("message.view_conversation",
                                conversation_id=old_conv.id))

    return render_template("message/conversation.html",
                           conversation=conversation, form=form)
コード例 #6
0
ファイル: views.py プロジェクト: yonglehou/flaskbb
def view_conversation(conversation_id):
    conversation = Conversation.query.filter_by(
        id=conversation_id,
        user_id=current_user.id
    ).first_or_404()

    if conversation.unread:
        conversation.unread = False
        conversation.save()

    form = MessageForm()
    if form.validate_on_submit():

        message_count = Conversation.query.\
            filter(Conversation.user_id == current_user.id).\
            count()

        if message_count >= flaskbb_config["MESSAGE_QUOTA"]:
            flash(_("You cannot send any messages anymore because you have"
                    "reached your message limit."), "danger")
            return redirect(url_for("message.view_conversation",
                                    conversation_id=conversation.id))

        to_user_id = None
        # If the current_user is the user who recieved the message
        # then we have to change the id's a bit.
        if current_user.id == conversation.to_user_id:
            to_user_id = conversation.from_user_id
        else:
            to_user_id = conversation.to_user_id

        form.save(conversation=conversation, user_id=current_user.id)

        # save the message in the recievers conversation
        old_conv = conversation
        conversation = Conversation.query.\
            filter(
                Conversation.user_id == to_user_id,
                Conversation.shared_id == conversation.shared_id
            ).first()

        # user deleted the conversation, start a new conversation with just
        # the recieving message
        if conversation is None:
            conversation = Conversation(
                subject=old_conv.subject,
                from_user_id=current_user.id,
                to_user=to_user_id,
                user_id=to_user_id,
                shared_id=old_conv.shared_id
            )
            conversation.save()

        form.save(conversation=conversation, user_id=current_user.id,
                  unread=True)

        return redirect(url_for("message.view_conversation",
                                conversation_id=old_conv.id))

    return render_template("message/conversation.html",
                           conversation=conversation, form=form)