Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isDirectChat is not properly set #2019

Closed
1 of 2 tasks
PhantomRay opened this issue Feb 5, 2025 · 1 comment
Closed
1 of 2 tasks

isDirectChat is not properly set #2019

PhantomRay opened this issue Feb 5, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@PhantomRay
Copy link
Contributor

PhantomRay commented Feb 5, 2025

Checklist

  • I could not find a solution in the documentation, the existing issues or discussions.
  • I already asked for help in the chat

In which Project did the bug appear?

Other

If you selected "Other" as Project, please enter in which project the bug occurred.

No response

On which platform did the bug appear?

Android, iOS

SDK Version

~0.37

Describe the problem caused by this bug

By looking at the source code, isDirectChat relies on directChatMatrixID. Inside directChatMatrixID block, it only sets value when membership == Membership.invite. It should cater the scenario for Membership.join which is majority of the cases. In another words, when membership is join, this value is incorrect when the room is actually a direct chat room.

  String? get directChatMatrixID {
    // Calculating the directChatMatrixId can be expensive. We cache it and
    // validate the cache instead every time.
    final cache = _cachedDirectChatMatrixId;
    if (cache != null) {
      final roomIds = client.directChats[cache];
      if (roomIds is List && roomIds.contains(id)) {
        return cache;
      }
    }

    if (membership == Membership.invite) {
      final userID = client.userID;
      if (userID == null) return null;
      final invitation = getState(EventTypes.RoomMember, userID);
      if (invitation != null && invitation.content['is_direct'] == true) {
        return _cachedDirectChatMatrixId = invitation.senderId;
      }
    }

    final mxId = client.directChats.entries
        .firstWhereOrNull((MapEntry<String, dynamic> e) {
      final roomIds = e.value;
      return roomIds is List<dynamic> && roomIds.contains(id);
    })?.key;
    if (mxId?.isValidMatrixId == true) return _cachedDirectChatMatrixId = mxId;
    return _cachedDirectChatMatrixId = null;
  }

  /// Wheither this is a direct chat or not
  bool get isDirectChat => directChatMatrixID != null;

Steps To Reproduce

No response

Screenshots or Logs

No response

Security related

No response

@PhantomRay PhantomRay added the bug Something isn't working label Feb 5, 2025
@PhantomRay
Copy link
Contributor Author

I need to dig more as to why this didn't work for a particular room. Close it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant