mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-07-07 02:10:58 +02:00
fix(dm): refresh mc.contacts on approve, DB name fallback, relink orphans
Three fixes for DM sending after contact delete/re-add: 1. approve_contact() now calls ensure_contacts() to refresh mc.contacts so send_dm can find newly added contacts immediately 2. cli.send_dm() falls back to DB name lookup when mc.contacts misses, preventing the contact name from being passed as a pubkey string 3. approve_contact() re-links orphaned DMs (NULL contact_pubkey from ON DELETE SET NULL) back to the re-added contact New DB methods: get_contact_by_name(), relink_orphaned_dms() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+13
-3
@@ -376,15 +376,25 @@ def send_dm(recipient: str, text: str) -> Tuple[bool, Dict]:
|
||||
|
||||
try:
|
||||
dm = _get_dm()
|
||||
# Try to find contact by name first
|
||||
recipient = recipient.strip()
|
||||
|
||||
# Try to find contact by name in mc.contacts (in-memory)
|
||||
contact = None
|
||||
if dm.mc:
|
||||
contact = dm.mc.get_contact_by_name(recipient.strip())
|
||||
contact = dm.mc.get_contact_by_name(recipient)
|
||||
|
||||
if contact:
|
||||
pubkey = contact.get('public_key', recipient)
|
||||
elif len(recipient) >= 12 and all(c in '0123456789abcdef' for c in recipient.lower()):
|
||||
# Looks like a pubkey/prefix already
|
||||
pubkey = recipient
|
||||
else:
|
||||
pubkey = recipient.strip()
|
||||
# Name not in mc.contacts — try DB lookup
|
||||
db_contact = dm.db.get_contact_by_name(recipient)
|
||||
if db_contact:
|
||||
pubkey = db_contact['public_key']
|
||||
else:
|
||||
pubkey = recipient
|
||||
|
||||
result = dm.send_dm(pubkey, text.strip())
|
||||
return result['success'], result
|
||||
|
||||
Reference in New Issue
Block a user