getChats method

Future getChats({
  1. bool onlyUser = false,
  2. bool onlyGroups = false,
})

get all Chats using getChats, as plain maps: id, name, isGroup, isNewsletter, unreadCount, timestamp, archived, pinned. (WhatsApp's own chat objects can't cross to Dart; they arrived as null.)

Implementation

Future getChats({
  bool onlyUser = false,
  bool onlyGroups = false,
}) async {
  return await wpClient.evaluateJs(
    '''window.WPP.chat.list({
          onlyUsers: ${onlyUser.jsParse},
          onlyGroups: ${onlyGroups.jsParse}
       }).then(function(chats) { return chats.map(function(c) {
        return {
          id: c.id && c.id._serialized ? c.id._serialized : String(c.id),
          name: c.name || (c.groupMetadata && c.groupMetadata.subject) || c.formattedTitle || (c.contact && (c.contact.name || c.contact.pushname)) || '',
          isGroup: !!c.isGroup,
          isNewsletter: !!c.isNewsletter,
          unreadCount: c.unreadCount || 0,
          timestamp: c.t || 0,
          archived: !!c.archive,
          pinned: !!c.pin
        };
      }); })''',
    methodName: "GetChats",
    forceJsonParseResult: true,
  );
}