Skip to content

Conversation

coodos
Copy link
Contributor

@coodos coodos commented Oct 15, 2025

Description of change

Issue Number

closes #370
closes #369
closes #368

Type of change

  • Breaking (any change that would cause existing functionality to not work as expected)
  • New (a change which implements a new feature)
  • Update (a change which updates existing functionality)
  • Fix (a change which fixes an issue)
  • Docs (changes to the documentation)
  • Chore (refactoring, build scripts or anything else that isn't user-facing)

How the change has been tested

Change checklist

  • I have ensured that the CI Checks pass locally
  • I have removed any unnecessary logic
  • My code is well documented
  • I have signed my commits
  • My code follows the pattern of the application
  • I have self reviewed my code

Summary by CodeRabbit

  • Bug Fixes

    • Corrected profile links in notifications to point to /profile/{ename}.
    • Prevents creation of duplicate direct message threads between two users.
    • Improves reliability of initial messages after a new chat is created.
  • Refactor

    • Streamlined mutual chat creation and detection across notification and consent flows to reduce errors and ensure private chats are ready before messaging.
    • Optimized private chat lookup to more efficiently find existing two‑member chats.

Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors mutual chat creation across services to return { chat, wasCreated } and introduces a 15-second delay before messaging when a chat is newly created. Adds a 2-member DM fast-path and pre-check in group lookup/creation to avoid duplicate chats. Updates link building in notifications and expands logging.

Changes

Cohort / File(s) Summary
Mutual chat return-shape refactor and delayed messaging
platforms/dreamsync-api/src/services/ConsentService.ts, platforms/dreamsync-api/src/services/MatchNotificationService.ts
Change findOrCreateMutualChat to return { chat, wasCreated }; update call sites to unpack values and conditionally wait 15s before sending messages; standardize null/error returns to { chat: null, wasCreated: false }; add logging and JSDoc.
DM lookup fast-path and creation pre-check
platforms/dreamsync-api/src/services/GroupService.ts
Add optimized 2-member private DM search using name prefix and exact-member match; filter by isPrivate; in createGroup, pre-check for existing DM and return it to skip creation.
Notification link tweak
.../MatchNotificationService.ts
Update convertEnameToLinks to use /profile/{ename} instead of /user/{ename}.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Svc as Service (Consent/MatchNotification)
  participant GroupSvc as GroupService
  participant Store as Data Store
  participant Msg as Messaging

  Note over Svc: findOrCreateMutualChat(targetUserId)
  Svc->>GroupSvc: findGroupByMembers([me, target])
  alt Existing DM found
    GroupSvc-->>Svc: { chat, wasCreated: false }
  else Not found
    Svc->>GroupSvc: createGroup(private, 2 members)
    GroupSvc->>GroupSvc: pre-check existing DM
    alt DM exists
      GroupSvc-->>Svc: { chat: existing, wasCreated: false }
    else Create new
      GroupSvc->>Store: insert group
      Store-->>GroupSvc: group
      GroupSvc-->>Svc: { chat: new, wasCreated: true }
    end
  end

  alt wasCreated == true
    Note over Svc: Wait 15s to ensure chat readiness
  end
  Svc->>Msg: send initial messages to chat
Loading
sequenceDiagram
  autonumber
  participant Client as Caller (Any Service)
  participant GroupSvc as GroupService
  participant DB as DB

  Note over Client,GroupSvc: findGroupByMembers([A,B])
  alt Exactly 2 members
    GroupSvc->>DB: query private groups with DreamSync Chat prefix
    DB-->>GroupSvc: candidate groups
    GroupSvc->>GroupSvc: filter exact 2-member match
    GroupSvc-->>Client: DM or null
  else Other sizes
    GroupSvc->>DB: query private groups by members
    DB-->>GroupSvc: result
    GroupSvc-->>Client: group or null
  end

  Note over Client,GroupSvc: createGroup(private, [A,B])
  GroupSvc->>GroupSvc: pre-check findGroupByMembers([A,B])
  alt Found
    GroupSvc-->>Client: existing group
  else Not found
    GroupSvc->>DB: insert new group
    DB-->>GroupSvc: group
    GroupSvc-->>Client: new group
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I thump my paw: “Delay, delay!”
Fifteen ticks so chats won’t stray.
Two-heart tunnels, swift and neat—
Find before we forge the seat.
Links hop paths to profiles new,
Burrows tidy, messages through.
DreamSync hums—carrots for the crew! 🥕✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/dreamsync-bugs

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9bf39c0 and cd1801a.

📒 Files selected for processing (3)
  • platforms/dreamsync-api/src/services/ConsentService.ts (12 hunks)
  • platforms/dreamsync-api/src/services/GroupService.ts (2 hunks)
  • platforms/dreamsync-api/src/services/MatchNotificationService.ts (10 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coodos coodos merged commit fc4080e into main Oct 15, 2025
0 of 4 checks passed
@coodos coodos deleted the fix/dreamsync-bugs branch October 15, 2025 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Dream Sync Pre Sends Message Before Channel Creation [bug] dream sync system message: profile links not working [Bug] DreamSync double chat

1 participant