diff --git a/model/overlay.go b/model/overlay.go index 03fe0bb..b79a4ce 100644 --- a/model/overlay.go +++ b/model/overlay.go @@ -19,6 +19,24 @@ type MessageWrapper struct { RecvTime *time.Time `json:"r,omitempty"` } +// Channel is defined as being the last 3 bits of the overlay id +// Channel 0 is reserved for the main conversation +// Channel 2 is reserved for conversation admin (managed groups) +// Channel 7 is reserved for streams (no ack, no store) +func (mw MessageWrapper) Channel() int { + if mw.Overlay > 1024 { + return mw.Overlay & 0x07 + } + // for backward compatibilty all overlays less than 0x400 i.e. 1024 are + // mapped to channel 0 regardless of their channel status. + return 0 +} + +// If Overlay is a Stream Message it should not be ackd, or stored. +func (mw MessageWrapper) IsStream() bool { + return mw.Channel() == 0x07 +} + // OverlayChat is the canonical identifier for chat overlays const OverlayChat = 1 diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 116b1a1..5311b09 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -438,7 +438,7 @@ func (cp *cwtchPeer) SendMessage(conversation int, message string) (int, error) // check if we should store this message locally... if cm, err := model.DeserializeMessage(message); err == nil { - if cm.Overlay < 1024 || cm.Overlay&0x7 != 0x7 { + if !cm.IsStream() { // For p2p messages we store the event id of the message as the "signature" we can then look this up in the database later for acks id, err = cp.storage.InsertMessage(conversationInfo.ID, 0, message, model.Attributes{constants.AttrAuthor: string(onion), constants.AttrAck: event.False, constants.AttrSentTimestamp: time.Now().Format(time.RFC3339Nano)}, ev.EventID, model.CalculateContentHash(string(onion), message)) if err != nil { @@ -1490,7 +1490,7 @@ func (cp *cwtchPeer) storeMessage(handle string, message string, sent time.Time) // Don't store messages in channel 7 if cm, err := model.DeserializeMessage(message); err == nil { - if cm.Overlay > 1024 && cm.Overlay&0x7 == 0x7 { + if cm.IsStream() { return -1, nil } } else {