def send_later(): """ This is a flask wrapper for the message_send_later function Parameters: No parameters Returns: (dictionary): A dictionary containing the message_id of the message that was sent. """ data = request.get_json() token = data['token'] channel_id = int(data['channel_id']) message = data['message'] time = (data['time_sent']) if len(message) >= 1000: raise InputError(description="Message is too long") if not check_if_channel_exists(channel_id): raise InputError(description="Channel does not exist") if int(time) < int(datetime.datetime.now().replace(tzinfo=timezone.utc).timestamp()): raise InputError(description="Invalid time") if not check_if_user_in_channel_member(token, channel_id): raise AccessError(description="User not member of channel") message_id = message_send_later(token, channel_id, message, time) return dumps(message_id)
def unpin(): """ This is a flask wrapper for the message_unpin function Parameters: No parameters Returns: (dictionary): Empty dictionary. """ data = request.get_json() token = data['token'] message_id = int(data['message_id']) if message_check(message_id) is None: raise InputError(description="Invalid id") message = message_check(message_id) if not message['is_pinned']: raise InputError(description="Already unpinned") if not check_if_user_in_channel_member(token, message['channel_id']): raise AccessError(description="User not member") if not check_if_user_in_channel_owner(token, message['channel_id']): raise AccessError(description="User not Owner") message_unpin(token, message_id) return dumps(message_id)
def c_details(): """ This is a flask wrapper for the channel_details function Parameters: No parameters Returns: (dictionary): A dictionary which contains details about the channel(the name of the channel, owners of the channels and all the members of the channel) """ token = request.args.get('token') channel_id = int(request.args.get('channel_id')) if not channel_check(channel_id): raise InputError(description="channel id not found") if not check_if_user_in_channel_member(token, channel_id): raise AccessError(description="User in channel members not found") return_dict = channel_details(token, channel_id) return dumps(return_dict)
def c_leave(): """ This is a flask wrapper for the channel_leave function Parameters: No parameters Returns: (dictionary): Empty dictionary """ data = request.get_json() channel_id = data['channel_id'] token = data['token'] if channel_check(channel_id) is None: raise InputError(description="Channel invalid id") if not check_if_user_in_channel_member(token, channel_id): raise AccessError(description="User not a member of channel") channel_leave(token, channel_id) return dumps({})
def send(): """ This is a flask wrapper for the message_send function Parameters: No parameters Returns: (dictionary): A dictionary containing the message_id of the message that was sent. """ data = request.get_json() token = data['token'] channel_id = data['channel_id'] message = data['message'] if len(message) >= 1000: raise InputError(description="Message is too long") if not check_if_user_in_channel_member(token, channel_id): raise AccessError(description="User not member of channel") message_id = message_send(token, channel_id, message) return dumps(message_id)
def c_messages(): """ This is a flask wrapper for the channel_messages function Parameters: No parameters Returns: (dictionary): A dictionary containing messages which are between the start value and the end value. This dictionary contains the keys of messages, start and end. """ token = request.args.get('token') ch_id = int(request.args.get('channel_id')) start = int(request.args.get('start')) if not channel_check(ch_id): raise InputError(description="channel id not found") if not check_if_user_in_channel_member(token, ch_id): raise AccessError("User not a member of channel") return_dict = channel_messages(token, ch_id, start) return dumps(return_dict)
def c_join(): """ This is a flask wrapper for the channel_join function Parameters: No parameters Returns: (dictionary): Empty dictionary """ data = request.get_json() channel_id = data['channel_id'] token = data['token'] if channel_check(channel_id) is None: raise InputError(description="Wrong channel ID") if not check_if_channel_is_public(channel_id): raise AccessError(description="Channel is not public") if check_if_user_in_channel_member(token, channel_id): raise AccessError(description="User already member of channel") channel_join(token, channel_id) return dumps({})