Skip to content

[IMPROVEMENT] Remove redundant await on synchronous userPreferences.getBool in getUsersPresence #7737

Description

@cynicalmindset

Description:

In app/lib/methods/getUsersPresence.ts, the setPresenceCap function contains an unnecessary await when calling userPreferences.getBool(NOTIFICATION_PRESENCE_CAP).

UserPreferences is backed by react-native-mmkv, where getBool(key) is completely synchronous and returns boolean | null (not a Promise). Awaiting a synchronous non-Promise value is redundant, flags @typescript-eslint/await-thenable, and adds unnecessary microtask overhead to an otherwise synchronous routine.

Environment Information:

  • Rocket.Chat Server Version: N/A (Client TypeScript codebase)
  • Rocket.Chat App Version: develop branch
  • Device Name: All
  • OS Version: iOS / Android

Steps to reproduce:

  1. Open app/lib/methods/getUsersPresence.ts lines 140–151.
  2. Note that userPreferences.getBool is called with await.
  3. Check definition of userPreferences.getBool in app/lib/methods/userPreferences.ts: it synchronously returns boolean | null.

Expected behavior:

userPreferences.getBool(NOTIFICATION_PRESENCE_CAP) should be evaluated synchronously without await. Since all internal operations in setPresenceCap are synchronous, the async modifier should also be removed.

Actual behavior:

A non-Promise return value (boolean | null) is awaited using await, and setPresenceCap is unnecessarily declared as async.

Proposed Solution & Approach:

  1. In app/lib/methods/getUsersPresence.ts, remove await on line 142.
  2. Remove async keyword from setPresenceCap on line 140.
  3. Verify that pnpm lint (oxlint && tsc) passes without errors.

Additional context:

All external callers in the codebase (app/lib/methods/getSettings.ts line 186 and app/lib/services/connect.ts line 349) already invoke setPresenceCap(...) synchronously without await. Making setPresenceCap strictly synchronous aligns the implementation with its callers and avoids microtask scheduling.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions