sort method

void sort()

Implementation

void sort() {
  switch (_query.order) {
    case GroupChannelListQueryOrder.chronological:
      channelList.sort((a, b) {
        if (a.createdAt != null && b.createdAt != null) {
          return b.createdAt!.compareTo(a.createdAt!);
        }
        return 0;
      });
      break;

    case GroupChannelListQueryOrder.latestLastMessage:
      channelList.sort((a, b) {
        if (a.lastMessage != null && b.lastMessage == null) {
          return -1;
        } else if (a.lastMessage == null && b.lastMessage != null) {
          return 1;
        } else if (a.lastMessage != null && b.lastMessage != null) {
          return b.lastMessage!.createdAt.compareTo(a.lastMessage!.createdAt);
        } else {
          if (a.createdAt != null && b.createdAt != null) {
            return b.createdAt!.compareTo(a.createdAt!);
          }
          return 0;
        }
      });
      break;

    case GroupChannelListQueryOrder.channelNameAlphabetical:
      channelList.sort((a, b) {
        return a.name.compareTo(b.name);
      });
      break;

    case GroupChannelListQueryOrder.metadataValueAlphabetical:
      // TODO: (?)
      break;
  }
}