Ignore Broadcast and Status messages
Status messages and Broadcasts require special handling on the Slidge side, especially where read receipts are concerned. However, if not handled specifically, these will currently default to being handled as (strange) group-chats, which might be responsible for crashes etc. This commit has these message types be explicitly unhandled until we introduce support for handling these properly.
This commit is contained in:
parent
72ebb936d2
commit
e0c7c5c13d
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue