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")
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!")
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")
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")