package main // WhatsApp calls as lines in their chat (chat CONTRACT "Documents, links, a recording's date, WhatsApp calls": "a call // the WhatsApp link reports: write it as a message row in that chat with channel whatsapp and meta.call = the call's // facts, in CallFacts' shape"). The owner, 24 Nov 2026: WhatsApp shows "Voice call" as the chat's last line, Comms // showed the message before it. // // Two sources, both read only (nothing here answers, rejects or places a call): // - live: WhatsApp tells a linked device of a call as call stanzas (CallOffer or CallOfferNotice, CallAccept, // CallReject, CallTerminate). They are followed by call id until the call ends, then one message goes out; // - history: a missed call WhatsApp kept as a stub (CALL_MISSED_*), and a call log message (CallLogMessage). // // The message's id is the call's own (live: "call:"; history: the entry's message id), so a call reported // twice is one row. import ( "strings" "sync" "time" waBinary "go.mau.fi/whatsmeow/binary" "go.mau.fi/whatsmeow/proto/waE2E" "go.mau.fi/whatsmeow/proto/waWeb" "go.mau.fi/whatsmeow/types" "go.mau.fi/whatsmeow/types/events" ) // Call is a call's facts in Cotton's shape (cotton-core messages::app::calls::CallFacts, camelCase). type Call struct { Room string `json:"room"` Direction string `json:"direction"` // in or out Video bool `json:"video"` Outcome string `json:"outcome"` // answered, missed, cancelled or failed Reason string `json:"reason"` // missed, declined, no_answer, cancelled, failed, answered DurationS int64 `json:"durationS"` Missed bool `json:"missed"` // rang here and nobody here answered or declined it Group bool `json:"group"` } // How long a call may go without its end before it is let go (said as missed when it never connected). const callForgotten = 2 * time.Hour type ringing struct { account string chat types.JID group bool video bool incoming bool started time.Time accepted time.Time rejected bool } // Calls follows live calls by id until they end. type Calls struct { mu sync.Mutex open map[string]*ringing clock func() time.Time } func NewCalls() *Calls { return &Calls{open: map[string]*ringing{}, clock: time.Now} } // videoOf reads a call stanza's media: a