2022-12-02 23:18:13 +01:00
|
|
|
package client
|
|
|
|
|
2023-02-15 22:08:17 +01:00
|
|
|
import "forge.redroom.link/yves/meowlib"
|
|
|
|
|
|
|
|
type InternalUserMessage struct {
|
2024-05-23 14:14:12 +02:00
|
|
|
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"`
|
2024-02-18 13:46:11 +01:00
|
|
|
//Group group
|
2024-03-02 10:07:59 +01:00
|
|
|
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"`
|
2024-02-18 13:46:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// InternalUserMessageFromUserMessage creates an InternalUserMessage from a UserMessage
|
|
|
|
func InternalUserMessageFromUserMessage(peer *Peer, msg *meowlib.UserMessage) *InternalUserMessage {
|
|
|
|
iu := new(InternalUserMessage)
|
|
|
|
if peer.ContactPublicKey == msg.From {
|
2024-02-29 21:03:15 +01:00
|
|
|
iu.Outbound = false
|
2024-02-18 13:46:11 +01:00
|
|
|
} else {
|
2024-02-29 21:03:15 +01:00
|
|
|
iu.Outbound = true
|
2024-02-18 13:46:11 +01:00
|
|
|
}
|
|
|
|
iu.Messagetype = msg.Type
|
|
|
|
iu.Message = string(msg.Data)
|
|
|
|
iu.ConversationStatus = msg.Status
|
|
|
|
iu.Contact = msg.Contact
|
|
|
|
return iu
|
2023-02-15 22:08:17 +01:00
|
|
|
}
|
|
|
|
|
2023-11-08 22:01:44 +01:00
|
|
|
func ProcessOutboundTextMessage(peer *Peer, text string, srv *Server) ([]byte, error) {
|
2022-12-18 19:47:44 +01:00
|
|
|
// Creating User message
|
|
|
|
usermessage, err := peer.BuildSimpleUserMessage([]byte(text))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Prepare cyphered + packed user message
|
2022-12-18 20:59:27 +01:00
|
|
|
packedMsg, err := peer.ProcessOutboundUserMessage(usermessage)
|
2022-12-18 19:47:44 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-12-02 23:18:13 +01:00
|
|
|
// Creating Server message for transporting the user message
|
2022-12-18 20:36:44 +01:00
|
|
|
toServerMessage := srv.BuildToServerMessageFromUserMessage(packedMsg)
|
2022-12-18 20:59:27 +01:00
|
|
|
return srv.ProcessOutboundMessage(toServerMessage)
|
2022-12-17 19:57:02 +01:00
|
|
|
}
|