def test_message_react(message_init): m_id = message_send(message_init[0]['token'], message_init[2], "message")['message_id'] message_react(message_init[0]['token'], m_id, 1) database = DataBase() assert message_init[0]['u_id'] in database.get_channel_messages( message_init[2])[int(str(m_id)[5:10])]['reacts'][0]['u_ids']
def test_message_pin(message_init): m_id = message_send(message_init[0]['token'], message_init[2], "message")['message_id'] message_pin(message_init[0]['token'], m_id) database = DataBase() assert database.get_channel_messages(message_init[2])[int( str(m_id)[5:10])]['is_pinned'] == True
def test_message_sendlater_with_fomatted_time(message_init): m_id = message_sendlater( message_init[0]['token'], message_init[2], "message", str(datetime.datetime.now().replace(microsecond=0) + datetime.timedelta(seconds=2)))['message_id'] database = DataBase() assert database.get_channel_messages(message_init[2])[int( str(m_id)[5:10])]['message_id'] == m_id
def test_message_edit(message_init): m_id = message_send(message_init[0]['token'], message_init[2], "message")['message_id'] # Edited message_edit(message_init[0]['token'], m_id, "edited") # Deleted message_edit(message_init[0]['token'], m_id, "") database = DataBase() assert len(database.get_channel_messages(message_init[2])) == 0
def test_message_pin_remote(url, message_init): m_id = message_send(message_init[0]['token'], message_init[2], "message")['message_id'] requests.post(f'{url}message/pin', json={ 'token': message_init[0]['token'], 'message_id': m_id, }) database = DataBase() assert database.get_channel_messages(message_init[2])[int( str(m_id)[5:10])]['is_pinned'] == True
def test_message_react_remote(url, message_init): m_id = message_send(message_init[0]['token'], message_init[2], "message")['message_id'] requests.post(f'{url}message/react', json={ 'token': message_init[0]['token'], 'message_id': m_id, 'react_id': 1 }) database = DataBase() assert message_init[0]['u_id'] in database.get_channel_messages( message_init[2])[int(str(m_id)[5:10])]['reacts'][0]['u_ids']
def message_remove(token, message_id): """ Remove message in channel """ database = DataBase() user_id = database.get_account_info(token)['u_id'] channel_id = str(message_id) channel_id = NO_CHANNELS - int(channel_id[0:5]) channel = database.get_channel_info(channel_id) channel_msgs = database.get_channel_messages(channel_id) message_user_id = int(str(message_id)[10:]) # Check users allowed to delete messages if user_id not in channel['owners_id'] and user_id != message_user_id: raise AccessError('Not a member of channel') # Check if message exists to delete in list message_index = find_message_index(message_id, channel_msgs) channel_msgs.pop(message_index) database.close() return {}
def message_react(token, message_id, react_id): """ Let users react to messages. """ database = DataBase() channel_id = str(message_id) channel_id = NO_CHANNELS - int(channel_id[0:5]) channel_msgs = database.get_channel_messages(channel_id) message_index = find_message_index(message_id, channel_msgs) msg = channel_msgs[message_index] channel_member_id = database.get_account_info(token)['u_id'] if react_id != 1 or channel_member_id in msg['reacts'][react_id-1]['u_ids']: raise InputError # Add react react = channel_msgs[message_index]['reacts'][react_id - 1] react['is_this_user_reacted'] = True react['u_ids'].append(database.get_account_info(token)['u_id']) database.close() return {}
def message_unpin(token, message_id): """ Unpin messages. """ database = DataBase() channel_id = str(message_id) channel_id = NO_CHANNELS - int(channel_id[0:5]) channel_msgs = database.get_channel_messages(channel_id) message_index = find_message_index(message_id, channel_msgs) # Error checking msg = channel_msgs[message_index] channel = database.get_channel_info(channel_id) channel_member_id = database.get_account_info(token)['u_id'] if channel_member_id not in channel['members_id']: raise AccessError('Not a member in the channel') if not msg['is_pinned']: raise InputError('Message is already unpinnned') # Unpin messages channel_msgs[message_index]['is_pinned'] = False database.close() return {}
def message_unreact(token, message_id, react_id): """ User unreacts to message. """ database = DataBase() channel_id = str(message_id) channel_id = NO_CHANNELS - int(channel_id[0:5]) channel_msgs = database.get_channel_messages(channel_id) message_index = find_message_index(message_id, channel_msgs) #Error checking msg = channel_msgs[message_index] channel_member_id = database.get_account_info(token)['u_id'] if react_id != 1 or channel_member_id not in msg['reacts'][react_id-1]['u_ids']: raise InputError('Not valid react or member hasn\'t reacted') react = msg['reacts'][react_id - 1] if not react['is_this_user_reacted']: raise InputError('No reacts have been made') #Implementation react['u_ids'].remove(database.get_account_info(token)['u_id']) if not react['u_ids']: react['is_this_user_reacted'] = False database.close() return {}