Beispiel #1
0
def message_unreact(token, message_id, react_id):
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()
    message_id = int(message_id)
    react_id = int(react_id)

    check_reaction(react_id)

    u_id = token_to_u_ID(loggedInUsersDB, token)
    channel = get_channel(channelsDB, message_id)

    if not is_inChannel(channelsDB=channelsDB,
                        u_id=u_id,
                        channel_id=channel['channel_id']):
        raise AccessError(
            description='You must be in the channel to unreact to a message!')

    for message in channel['messagesListDict']:
        if message['message_id'] == message_id:
            for reaction in message['reacts']:
                if reaction['react_id'] == react_id:
                    if u_id in reaction['u_ids']:
                        reaction['u_ids'].remove(u_id)
                        reaction['is_this_user_reacted'] = False
                        for userID in reaction['u_ids']:
                            if get_user_permission(userID) < 2:
                                reaction['is_this_user_reacted'] = True
                        return
                    else:
                        raise ValueError(
                            description='You cant unreact a unreacted message!'
                        )
    raise ValueError("Error unreacting")
Beispiel #2
0
def message_send_later(token, channel_id, message, time_to_send):
    messageQueue = get_global_messageQueue()

    time_to_send = float(time_to_send)
    time_to_send = int(time_to_send)

    if len(message) > 1000:
        raise ValueError(description="Message too long")

    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()
    messageQueue = get_global_messageQueue()

    channel_id = int(channel_id)

    u_id = token_to_u_ID(loggedInUsersDB, token)

    if not is_inChannel(
            channelsDB=channelsDB, u_id=u_id, channel_id=channel_id):
        raise AccessError(
            description='You must join the channel to send a message!')

    timeNow = (datetime.datetime.utcnow() -
               datetime.timedelta(seconds=1)).replace(
                   tzinfo=timezone.utc).timestamp()

    if time_to_send < timeNow:
        raise ValueError(description='You selected a time in the past!')

    length = len(messageQueue) + 1
    msgElement = create_message_later(u_id, message, time_to_send, channel_id)
    messageQueue.append(msgElement)
    # This is just temporary; it will get updated once the message actually sends
    return {'message_id': length}
def channel_name_change(token, channel_id, name):
    registeredUsersDB = get_global_registeredUsers()
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = load_channel()

    check_valid_channel_name(name)
    email = token_to_email(token)
    if not is_loggedIn(loggedInUsersDB, email):
        raise AccessError(
            description="You must be logged in to change the name of a channel!"
        )

    u_id = token_to_u_ID(loggedInUsersDB, token)
    u_id = int(u_id)
    channel_id = int(channel_id)
    if not is_inChannel(
            u_id=u_id, channel_id=channel_id, channelsDB=channelsDB):
        raise AccessError(
            description=
            'You must be in the channel to change the name of a channel!')
    for channel in channelsDB:
        if channel['channel_id'] == channel_id:
            for owner in channel['owner_members']:
                if u_id == owner['u_id']:
                    channel['name'] = name
                    save_channel()
                    return {}
    raise AccessError(
        description=
        'You must be an owner of the channel to change the name of the channel!'
    )
def channel_delete(token, channel_id):
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()

    email = token_to_email(token)
    if not is_loggedIn(loggedInUsersDB, email):
        raise AccessError(
            description="You must be in a channel to delete a channel!")

    u_id = token_to_u_ID(loggedInUsersDB, token)
    u_id = int(u_id)
    channel_id = int(channel_id)

    if not is_inChannel(
            u_id=u_id, channel_id=channel_id, channelsDB=channelsDB):
        raise AccessError(
            description='You must be in the channel to delete a channel!')

    for channel in channelsDB:
        if channel['channel_id'] == channel_id:
            for owner in channel['owner_members']:
                if u_id == owner['u_id']:
                    channelsDB.remove(channel)
                    save_channel()
                    return {}

    raise ValueError(description='You must be an owner to delete the channel!')
