This is how I got all the messages across all channels from the server. I wrote it in JS, hopefully it will help you out:
async function listUnreadMessages(user) {
const serverClient = new StreamChat(api_key, stream_secret, options)
await serverClient.setUser(
{
id: `${user.id}`,
name: `${user.full_name}`,
image: user.profile_image
},
user.chat_token
)
const filter = { members: { $in: [`${user.id}`] } }
const sort = { last_message_at: -1 }
const channels = await serverClient.queryChannels(filter, sort, {
watch: true
})
let unreadList = {}
const unreads = await Promise.all(
channels.map((c) => {
unreadList[c.id] = c.countUnread()
return c.countUnread()
})
)
serverClient.disconnect()
return unreadList
}