Skip to content

Fix cross-device sync for attach logs preference (MM-67856)#9667

Draft
Willyfrog wants to merge 3 commits intomainfrom
send_logs_fix_observe
Draft

Fix cross-device sync for attach logs preference (MM-67856)#9667
Willyfrog wants to merge 3 commits intomainfrom
send_logs_fix_observe

Conversation

@Willyfrog
Copy link
Copy Markdown
Contributor

Summary

Follow up of #9633

WatermelonDB query .observe() only emits when records enter/leave the result set, not when a field on an existing record changes. This caused the attach logs toggle to not sync across devices after the initial creation. Fix by subscribing to the individual record's .observe() via switchMap, which emits on any field change.

Extract observePreferenceAsBool helper to app/queries/servers/preference.ts and use it in both report_a_problem and quick_actions enhanced components.

Also adds unit tests, E2E tests, and debug logging for preference WS events.

Ticket Link

MM-67856

Checklist

  • Added or updated unit tests (required for all new features)
  • Has UI changes
  • Includes text changes and localization file updates
  • Have tested against the 5 core themes to ensure consistency between them.
  • Have run E2E tests by adding label E2E/Run (or E2E/Run-iOS / E2E/Run-Android for platform-specific runs).

Device Information

This PR was tested on: pixel 8, ios sim

Release Note

fix realtime UI update when changing the settings for the attach logs for debugging functionality

WatermelonDB query .observe() only emits when records enter/leave the
result set, not when a field on an existing record changes. This caused
the attach logs toggle to not sync across devices after the initial
creation. Fix by subscribing to the individual record's .observe() via
switchMap, which emits on any field change.

Extract observePreferenceAsBool helper to app/queries/servers/preference.ts
and use it in both report_a_problem and quick_actions enhanced components.

Also adds unit tests, E2E tests, and debug logging for preference WS events.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Willyfrog Willyfrog requested a review from Copilot April 7, 2026 09:57
@Willyfrog Willyfrog self-assigned this Apr 7, 2026
@Willyfrog Willyfrog added the 2: Dev Review Requires review by a core commiter label Apr 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Coverage Comparison Report

Generated on April 14, 2026 at 15:03:32 UTC

+-----------------+------------+------------+-----------+
| Metric          | Main       | This PR    | Diff      |
+-----------------+------------+------------+-----------+
| Lines           |     85.17% |     85.18% |     0.01% |
| Statements      |     85.03% |     85.04% |     0.01% |
| Branches        |     72.22% |     72.24% |     0.02% |
| Functions       |     84.03% |     84.05% |     0.02% |
+-----------------+------------+------------+-----------+
| Total           |     81.61% |     81.62% |     0.01% |
+-----------------+------------+------------+-----------+

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a realtime sync issue where the “Attach app logs” preference didn’t update across devices because the underlying WatermelonDB query observable didn’t emit on field updates for existing records.

Changes:

  • Introduced observePreferenceAsBool to correctly react to preference value updates and reused it in Report a Problem and post draft quick actions.
  • Added unit test coverage for reacting to preference updates and a new Detox E2E suite for the attach logs toggle/attachment menu behavior.
  • Added debug logging for preference WebSocket events.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
detox/e2e/test/products/channels/account/attach_logs.e2e.ts Adds E2E coverage for attach logs toggle visibility and attachment menu option.
detox/e2e/support/ui/screen/report_problem.ts Adds a Detox screen object for the Report a Problem screen interactions.
detox/e2e/support/ui/screen/index.ts Exports the new ReportProblemScreen helper.
app/screens/report_a_problem/index.ts Switches attach logs observable to the new per-record preference observer.
app/screens/report_a_problem/index.test.tsx Adds a unit test to ensure UI reacts to preference value changes.
app/queries/servers/preference.ts Adds observePreferenceAsBool helper for reactive boolean preferences.
app/components/post_draft/quick_actions/index.ts Updates quick actions gating logic to use boolean preference observable.
app/components/post_draft/quick_actions/attachment_quick_action/index.test.tsx Adds a test to ensure showAttachLogs is passed through correctly.
app/actions/websocket/preferences.ts Adds debug logs for preference change WebSocket events.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +18
testID = {
reportProblemScreen: 'ReportProblem',
enableLogAttachmentsToggleOff: 'report_problem.enable_log_attachments.toggled.false.button',
enableLogAttachmentsToggleOn: 'report_problem.enable_log_attachments.toggled.true.button',
closeButton: 'close-report-problem',
};

reportProblemScreen = element(by.id(this.testID.reportProblemScreen));
enableLogAttachmentsToggleOff = element(by.id(this.testID.enableLogAttachmentsToggleOff));
enableLogAttachmentsToggleOn = element(by.id(this.testID.enableLogAttachmentsToggleOn));
closeButton = element(by.id(this.testID.closeButton));
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reportProblemScreen is set to the testID ReportProblem, but the app code for the Report a Problem screen doesn't expose a matching testID (and close-report-problem also doesn't appear to be wired up anywhere). This will likely make toBeVisible()/close() fail in E2E. Consider anchoring visibility/close interactions on existing, stable IDs (e.g. the RNN back button screen.back.button from navigation options), or add a dedicated screen-level testID in the app and reference ${id}.screen like other settings screens.

Copilot uses AI. Check for mistakes.
Comment on lines 20 to 23
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
const preference: PreferenceType = JSON.parse(msg.data.preference);
logDebug('[WS] PREFERENCE_CHANGED', preference.category, preference.name, preference.value);
handleSavePostAdded(serverUrl, [preference]);
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These logDebug statements log preference values received over WebSocket. Preference values can be large (e.g., theme JSON) and may contain sensitive/user-specific data; logging them can bloat logs and impact performance in production. Consider logging only category/name (and maybe value length), or gating value logging behind a debug/dev flag.

Copilot uses AI. Check for mistakes.
Comment on lines 26 to 30
const canUploadFiles = observeCanUploadFiles(database);
const maxFileCount = observeMaxFileCount(database);
const allowDownloadLogs = observeConfigBooleanValue(database, 'AllowDownloadLogs', true);
const attachLogsPref = queryPreferencesByCategoryAndName(
database,
Preferences.CATEGORIES.ADVANCED_SETTINGS,
Preferences.ATTACH_APP_LOGS,
).observe();
const attachLogsPref = observePreferenceAsBool(database, Preferences.CATEGORIES.ADVANCED_SETTINGS, Preferences.ATTACH_APP_LOGS);

Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attachLogsPref now holds an Observable<boolean> (via observePreferenceAsBool), not a preference model/array. Renaming it to something like attachLogsEnabled (or similar) would avoid confusion when reading the combineLatest logic.

Copilot uses AI. Check for mistakes.
Willyfrog and others added 2 commits April 7, 2026 17:17
- Add testID to Report a Problem screen and use screen.back.button in
  Detox screen object to match existing settings screen patterns
- Remove unused REPORT_PROBLEM_CLOSE_BUTTON_ID export
- Omit preference values from debug logs to avoid logging large or
  sensitive data
- Rename attachLogsPref to attachLogsEnabled for clarity

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2: Dev Review Requires review by a core commiter release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants