meowlib/client/message.go
ycc 17c991f442
Some checks failed
continuous-integration/drone/push Build is failing
some adjustmentsfor server delivery and peer storage study
2024-05-23 14:14:12 +02:00

51 lines
2.0 KiB
Go

package client
import "forge.redroom.link/yves/meowlib"
type InternalUserMessage struct {
Outbound bool `json:"outbound"`
Messagetype string `json:"messagetype,omitempty"`
Message string `json:"message,omitempty"`
ConversationStatus *meowlib.ConversationStatus `json:"conversation_status,omitempty"`
Contact *meowlib.ContactCard `json:"contact,omitempty"`
ServerDeliveryUuid string `json:"server_delivery_uuid,omitempty"`
ServerDeliveryTimestamp int64 `json:"server_delivery_timestamp,omitempty"`
//Group group
FilePaths []string `json:"file_paths,omitempty"`
CurrentLocation *meowlib.Location `json:"current_location,omitempty"`
Appdata []byte `json:"appdata,omitempty"`
Dbfile string `json:"dbfile,omitempty"`
Dbid int64 `json:"dbid,omitempty"`
}
// InternalUserMessageFromUserMessage creates an InternalUserMessage from a UserMessage
func InternalUserMessageFromUserMessage(peer *Peer, msg *meowlib.UserMessage) *InternalUserMessage {
iu := new(InternalUserMessage)
if peer.ContactPublicKey == msg.From {
iu.Outbound = false
} else {
iu.Outbound = true
}
iu.Messagetype = msg.Type
iu.Message = string(msg.Data)
iu.ConversationStatus = msg.Status
iu.Contact = msg.Contact
return iu
}
func ProcessOutboundTextMessage(peer *Peer, text string, srv *Server) ([]byte, error) {
// Creating User message
usermessage, err := peer.BuildSimpleUserMessage([]byte(text))
if err != nil {
return nil, err
}
// Prepare cyphered + packed user message
packedMsg, err := peer.ProcessOutboundUserMessage(usermessage)
if err != nil {
return nil, err
}
// Creating Server message for transporting the user message
toServerMessage := srv.BuildToServerMessageFromUserMessage(packedMsg)
return srv.ProcessOutboundMessage(toServerMessage)
}