fix: re-prime on chat switch; native Playwright click for profile cards
This commit is contained in:
parent
196acbac47
commit
a7835c3057
@ -180,6 +180,12 @@ class Monitor:
|
||||
_clear_line()
|
||||
print(f"Chat: {current_chat}")
|
||||
last_chat = current_chat
|
||||
if skip_existing:
|
||||
# Neuer Chat — bestehende Nachrichten überspringen
|
||||
try:
|
||||
self.poll_new_messages()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@ -37,23 +37,31 @@ class Resolver:
|
||||
)
|
||||
|
||||
def _extract_email_from_profile(self, display_name: str) -> str | None:
|
||||
# Click the first visible span whose text exactly matches the display name.
|
||||
# Works for both channel meetings (fui-StyledText spans) and meeting chat.
|
||||
clicked = self._page.evaluate("""(name) => {
|
||||
for (const span of document.querySelectorAll('span')) {
|
||||
if (span.textContent.trim() === name && span.offsetParent !== null) {
|
||||
span.click();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}""", display_name)
|
||||
# Use Playwright's native click (real mouse events) to trigger the Teams profile card.
|
||||
# Try multiple selectors that contain the sender's name.
|
||||
selectors = [
|
||||
f"[data-tid='message-author-name']:has-text('{display_name}')",
|
||||
f"[data-tid='reply-message-header'] span:has-text('{display_name}')",
|
||||
f"span:has-text('{display_name}')",
|
||||
]
|
||||
|
||||
clicked = False
|
||||
for selector in selectors:
|
||||
try:
|
||||
loc = self._page.locator(selector).first
|
||||
if loc.is_visible(timeout=1000):
|
||||
loc.click()
|
||||
clicked = True
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if not clicked:
|
||||
print(f" Sender '{display_name}' nicht im Chat gefunden.")
|
||||
return None
|
||||
|
||||
try:
|
||||
# Wait for profile card, then extract email from mailto link
|
||||
self._page.wait_for_selector(_PROFILE_EMAIL_SELECTOR, timeout=5000)
|
||||
email_el = self._page.query_selector(_PROFILE_EMAIL_SELECTOR)
|
||||
email = None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user