GetStream / stream-chat-flutter

Flutter Chat SDK - Build your own chat app experience using Dart, Flutter and the Stream Chat Messaging API.
https://getstream.io/chat/sdk/flutter/
Other
881 stars 314 forks source link

Filtering does not work when querying channels #1887

Closed AlaaAbdelbaki closed 3 months ago

AlaaAbdelbaki commented 3 months ago

Which packages are you using?

stream_chat, stream_chat_flutter, stream_chat_flutter_core

On what platforms did you experience the issue?

iOS, Android, Web

What version are you using?

7.1.0

What happened?

Starting from today, whenever I try to query channels using a filter, the filter is always ignored, and the query function always returns the last 10 conversations.

Screenshot 2024-03-28 at 10 08 18

As you can see in the screenshot, we are trying to query the channels and filtering by a field in their extra data called company ID, for this example we are trying to query all the channels that have the value "enable" for the company ID field, but the client ignores the filter and queries the latest 10 channels.

Steps to reproduce

1. Try to query the available channels using a custom filter.
2. The returned channels are always the last 10 channels, and the filter used in the query function is ignored

Supporting info to reproduce

No response

Relevant log output

No response

Flutter analyze output

No response

Flutter doctor output

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.2, on Microsoft Windows [Version 10.0.22631.3296], locale en-GB)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[!] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.30)
    ✗ The current Visual Studio installation is incomplete.
      Please use Visual Studio Installer to complete the installation or reinstall Visual Studio.
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.87.2)
[✓] Connected device (3 available)
[✓] Network resources

Code of Conduct

senkia24 commented 3 months ago

same here any update?

AlaaAbdelbaki commented 3 months ago

We had to update the package internally in the channels_api.dart file we replaced the queryChannels method with this one We replaced it from this:

/// THIS IS THE OLD FUNCTION THAT'S CAUSING THE ERROR
/// Line 50
/// Requests channels with a given query from the API.
  Future<QueryChannelsResponse> queryChannels({
    Filter? filter,
    List<SortOption>? sort,
    int? memberLimit,
    int? messageLimit,
    bool state = true,
    bool watch = true,
    bool presence = false,
    PaginationParams paginationParams = const PaginationParams(),
  }) async {
    final response = await _client.get(
      '/channels',
      queryParameters: {
        'payload': jsonEncode({
          // default options
          'state': state,
          'watch': watch,
          'presence': presence,

          // passed options
          if (sort != null) 'sort': sort,
          if (filter != null) 'filter_conditions': filter,
          if (memberLimit != null) 'member_limit': memberLimit,
          if (messageLimit != null) 'message_limit': messageLimit,

          // pagination
          ...paginationParams.toJson(),
        }),
      },
    );
    return QueryChannelsResponse.fromJson(response.data);
  }

to this

  /// THIS IS THE FIXED FUNCTION
  /// Line 50
  /// Requests channels with a given query from the API.
  Future<QueryChannelsResponse> queryChannels({
    Filter? filter,
    List<SortOption>? sort,
    int? memberLimit,
    int? messageLimit,
    bool state = true,
    bool watch = true,
    bool presence = false,
    PaginationParams paginationParams = const PaginationParams(),
  }) async {
    final response = await _client.post(
      '/channels',
      data: {
        // default options
        'state': state,
        'watch': watch,
        'presence': presence,

        // passed options
        if (sort != null) 'sort': sort,
        if (filter != null) 'filter_conditions': filter,
        if (memberLimit != null) 'member_limit': memberLimit,
        if (messageLimit != null) 'message_limit': messageLimit,

        // pagination
        ...paginationParams.toJson(),
      },
    );
    return QueryChannelsResponse.fromJson(response.data);
  }

Also I had to copy the getstream packages to my local project and add this dependency override in my pubspec.yaml


dependency_overrides:
  stream_chat_flutter:
    path: ./packages/stream_chat_flutter-7.1.0
  stream_chat_flutter_core:
    path: ./packages/stream_chat_flutter_core-7.1.0
  stream_chat:
    path: ./packages/stream_chat-7.1.0
senkia24 commented 3 months ago

In production env, Our app received wrong channels or sometimes error 403.

nbourdin commented 3 months ago

@AlaaAbdelbaki So we need to wait for a new release with the update ?

AlaaAbdelbaki commented 3 months ago

I'd say yes if you do not want to update the internal package yourself

esarbanis commented 3 months ago

Hi everyone, I am checking with the team internally to see if there were any API changes. This code block haven't been touched for over 3 years now ...

@AlaaAbdelbaki thank you for investigating. Can you please open a PR with this patch? Once I have confirmation internally from the team I will review and merge.

tahaJemmali commented 3 months ago

Today, a backend update was rolled out, resulting in the disabling of the GET request used for querying channels. This has led to an issue where all users are now able to view every conversation due to the malfunctioning of the filtering feature. To address this, please restore the GET API request as an immediate corrective action. Following that, you can initiate the planning and development of a new release update to ensure a more comprehensive solution.

nullpoint-dev commented 3 months ago

@esarbanis - thanks for investigating internally.

To add some extra info.

I believe that a backend update is likely causing these issues.

Our app uses the flutter UIKit and since the early hours of this morning all our users were unable to view any channels.

This is caused by all channel querys hitting a 403 stating that 'channels cannot be returned because you don't have acces to them'.

There has been not changes to any of the code associated with stream for months - on our backend or within the app.

Edit - @esarbanis this appears to have been resolved.

esarbanis commented 3 months ago

It was an issue with the latest deployment of our API, this should be fixed now. Thanks everyone for their quick response and feedback 🚀