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

Hope support for sorting channel list by custom fields #65

Closed
yswtrue opened this issue Jul 30, 2020 · 6 comments
Closed

Hope support for sorting channel list by custom fields #65

yswtrue opened this issue Jul 30, 2020 · 6 comments

Comments

@yswtrue
Copy link

yswtrue commented Jul 30, 2020

I need to put system_message channel and customer_message channel on the top of channelsPage, but I can't sort by a custom field like priority. Hope support for sorting by custom fields.

gz#4687

@shodgetts
Copy link

Agent comment from Stephen Hodgetts in Zendesk ticket #4687:

You can sort by custom channel fields. Can you share how you're using channellistview and the sort parameter you're using, please?

@yswtrue
Copy link
Author

yswtrue commented Aug 5, 2020

Agent comment from Stephen Hodgetts in Zendesk ticket #4687:

You can sort by custom channel fields. Can you share how you're using channellistview and the sort parameter you're using, please?

class ChannelListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        centerTitle: true,
        title: Text(
          'Messages',
          style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
        ),
      ),
      body: ChannelsBloc(
        child: ChannelListView(
          filter: {
            'members': {
              '\$in': [StreamChat.of(context).user.id],
            }
          },
          sort: [
            SortOption('priority', direction: 1),
            SortOption('last_message_at')
          ],
          pagination: PaginationParams(
            limit: 20,
          ),
          channelWidget: ChannelPage(),
        ),
      ),
    );
  }
}

this is my ChannelListView code.

@imtoori imtoori removed the backend label Aug 5, 2020
@imtoori
Copy link
Contributor

imtoori commented Aug 5, 2020

hey @yswtrue I did some research and found out that you should keep in mind that the sorting fields are first transformed to string before being compared, so you should pad your priority field

eg: not 1 but 01

check it here https://play.golang.org/p/GvJV0E5Sj2_4

however, this raises a bug related to channels being pushed to the top of the ChannelListView when they receive a new message. I'll make sure to fix this bug and find a solution as soon as possible

@imtoori
Copy link
Contributor

imtoori commented Aug 25, 2020

@yswtrue did you solve your problem?

@yswtrue
Copy link
Author

yswtrue commented Aug 26, 2020

@yswtrue did you solve your problem?

I sort by message type now, so I haven't tried this solution.

@imtoori
Copy link
Contributor

imtoori commented Jan 26, 2021

Closing this
Feel free to reopen it if this is still an issue

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

No branches or pull requests

3 participants