def standup_send(token, channel_id, message):
	registeredUsersDB = get_global_registeredUsers()
	loggedInUsersDB = get_global_loggedInUsers()
	channelsDB = get_global_existingChannels()

	email = token_to_email(token)
	if not is_loggedIn(loggedInUsersDB, email):
		raise AccessError(description="Unauthorised Access")	
	
	channel_id = int(channel_id)
	channel = getChannel(channelsDB, channel_id)
	u_id = token_to_u_ID(loggedInUsersDB, token)

	if not channel['is_standup_running']:
		raise ValueError(description="No standup is running")
	if len(message) > 1000: 
		raise ValueError(description="Message too long")


	if not is_inChannel(channelsDB,channel_id, u_id):
		raise AccessError(description='You must be in a channel to send a standup')


	handle = get_user_handle(registeredUsersDB, u_id)

	message = handle + ' : ' + message +'\n'
	for standup in channel['standups']:
		if standup['isActive']:

			standup['messages'] += message
			
	return {}
Beispiel #6
0
def message_send(token, channel_id, message, time_sent):
    if len(message) > 1000:
        raise ValueError(description="Message too long")

    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()

    channel_id = int(channel_id)

    u_id = token_to_u_ID(loggedInUsersDB, token)

    if not is_inChannel(
            channelsDB=channelsDB, u_id=u_id, channel_id=channel_id):
        raise AccessError(
            description='You must join the channel to send a message!')
    return send_message_help(u_id, channel_id, message, time_sent)
Beispiel #7
0
def message_unpin(token, message_id):
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()

    message_id = int(message_id)
    u_id = token_to_u_ID(loggedInUsersDB, token)
    channel = get_channel(channelsDB, message_id)

    if not is_inChannel(channelsDB=channelsDB,
                        u_id=u_id,
                        channel_id=channel['channel_id']):
        raise AccessError(
            description='You must be in the channel to unpin a message!')

    for owner in channel['owner_members']:
        if u_id == owner['u_id']:
            return unpin_message(channel, message_id)
    for member in channel['other_members']:
        if u_id == member['u_id']:
            raise AccessError(
                description="You must be an owner of the channel to unpin!")
Beispiel #8
0
def message_edit(token, message_id, editMessage):
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()
    message_id = int(message_id)

    if len(editMessage) > 1000:
        raise ValueError(description="Message too long")

    u_id = token_to_u_ID(loggedInUsersDB, token)
    channel = get_channel(channelsDB, message_id)

    if not is_inChannel(channelsDB=channelsDB,
                        u_id=u_id,
                        channel_id=channel['channel_id']):
        raise AccessError(
            description='You must be in the channel to edit a message!')

    for message in channel['messagesListDict']:
        if message['message_id'] == message_id:
            if message['u_id'] == u_id:
                if editMessage.isspace():
                    message_remove(token, message_id)
                else:
                    message['message'] = editMessage
                return {}
            else:
                for owner in channel['owner_members']:
                    if u_id == owner['u_id']:
                        if editMessage.isspace():
                            message_remove(token, message_id)
                        else:
                            message['message'] = editMessage
                        return {}
                raise AccessError(
                    description=
                    "You did not write this message. You need to be an owner of the channel to edit a message you did not write!"
                )

    raise ValueError(description="Error editting")
Beispiel #9
0
def message_remove(token, message_id):

    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()
    message_id = int(message_id)

    u_id = token_to_u_ID(loggedInUsersDB, token)
    channel = get_channel(channelsDB, message_id)
    if not is_inChannel(channelsDB=channelsDB,
                        u_id=u_id,
                        channel_id=channel['channel_id']):
        raise AccessError(
            description='You must be in the channel to remove a message!')

    for message in channel['messagesListDict']:
        if message['message_id'] == message_id:
            if message['u_id'] == u_id:
                channel['messagesListDict'].remove(message)
                return {}
            for owner in channel['owner_members']:
                if u_id == owner['u_id']:
                    channel['messagesListDict'].remove(message)
                    return {}
    raise AccessError(description="You are not allowed to remove this message")