Browse Source

Fix auto-stop recording for scheduled Meet URLs

Make meeting-code extraction robust to trailing slashes/segments so scheduled and code/link joins reliably start the Meet lifecycle monitor and stop recording when the meeting ends.

Co-authored-by: Cursor <cursoragent@cursor.com>
huzaifahayat12 2 months ago
parent
commit
29a48868fb
1 changed files with 18 additions and 7 deletions
  1. 18 7
      meetings_app/ViewController.swift

+ 18 - 7
meetings_app/ViewController.swift

@@ -4347,18 +4347,29 @@ private extension ViewController {
 
     private func aiCompanionMeetMeetingCode(from meetURL: URL) -> String? {
         // Typical: https://meet.google.com/abc-defg-hij
+        // But scheduled events can include trailing slashes and extra segments/query params.
         guard let host = meetURL.host?.lowercased(),
               host == "meet.google.com" || host.hasSuffix(".meet.google.com") else { return nil }
 
-        let codeCandidate = meetURL.pathComponents.filter { !$0.isEmpty }.last
-        guard let codeCandidate else { return nil }
+        // Prefer path segments (ignoring the "/" components that URL.pathComponents includes).
+        let rawSegments = meetURL.pathComponents
+            .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
+            .filter { $0.isEmpty == false && $0 != "/" }
 
-        // Allow flexible token shapes; Meet codes are usually 3 hyphen-separated chunks.
-        let cleaned = codeCandidate.trimmingCharacters(in: .whitespacesAndNewlines)
-        let parts = cleaned.split(separator: "-")
-        guard parts.count >= 3 else { return nil }
+        for segment in rawSegments {
+            if isValidMeetMeetingCode(segment) {
+                return segment.lowercased()
+            }
+        }
 
-        return cleaned
+        // Fallback: handle weird path formats by scanning the trimmed path.
+        let trimmedPath = meetURL.path.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
+        if let first = trimmedPath.split(separator: "/").first.map(String.init),
+           isValidMeetMeetingCode(first) {
+            return first.lowercased()
+        }
+
+        return nil
     }
 
     private func aiCompanionSelectConferenceRecord(for meeting: ScheduledMeeting, from records: [ConferenceRecord]) -> ConferenceRecord? {