mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-08-11 03:02:56 +02:00
fix(contacts): remove from pending list after approve + add reject/clear
approve_contact now removes the contact from mc.pending_contacts after successful approval. Added reject_contact (remove without adding) and clear_pending_contacts methods with API endpoints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -827,11 +827,38 @@ class DeviceManager:
|
||||
last_advert=last_advert_val,
|
||||
source='device',
|
||||
)
|
||||
# Remove from pending list after successful approval
|
||||
self.mc.pending_contacts.pop(pubkey, None)
|
||||
return {'success': True, 'message': 'Contact approved'}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to approve contact: {e}")
|
||||
return {'success': False, 'error': str(e)}
|
||||
|
||||
def reject_contact(self, pubkey: str) -> Dict:
|
||||
"""Reject a pending contact (remove from pending list without adding)."""
|
||||
if not self.is_connected:
|
||||
return {'success': False, 'error': 'Device not connected'}
|
||||
|
||||
try:
|
||||
removed = self.mc.pending_contacts.pop(pubkey, None)
|
||||
if removed:
|
||||
return {'success': True, 'message': 'Contact rejected'}
|
||||
return {'success': False, 'error': 'Contact not in pending list'}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to reject contact: {e}")
|
||||
return {'success': False, 'error': str(e)}
|
||||
|
||||
def clear_pending_contacts(self) -> Dict:
|
||||
"""Clear all pending contacts."""
|
||||
try:
|
||||
count = len(self.mc.pending_contacts) if self.mc and self.mc.pending_contacts else 0
|
||||
if self.mc and self.mc.pending_contacts is not None:
|
||||
self.mc.pending_contacts.clear()
|
||||
return {'success': True, 'message': f'Cleared {count} pending contacts'}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to clear pending contacts: {e}")
|
||||
return {'success': False, 'error': str(e)}
|
||||
|
||||
def get_battery(self) -> Optional[Dict]:
|
||||
"""Get battery status."""
|
||||
if not self.is_connected:
|
||||
|
||||
Reference in New Issue
Block a user