Exemplo n.º 1
0
def search(token, quer_str):
    user = get_user_from_token(token)
    search_result = []
    search_list = []
    channels_dict = channels_list(token)
    for channel in channels_dict:
        search_list.append(channel['channel_id'])

    for channel_id in search_list:
        channel = get_verified_channel_from_id(channel_id, get_channel_list())
        for message in channel.get_mess():
            if quer_str in message.get_message_content():
                message_dict = {
                    'message_id': message.get_message_id(),
                    'u_id': message.get_user_id(),
                    'message': message.get_message_content(),
                    'time_created':
                    int(message.get_time_created().timestamp()),
                    'reacts': [],
                    'is_pinned': message.get_is_pinned()
                }
                message_dict['reacts'] = generate_reacts_dictionary(
                    user, message)
                search_result.append(message_dict)

    return {'messages': search_result}
Exemplo n.º 2
0
def standup_send(token, channel_id, message):
    global list_of_messages
    global end_time

    curr_user = get_user_from_token(token)

    try:
        curr_channel = get_verified_channel_from_id(channel_id,
                                                    get_channel_list())
    except:
        raise ValueError("Channel ID is not a valid channel")

    if curr_user.get_uid() in curr_channel.get_mem_list():
        if (len(message) <= 1000):
            if curr_channel.get_active_standup():
                list_of_messages.append({
                    "handle_str":
                    curr_user.get_handle_str(),
                    "message":
                    message
                })
                return {}
            else:
                raise ValueError("Standup is not active at the moment")
        else:
            raise ValueError("Message is more that 1000 characters")
    else:
        raise AccessError("The user is not a valid user")
Exemplo n.º 3
0
def standup_start(token, channel_id, length):
    global end_time

    sender = get_user_from_token(token)
    sender_uid = sender.get_uid()
    try:
        curr_channel = get_verified_channel_from_id(channel_id,
                                                    get_channel_list())
    except:
        raise ValueError("Channel ID is not a valid channel")

    if sender_uid in curr_channel.get_mem_list():
        if not curr_channel.get_active_standup():

            curr_channel.set_active_standup(True)
            start_time = datetime.now()
            t = Timer(length, standup_output_message, [token, channel_id], {})
            t.start()

            end_time = start_time + timedelta(seconds=length)
            return {'time_finish': int(end_time.timestamp())}
        else:
            raise ValueError("Standup is already running.")
    else:
        raise AccessError("Authorised user is not a member of the channel.")
Exemplo n.º 4
0
def authorized_user(token, channel_id):
    user_id = get_user_from_token(token)
    channel = get_verified_channel_from_id(channel_id, get_channel_list())
    channel_members = channel.get_mem_list()
    for member in channel_members:
        if user_id.get_uid() == member:
            return True
    return False
Exemplo n.º 5
0
def get_channel_from_message(message_id):
    channels = get_channel_list()
    flag = False
    for channel in channels:
        messages = channel.get_mess()

        for message in messages:
            if message_id == message.get_message_id():
                flag = True
                return channel.get_channel_id()
    return None
Exemplo n.º 6
0
def standup_active(token, channel_id):
    global end_time

    if user_valid_token(token) is False:
        raise AccessError("Invalid User Token")

    if get_verified_channel_from_id(channel_id,
                                    get_channel_list()).get_active_standup():
        return {"is_active": True, "time_finish": int(end_time.timestamp())}
    else:
        return {"is_active": False, "time_finish": None}
Exemplo n.º 7
0
 def wrapper(*args, **kwargs):
     channels = get_channel_list()
     message_id = list(args)[1]
     flag = False
     for channel in channels:
         channel_messages = channel.get_mess()
         for message in channel_messages:
             if message_id == message.get_message_id():
                 flag = True
     if flag is False:
         raise ValueError("Message no long exist")
     return function(*args, **kwargs)
Exemplo n.º 8
0
def valid_message_in_channel(user_id, message_id):
    channel_id = get_channel_from_message(message_id)

    if channel_id is None:
        return False

    channel = get_verified_channel_from_id(channel_id, get_channel_list())
    member_list = channel.get_mem_list()

    for member in member_list:
        if user_id == member:
            return True
    return False
Exemplo n.º 9
0
def standup_output_message(token, channel_id):
    global list_of_messages

    get_verified_channel_from_id(channel_id,
                                 get_channel_list()).set_active_standup(False)
    u_id = get_user_from_token(token).get_uid()
    channel = get_verified_channel_from_id(channel_id, get_channel_list())

    output_string = ""

    for dictionary in list_of_messages:
        str1 = dictionary['handle_str']
        str2 = dictionary['message']
        adjusted_string = str1 + ": " + str2 + "\n"
        output_string += adjusted_string
        adjusted_string = ""

    list_of_messages.clear()
    message = Message(set_global_message_id(), u_id, output_string,
                      datetime.now())
    output_string = None
    channel.get_mess().append(message)
Exemplo n.º 10
0
def message_remove(token, message_id):

    user_id = get_user_from_token(token).get_uid()

    message = get_message_from_m_id(message_id)
    channel = get_verified_channel_from_id(
        get_channel_from_message(message_id), get_channel_list())

    if not channel_owner(user_id, channel):
        if not message_poster(user_id, message):
            raise AccessError("Not authorized user of message")

    channel.get_mess().remove(message)
    return {}
Exemplo n.º 11
0
def message_edit(token, message_id, message_str):

    if not user_valid_token(token):
        raise AccessError("User is not a valid user")

    user_id = get_user_from_token(token).get_uid()
    message = get_message_from_m_id(message_id)
    channel = get_verified_channel_from_id(
        get_channel_from_message(message_id), get_channel_list())

    if not channel_owner(user_id, channel):
        if not message_poster(user_id, message):
            raise AccessError("Not authorized user of message")

    message.change_content(message_str)
    return {}
Exemplo n.º 12
0
def message_unpin(token, message_id):
    user_id = get_user_from_token(token).get_uid()

    message = get_message_from_m_id(message_id)
    channel = get_verified_channel_from_id(
        get_channel_from_message(message_id), get_channel_list())

    if not authorized_user(token, channel.get_channel_id()):
        raise AccessError("User is not a member of the channel")

    if not user_valid_token(token):
        raise AccessError("User is not a valid user")

    if not channel_owner(user_id, channel):
        raise ValueError("The user is not an admin")

    if not message.pinned():
        raise ValueError("Message is already unpinned")

    message.unpin_message()
    return {}
Exemplo n.º 13
0
def get_channel_messages(channel_id):
    channel = get_verified_channel_from_id(channel_id, get_channel_list())
    return channel.get_mess()