github.com/status-im/status-go@v1.1.0/protocol/common/raw_message.go (about)

     1  package common
     2  
     3  import (
     4  	"crypto/ecdsa"
     5  
     6  	"github.com/status-im/status-go/protocol/protobuf"
     7  )
     8  
     9  type CommKeyExMsgType uint8
    10  
    11  const (
    12  	KeyExMsgNone  CommKeyExMsgType = 0
    13  	KeyExMsgReuse CommKeyExMsgType = 1
    14  	KeyExMsgRekey CommKeyExMsgType = 2
    15  )
    16  
    17  // ResendType There are distinct mechanisms for retrying send messages: Datasync supports only direct messages (1-to-1 or private group chats)
    18  // because it requires an acknowledgment (ACK). As implemented, sending a message to a community, where hundreds of
    19  // people receive it, would lead all recipients to attempt sending an ACK, resulting in an excessive number of messages.
    20  // Datasync utilizes ACKs, but community messages do not, to avoid this issue. However, we still aim to retry sending
    21  // community messages if they fail to send or if we are offline.
    22  type ResendType uint8
    23  
    24  const (
    25  	// ResendTypeNone won't resend
    26  	ResendTypeNone ResendType = 0
    27  	// ResendTypeDataSync use DataSync which use MVDS as underlying dependency to resend messages.
    28  	// Works only when underlying sending method is MessageSender#SendPrivate. Pls see SendPrivate for more details.
    29  	// For usage example, you can find usage with this type value in this project. e.g. Messenger#syncContact
    30  	ResendTypeDataSync ResendType = 1
    31  	// ResendTypeRawMessage We have a function, watchExpiredMessages, that monitors the 'raw_messages' table
    32  	// and will attempts to resend messages if a previous message sending failed.
    33  	ResendTypeRawMessage ResendType = 2
    34  )
    35  
    36  // ResendMethod defines how to resend a raw message
    37  type ResendMethod uint8
    38  
    39  const (
    40  	// ResendMethodDynamic determined by logic of Messenger#dispatchMessage, mostly based on chat type
    41  	ResendMethodDynamic ResendMethod = 0
    42  	// ResendMethodSendPrivate corresponding function MessageSender#SendPrivate
    43  	ResendMethodSendPrivate ResendMethod = 1
    44  	// ResendMethodSendCommunityMessage corresponding function MessageSender#SendCommunityMessage
    45  	ResendMethodSendCommunityMessage ResendMethod = 2
    46  )
    47  
    48  // MessagePriority determines the ordering for publishing  message
    49  type MessagePriority = int
    50  
    51  var (
    52  	LowPriority    MessagePriority = 0
    53  	NormalPriority MessagePriority = 1
    54  	HighPriority   MessagePriority = 2
    55  )
    56  
    57  // RawMessage represent a sent or received message, kept for being able
    58  // to re-send/propagate
    59  type RawMessage struct {
    60  	ID          string
    61  	LocalChatID string
    62  	LastSent    uint64
    63  	SendCount   int
    64  	Sent        bool
    65  	// don't wrap message into ProtocolMessage.
    66  	// when this is true, the message will not be resent via ResendTypeDataSync, but it's possible to
    67  	// resend it via ResendTypeRawMessage specified in ResendType
    68  	// MVDS only supports sending encrypted message.
    69  	SkipEncryptionLayer   bool
    70  	SendPushNotification  bool
    71  	MessageType           protobuf.ApplicationMetadataMessage_Type
    72  	Payload               []byte
    73  	Sender                *ecdsa.PrivateKey
    74  	Recipients            []*ecdsa.PublicKey
    75  	SkipGroupMessageWrap  bool
    76  	SkipApplicationWrap   bool
    77  	SendOnPersonalTopic   bool
    78  	CommunityID           []byte
    79  	CommunityKeyExMsgType CommKeyExMsgType
    80  	Ephemeral             bool
    81  	BeforeDispatch        func(*RawMessage) error
    82  	HashRatchetGroupID    []byte
    83  	PubsubTopic           string
    84  	ResendType            ResendType
    85  	ResendMethod          ResendMethod
    86  	Priority              *MessagePriority
    87  }