Util Functions for MW
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Sarah Jamie Lewis 2024-02-11 14:44:18 -08:00
parent 3124f7b7c4
commit 1a034953df
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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 {