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 remove(): """ This is a flask wrapper for the message_remove function Parameters: No parameters Returns: (dictionary): Empty dictionary """ data = request.get_json() token = data['token'] message_id = int(data['message_id']) message_probe = message_check(message_id) user = token_check(token) if message_probe is None: raise InputError(description="Message not found") if not check_if_user_in_channel_owner(token, message['channel_id']): raise AccessError(description="User not owner") if user['u_id'] != message_probe['user_id']: raise AccessError(description="User not sender") message_remove(token, message_id) return dumps(message_id)
def message_edit(token, message_id, edited_message): """Edits a current message Parameters: token (string) message_id(int) edited_message(string) """ message = message_check(message_id) if message == None: raise InputError is_owner = owner_channel_check(token, message['channel_id']) user = token_check(token) if user == False: raise AccessError is_sender = False #print("message----->",message) if user['u_id'] == message['user_id']: is_sender = True if (is_owner or is_sender) == False: raise AccessError message['message'] = edited_message #message_data = get_messages_store() #message_data['Messages'].remove(message) return {}
def message_remove(token, message_id): """Removes a message Parameters: token (string) message_id(int) """ message = message_check(message_id) if message == None: raise InputError is_owner = owner_channel_check(token, message['channel_id']) user = token_check(token) if user == False: raise AccessError is_sender = False #print("message----->",message) if user['u_id'] == message['user_id']: is_sender = True #print('is owner: ',is_owner,'is_sender:', is_sender) if (is_owner or is_sender) == False: raise AccessError message_data = get_messages_store() message_data['Messages'].remove(message) return {}
def message_react(token, message_id, react_id): """ Reacts to a message Parameters: token (string) message_id(int) react_id(int) """ message = message_check(message_id) if message == None: raise InputError if react_id != 1: #This is assuming that there's only 1 react id (1) raise InputError user = token_check(token) if user == None: raise AccessError if react_check(message_id, user['u_id'], react_id): print("react check input errroorrrrrrrr") raise InputError is_this_user_reacted = False flag = 0 for reacts in message['reacts']: if reacts['react_id'] == react_id: reacts['u_ids'].append(int(user['u_id'])) flag = 1 if reacts['is_this_user_reacted']: is_this_user_reacted = True if message['user_id'] == user['u_id']: is_this_user_reacted = True if flag == 0: dict_append = { 'u_ids': [int(user['u_id'])], 'react_id': int(react_id), 'is_this_user_reacted': is_this_user_reacted } message['reacts'].append(dict_append) return {}
def message_unpin(token, message_id): """Unpins a message Parameters: token (string) message_id(int) """ message = message_check(message_id) if message == None: raise InputError if member_channel_check(token, message['channel_id']) == False: raise AccessError if owner_channel_check(token, message['channel_id']) == False: raise InputError if message['is_pinned'] == False: raise InputError message['is_pinned'] = False return {}
def message_unreact(token, message_id, react_id): """ Removes a react from a message Parameters: token (string) message_id(int) react_id(int) """ message = message_check(message_id) #print("This is message----->", message) if message == None: raise InputError if react_id != 1: #This is assuming that there's only 1 react id (1) raise InputError user = token_check(token) if user == None: raise AccessError if react_check(message_id, user['u_id'], react_id) == False: raise InputError flag = 0 for reacts in message['reacts']: if reacts['react_id'] == react_id: if user['u_id'] in reacts['u_ids']: reacts['u_ids'].remove(user['u_id']) if len(reacts['u_ids']) == 0: flag = 1 if flag == 1: #dict_append = { 'u_ids': user['u_id'], 'react_id' : react_id } for react in message['reacts']: if react_id == react['react_id']: break message['reacts'].remove(react) return {}