def handle_broadcast(json: dict, address: tuple, *args, **kwargs): from UI import openDialog if not Data.has_broadcast_received(json.get('id')): Data.add_broadcast_received(json.get('id')) openDialog(json['content'].get('text'), title=f'Broadcast: {json["content"]["src"]}') send_flood(json.get('content'), json.get('type'), json.get('status'), json.get('id'), black_list=[address[0], json['content'].get('src')]) else: print('hbroadcast else')
def handle_query_answer(json: dict, address: tuple, *args, **kwargs): from UI import openDialog content = json['content'] waiting = Data.get_waiting(content['uuid']) if waiting is True: print(f'{content["content"]} has been answered before.') elif isinstance(waiting, dict): rcv_from = waiting['received_from'] if rcv_from: send_query_answer(content, rcv_from) else: openDialog(str(content['data']), title=f'Query Answer: {content["src"]}') else: print('Query has been removed.')
def handle_leave(json: dict, address: tuple, *args, **kwargs): from UI import openDialog Data.leave(address[0]) openDialog(f'{address[0]} left the network!')
def handle_follow(json: dict, address: tuple, *args, **kwargs): from UI import openDialog Data.add_follower(address[0]) openDialog(f'{address[0]} followed you!') send_accept(address)
def handle_accept(json: dict, address: tuple, *args, **kwargs): from UI import openDialog Data.add_following(address[0]) alert_message = f"user {address[0]} followed successfuly" openDialog(alert_message)
def handle_error(json: dict, address: tuple, *args, **kwargs): from UI import openDialog content = json.get('content') alert_message = content.get('text') openDialog(alert_message)