diff --git a/slidge_whatsapp/event.go b/slidge_whatsapp/event.go index 17493a8..8f72c46 100644 --- a/slidge_whatsapp/event.go +++ b/slidge_whatsapp/event.go @@ -66,7 +66,7 @@ type Contact struct { // NewContactEvent returns event data meant for [Session.propagateEvent] for the contact information // given. Unknown or invalid contact information will return an [EventUnknown] event with nil data. -func newContactEvent(c *whatsmeow.Client, jid types.JID, info types.ContactInfo) (EventKind, *EventPayload) { +func newContactEvent(jid types.JID, info types.ContactInfo) (EventKind, *EventPayload) { var contact = Contact{ JID: jid.ToNonAD().String(), } @@ -188,6 +188,11 @@ func newMessageEvent(client *whatsmeow.Client, evt *events.Message) (EventKind, IsCarbon: evt.Info.IsFromMe, } + // Broadcast and status messages are currently not handled at all. + if evt.Info.Chat.Server == types.BroadcastServer { + return EventUnknown, nil + } + if evt.Info.IsGroup { message.GroupJID = evt.Info.Chat.ToNonAD().String() } else if message.IsCarbon { @@ -676,6 +681,11 @@ func newReceiptEvent(evt *events.Receipt) (EventKind, *EventPayload) { return EventUnknown, nil } + // Receipts for broadcast and status messages are currently not handled at all. + if evt.MessageSource.Chat.Server == types.BroadcastServer { + return EventUnknown, nil + } + if evt.MessageSource.IsGroup { receipt.GroupJID = evt.MessageSource.Chat.ToNonAD().String() } else if receipt.IsCarbon { @@ -683,9 +693,9 @@ func newReceiptEvent(evt *events.Receipt) (EventKind, *EventPayload) { } switch evt.Type { - case events.ReceiptTypeDelivered: + case types.ReceiptTypeDelivered: receipt.Kind = ReceiptDelivered - case events.ReceiptTypeRead: + case types.ReceiptTypeRead: receipt.Kind = ReceiptRead } diff --git a/slidge_whatsapp/gateway.go b/slidge_whatsapp/gateway.go index 85efb04..9192fbd 100644 --- a/slidge_whatsapp/gateway.go +++ b/slidge_whatsapp/gateway.go @@ -3,7 +3,6 @@ package whatsapp import ( // Standard library. "fmt" - "net/http" "os" "runtime" @@ -78,9 +77,8 @@ type Gateway struct { TempDir string // The directory to create temporary files under. // Internal variables. - container *sqlstore.Container - httpClient *http.Client - logger walog.Logger + container *sqlstore.Container + logger walog.Logger } // NewGateway returns a new, un-initialized Gateway. This function should always be followed by calls diff --git a/slidge_whatsapp/session.go b/slidge_whatsapp/session.go index 5ec091e..bca2369 100644 --- a/slidge_whatsapp/session.go +++ b/slidge_whatsapp/session.go @@ -431,7 +431,7 @@ func (s *Session) GetContacts(refresh bool) ([]Contact, error) { s.gateway.logger.Warnf("Failed to subscribe to presence for %s", jid) } - _, c := newContactEvent(s.client, jid, info) + _, c := newContactEvent(jid, info) contacts = append(contacts, c.Contact) } @@ -701,7 +701,7 @@ func (s *Session) handleEvent(evt interface{}) { if err != nil { continue } - s.propagateEvent(newContactEvent(s.client, jid, types.ContactInfo{FullName: n.GetPushname()})) + s.propagateEvent(newContactEvent(jid, types.ContactInfo{FullName: n.GetPushname()})) if err = s.client.SubscribePresence(jid); err != nil { s.gateway.logger.Warnf("Failed to subscribe to presence for %s", jid) } @@ -720,7 +720,7 @@ func (s *Session) handleEvent(evt interface{}) { case *events.Presence: s.propagateEvent(newPresenceEvent(evt)) case *events.PushName: - s.propagateEvent(newContactEvent(s.client, evt.JID, types.ContactInfo{FullName: evt.NewPushName})) + s.propagateEvent(newContactEvent(evt.JID, types.ContactInfo{FullName: evt.NewPushName})) case *events.JoinedGroup: s.propagateEvent(EventGroup, &EventPayload{Group: newGroup(s.client, &evt.GroupInfo)}) case *events.GroupInfo: