Beispiel #1
0
def message(message_id, is_sended=False):

    try:

        message = Message.find_by_id(message_id)

        if message is None:
            pass

        if message.readed_by_reciver is False and is_sended is False and session[
                '_id'] in message.reciver_id and message.readed_date is None:
            message.readed_by_reciver = True
            message.readed_date = datetime.datetime.now()
            message.save_to_mongo()
            message.update_to_elastic()

        sender_nickname = User.find_by_id(message.sender_id).nick_name
        if type(message.reciver_id) is list:
            reciver_nickname = []
            for reciver in message.reciver_id:
                reciver_nickname.append(User.find_by_id(reciver).nick_name)

        else:
            reciver_nickname = User.find_by_id(message.reciver_id).nick_name

        if message.is_a_noteOBJ:
            try:
                note = Note.find_by_id(message.content)
            except:
                note = None
        else:
            note = None
        resp = make_response(
            render_template('messages/message.html',
                            message=message,
                            sender_nickname=sender_nickname,
                            reciver_nickname=reciver_nickname,
                            is_a_note=message.is_a_noteOBJ,
                            note=note,
                            join_group_redirect_info=','.join(
                                [message_id, message.is_invtation])))

        return resp

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(error_msg=''.join(error_msg),
                           error_location='message message reading')
        Error_obj.save_to_mongo()

        return render_template('base_htmls/error_page.html',
                               error_msgr='Crashed during reading message...')
def delete_message(message_id):
    try:
        message = Message.find_by_id(message_id)

        message.delete()
        return redirect(url_for('.my_recived_messages',
                                user_id=session['_id']))

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(error_msg=''.join(error_msg),
                           error_location='delete_message message deleting')
        Error_obj.save_to_mongo()
        return render_template(
            'error_page.html',
            error_msgr='Crashed during deleteing your message...')
def message(message_id, is_sended=False):

    try:

        message = Message.find_by_id(message_id)

        if message is None:
            return 'There was an server error. Please try again a another time!'

        if message.readed_by_reciver is False and is_sended is False and session[
                '_id'] in message.reciver_id and message.readed_date is None:
            message.readed_by_reciver = True
            message.readed_date = datetime.datetime.now()
            message.save_to_mongo()

        sender_nickname = User.find_by_id(message.sender_id).nick_name
        if type(message.reciver_id) is list:
            reciver_nickname = []
            for reciver in message.reciver_id:
                reciver_nickname.append(User.find_by_id(reciver).nick_name)

        else:
            reciver_nickname = User.find_by_id(message.reciver_id).nick_name

        return render_template('messages/message.html',
                               message=message,
                               sender_nickname=sender_nickname,
                               reciver_nickname=reciver_nickname)

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(error_msg=''.join(error_msg),
                           error_location='message message reading')
        Error_obj.save_to_mongo()

        return render_template('error_page.html',
                               error_msgr='Crashed during reading message...')
Beispiel #4
0
def delete_message(message_id):
    try:
        message = Message.find_by_id(message_id)
        message.delete_on_elastic()
        message.delete()

        # flash('Your message has successfully deleted.')
        flash(
            '{ "message":"Your message has successfully deleted.", "type":"success" , "captaion":"Delete Success", "icon_id": "far fa-check-circle"}'
        )

        return redirect(url_for('.my_recived_messages',
                                user_id=session['_id']))

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(error_msg=''.join(error_msg),
                           error_location='delete_message message deleting')
        Error_obj.save_to_mongo()
        return render_template(
            'base_htmls/error_page.html',
            error_msgr='Crashed during deleteing your message...')
Beispiel #5
0
def join_group_(list_):
    list__ = list_.split(',')
    user_ = User.find_by_id(session['_id'])
    # saving group with user id

    group_ = Group.find_by_id(list__[1])

    # checking if user can join group
    if group_ is None:
        # flash('The group you want to join does not exist!')
        flash(
            '{ "message":"The group you want to join does not exist!", "type":"error" , "captaion":"Group Find Error", "icon_id": "fas fa-exclamation-triangle"}'
        )
        return redirect(url_for('groups.groups'))
    # checking if user had alerady joined group
    if session['_id'] in group_.members:
        # flash('You\'ve already joined this group!')
        flash(
            '{ "message":"You\'ve already joined this group!", "type":"info" , "captaion":"Group Join", "icon_id": "fas fa-question-circle"}'
        )
        return redirect(url_for('groups.group', group_id=group_._id))

    if user_.group_id is not None:
        # flash('You\'ve already joined a group. If you want to join this group, please secession the other group.')
        flash(
            '{ "message":"You\'ve already joined a group. If you want to join this group, please secession the other group.", "type":"warning" , "captaion":"Group Join Error", "icon_id": "fas fa-exclamation-triangle"}'
        )
        return redirect(url_for('groups.group', group_id=group_._id))

    else:

        if len(group_.members) >= 25:
            # flash('Sorry, this group\'s member amount has reached it\'s limit!')
            flash(
                '{ "message":"Sorry, this group\'s member amount has reached it\'s limit!", "type":"info" , "captaion":"Group Join", "icon_id": "fas fa-question-circle"}'
            )

            return redirect(url_for('groups.groups'))

        group_.members.extend([session['_id']])
        group_.save_to_elastic()
        group_.save_to_mongo()

        # saving to user database
        user_.group_id = group_._id
        user_.save_to_mongo()
        # flash('Joined group successfully')
        flash(
            '{ "message":"Joined group successfully", "type":"success" , "captaion":"Group Join", "icon_id": "fas fa-info-circle"}'
        )

    # if invatation, then remove the message and flash a message
    message = Message.find_by_id(list__[0])
    message.delete_on_elastic()
    message.delete()

    # adding to group alerts - to alert users that someone joined

    notifi = Notification(title='User {} has joined'.format(user_.nick_name),
                          content='',
                          target=group_._id,
                          type='to_group')
    notifi.save_to_mongo()

    # adding group _id to session
    session['group_id'] = group_._id

    # flashing
    # flash('Your invitation has expired.')
    flash(
        '{ "message":"Your invitation has expired.", "type":"info" , "captaion":"Invitation Expired", "icon_id": "fas fa-info-circle"}'
    )

    # redirecting

    return redirect(url_for('.group', group_id=list__[1]))