package main import ( "strings" "go.mau.fi/whatsmeow/proto/waE2E" "go.mau.fi/whatsmeow/proto/waWeb" "go.mau.fi/whatsmeow/types" "go.mau.fi/whatsmeow/types/events" ) // The census: how many messages of each kind WhatsApp handed this helper, live and in its history, including the // kinds Convert drops, so the import can be audited against what WhatsApp holds (owner, FEEDBACK-3, 23 Nov 2026). // Counts only: a kind's name and a number, never a chat, a person or a word. // kindOf names a message's kind as WhatsApp sends it, after whatsmeow took its wrappers off. func kindOf(msg *waE2E.Message) string { switch { case msg == nil: return "empty" case msg.GetConversation() != "" || msg.GetExtendedTextMessage() != nil: return "text" case msg.GetImageMessage() != nil: return "picture" case msg.GetVideoMessage() != nil: if msg.GetVideoMessage().GetGifPlayback() { return "gif" } return "video" case msg.GetPtvMessage() != nil: return "video note" case msg.GetAudioMessage() != nil: if msg.GetAudioMessage().GetPTT() { return "voice note" } return "audio file" case msg.GetDocumentMessage() != nil: return "document" case msg.GetStickerMessage() != nil: return "sticker" case msg.GetLocationMessage() != nil: return "location" case msg.GetLiveLocationMessage() != nil: return "live location" case msg.GetContactMessage() != nil || msg.GetContactsArrayMessage() != nil: return "contact card" case msg.GetReactionMessage() != nil || msg.GetEncReactionMessage() != nil: return "reaction" case msg.GetPollCreationMessage() != nil || msg.GetPollCreationMessageV2() != nil || msg.GetPollCreationMessageV3() != nil: return "poll" case msg.GetPollUpdateMessage() != nil: return "poll vote" case msg.GetEventMessage() != nil: return "event" case msg.GetGroupInviteMessage() != nil: return "group invite" case msg.GetCall() != nil || msg.GetCallLogMesssage() != nil: return "call" case msg.GetPinInChatMessage() != nil: return "pin" case msg.GetKeepInChatMessage() != nil: return "keep in chat" case msg.GetProtocolMessage() != nil: switch msg.GetProtocolMessage().GetType() { case waE2E.ProtocolMessage_REVOKE: return "delete for everyone" case waE2E.ProtocolMessage_MESSAGE_EDIT: return "edit" case waE2E.ProtocolMessage_EPHEMERAL_SETTING: return "disappearing setting" default: return "plumbing" } case msg.GetSenderKeyDistributionMessage() != nil: return "plumbing" } return "other" } // census counts one message: its kind, and beside it how it came (view once, disappearing) and whether the reader // can key its chat by a number at all. func (h *Hub) census(origin string, evt *events.Message, chat types.JID) { if h.outbox == nil { return } if IsStatus(evt.Info.Chat) { h.outbox.Count(origin, "status") return } h.outbox.Count(origin, kindOf(evt.Message)) if evt.IsViewOnce { h.outbox.Count(origin, "(view once)") } if evt.IsEphemeral { h.outbox.Count(origin, "(disappearing)") } if !evt.Info.IsGroup && chat.Server == types.HiddenUserServer { h.outbox.Count(origin, "(chat known by no number)") } } // censusStub counts a history entry with no message: what WhatsApp shows as a line in the chat (someone joined or // left, a missed call, the group's name changed), by its family. func (h *Hub) censusStub(web *waWeb.WebMessageInfo) { if h.outbox == nil || web.GetMessageStubType() == waWeb.WebMessageInfo_UNKNOWN { return } name := web.GetMessageStubType().String() switch { case strings.HasPrefix(name, "GROUP_PARTICIPANT_") || strings.HasPrefix(name, "COMMUNITY_PARTICIPANT_"): h.outbox.Count("history", "group join or leave") case strings.HasPrefix(name, "GROUP_") || strings.HasPrefix(name, "COMMUNITY_"): h.outbox.Count("history", "group change") case strings.HasPrefix(name, "CALL_"): h.outbox.Count("history", "call") case name == "REVOKE": h.outbox.Count("history", "deleted marker") case strings.HasPrefix(name, "E2E_") || strings.HasPrefix(name, "BIZ_") || strings.HasPrefix(name, "BLUE_MSG_"): h.outbox.Count("history", "notice") default: h.outbox.Count("history", "other line") } }