54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package client
|
|
|
|
import "forge.redroom.link/yves/meowlib"
|
|
|
|
const (
|
|
Inbound = 0
|
|
Outbound = 1
|
|
)
|
|
|
|
type InternalUserMessage struct {
|
|
Outbound bool // 0 = inbound, 1 = outbound
|
|
Messagetype string
|
|
Message string
|
|
ConversationStatus *meowlib.ConversationStatus
|
|
Contact *meowlib.ContactCard
|
|
//Group group
|
|
FilePaths []string
|
|
CurrentLocation *meowlib.Location
|
|
Appdata []byte
|
|
Dbfile string
|
|
Dbid int64
|
|
}
|
|
|
|
// 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)
|
|
}
|