Auties00 / Cobalt

Standalone unofficial fully-featured Whatsapp Web and Mobile API for Java and Kotlin
MIT License
634 stars 185 forks source link

Group participants list is empty #268

Closed llistochek closed 1 year ago

llistochek commented 1 year ago

chat.participants() returns empty list.

Version: 3.3.1

To reproduce, add following listener to Whatsapp instance:

// Kotlin
import it.auties.whatsapp.listener.Listener
import it.auties.whatsapp.model.chat.Chat

class ChatsListener : Listener {
    override fun onChats(chats: MutableCollection<Chat>) {
        chats.forEach { chat ->
            if (chat.isGroup) {
                println(chat.participants().size)
            }
        }
    }
}

Expected behavior: It should output anything other than "0".

Actual behavior: It outputs only "0".

Auties00 commented 1 year ago

chat.participants() returns empty list.

Version: 3.3.1

To reproduce, add following listener to Whatsapp instance:

// Kotlin
import it.auties.whatsapp.listener.Listener
import it.auties.whatsapp.model.chat.Chat

class ChatsListener : Listener {
    override fun onChats(chats: MutableCollection<Chat>) {
        chats.forEach { chat ->
            if (chat.isGroup) {
                println(chat.participants().size)
            }
        }
    }
}

Expected behavior: It should output anything other than "0".

Actual behavior: It outputs only "0".

right now it works as a cache, so you have to first invoke queryGroupMetadata for that list to he populated. I agree though that it's counter intuitive so I'll fix it

llistochek commented 1 year ago

Thanks for the quick reply!

right now it works as a cache, so you have to first invoke queryGroupMetadata for that list to he populated


import it.auties.whatsapp.api.Whatsapp
import it.auties.whatsapp.listener.Listener
import it.auties.whatsapp.model.chat.Chat

class ChatsListener : Listener { override fun onChats(whatsapp: Whatsapp, chats: MutableCollection) { for (chat in chats) { if (!chat.isGroup) continue val metadataParticipants = whatsapp.queryGroupMetadata(chat).join().participants() val chatParticipants = chat.participants() println("---") println(chat.name()) println("Metadata size: ${metadataParticipants.size}") println("Chat size: ${chatParticipants.size}") } } }


This listener prints normal `Metadata size:` (equal to real number of participants) but `Chat size:` is always 0. So it seems like group metadata isn't cached. Am I missing something?
Auties00 commented 1 year ago

Thanks for the quick reply!

right now it works as a cache, so you have to first invoke queryGroupMetadata for that list to he populated

import it.auties.whatsapp.api.Whatsapp
import it.auties.whatsapp.listener.Listener
import it.auties.whatsapp.model.chat.Chat

class ChatsListener : Listener {
    override fun onChats(whatsapp: Whatsapp, chats: MutableCollection<Chat>) {
        for (chat in chats) {
            if (!chat.isGroup) continue
            val metadataParticipants = whatsapp.queryGroupMetadata(chat).join().participants()
            val chatParticipants = chat.participants()
            println("---")
            println(chat.name())
            println("Metadata size: ${metadataParticipants.size}")
            println("Chat size: ${chatParticipants.size}")
        }
    }
}

This listener prints normal Metadata size: (equal to real number of participants) but Chat size: is always 0. So it seems like group metadata isn't cached. Am I missing something?

I've fixed it in the latest commit, now it will also sync all the metadata of groups used in the last 2 weeks