Ejemplo n.º 1
0
def message_unpin(token, message_id):
    """
    Given a message within a channel, remove it's mark as unpinned.
    """
    u_id = get_current_user(token)
    message_location = get_message_location(message_id)
    message_file = get_message(message_id)

    ################### START ERROR CHECKS ############################

    channel_data = get_channel_data(message_location['channel_id'])

    check = next((i for i in channel_data['member_ids'] if i == u_id), False)

    if check is False:
        raise AccessError(description='The authorised user is not ' +
                          'a member of the channel that the message is within')

    if u_id not in channel_data['owner_ids']:
        raise AccessError(description='The authorised user is not an owner')

    ##################### END ERROR CHECKS ########################

    if message_file['is_pinned'] is False:
        raise InputError(
            description='Message with ID message_id is already unpinned')
    else:
        message_file['is_pinned'] = False
    return {}
Ejemplo n.º 2
0
def message_unreact(token, message_id, react_id):
    """
    Given a message within a channel the authorised user is part of,
    remove a "react" to that particular message.
    """
    # Token check
    u_id = get_current_user(token)

    # React_id check
    if react_id != 1:
        raise InputError(description='react_id is not a valid React ID.' +
                         'The only valid react ID the frontend has is 1')

    # Check user is in channel they are reacting in and if they are,
    # execute.
    if user_in_message_channel(message_id, u_id) is True:
        message_file = get_message(message_id)
        u_id_to_unreact = next(
            (i for i in message_file['reacts'][0]['u_ids'] if u_id == i), None)

        if u_id_to_unreact is not None:
            # If there was a react from the user.
            message_file['reacts'][0]['u_ids'].remove(u_id)
        else:
            # If there wasn't a react from the user.
            raise InputError(
                description='Message with ID message_id does not' +
                'contain an active React with ID react_id')

    return {}
Ejemplo n.º 3
0
def message_react(token, message_id, react_id):
    """
    Given a message within a channel the authorised user is part of,
    add a "react" to that particular message.
    """

    u_id = get_current_user(token)

    # React_id check
    if react_id != 1:
        raise InputError(description='react_id is not a valid React ID.' +
                         'The only valid react ID the frontend has is 1')

    # Check user is in channel they are reacting in and if they are,
    # execute.
    if user_in_message_channel(message_id, u_id) is True:
        message_file = get_message(message_id)
        u_id_to_react = next(
            (i for i in message_file['reacts'][0]['u_ids'] if u_id == i),
            False)

        if u_id_to_react is not False:
            # This user has already reacted.
            raise InputError(description='Message with ID message_id already' +
                             'contains an active React with ID react_id')
        else:
            # User has not already reacted.
            message_file['reacts'][0]['u_ids'].append(u_id)

    return {}
Ejemplo n.º 4
0
def mainloop(InnerFun, timeout=30, block=['None']):

    people = db.get_contacts()
    [people.remove(i) if i != 'None' else people for i in block]

    while True:
        try:
            for contact in range(1, 18):  #Tener al menos 18 contactos

                db.extract_data(contact)

                if db.newMsg() and db.get_name() in people:  #CHAT FIJADO

                    hl.open_conversation(db.get_xpath_num(contact))
                    text = db.get_message()
                    response = InnerFun(text)

                    hl.write(response, db.get_xpath_num(contact))
                    hl.open_conversation(db.get_xpath_num(contact + 1))

        except:
            hl.refresh()
            hl.wait_until_window(timeout)

            people = db.get_contacts()
            [people.remove(i) if i != 'None' else people for i in block]
Ejemplo n.º 5
0
def get_message(db):

    user_id = users.get_userID(db)
    recipient_id = users.return_userID(db, request.query['username'])

    ret_val = database.get_message(db, user_id, recipient_id)

    return {'data': ret_val}
Ejemplo n.º 6
0
 def wrapper_func(*args, **kwargs):
     """ Wrapper function """
     try:
         msg_arg_index = argspec.args.index("message_id")
         target_message = database.get_message(args[msg_arg_index])
         # Check the u_id is valid.
         if target_message is None:
             # u_id is invalid
             raise error.InputError(
                 description="Message based on ID does not exist")
         else:
             return func(*args, **kwargs)
     except ValueError:
         print("\033[93m" +
               "WARNING: msg_id arg not found - running function " +
               f"{func.__name__} without msg_id check." + "\033[0m")
         return func(*args, **kwargs)