some cleanup + logging

This commit is contained in:
Martin/Geno 2019-09-06 03:57:27 +02:00 committed by genofire
parent 887d6ac3ff
commit 7e53697945
2 changed files with 28 additions and 30 deletions

View File

@ -62,13 +62,21 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeGroupchat, From: jidFromThreemaGroup(sender, msg.GroupMessageHeader), To: a.XMPP.String(), Id: strconv.FormatUint(header.ID, 10)})
xMSG.Body = msg.Body
requestExtensions(&xMSG)
logger.WithField("text", xMSG.Body).Debug("send text")
logger.WithFields(map[string]interface{}{
"from_x": xMSG.From,
"id": xMSG.Id,
"text": xMSG.Body,
}).Debug("recv grouptext")
return xMSG, nil
case *o3.TextMessage:
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: sender, To: a.XMPP.String(), Id: strconv.FormatUint(header.ID, 10)})
xMSG.Body = msg.Body
requestExtensions(&xMSG)
logger.WithField("text", xMSG.Body).Debug("send text")
logger.WithFields(map[string]interface{}{
"from_x": xMSG.From,
"id": xMSG.Id,
"text": xMSG.Body,
}).Debug("recv text")
return xMSG, nil
/*
case o3.AudioMessage:
@ -87,7 +95,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
}
xMSG.Type = "chat"
requestExtensions(&xMSG)
logger.WithField("url", xMSG.Body).Debug("send audio")
logger.WithField("url", xMSG.Body).Debug("recv audio")
return xMSG, nil
case o3.ImageMessage:
@ -106,7 +114,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
}
xMSG.Type = "chat"
requestExtensions(&xMSG)
logger.WithField("url", xMSG.Body).Debug("send image")
logger.WithField("url", xMSG.Body).Debug("recv image")
return xMSG, nil
*/
case *o3.DeliveryReceiptMessage:
@ -134,7 +142,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
}
if len(xMSG.Extensions) > 0 {
logger.WithField("state", state).Debug("send state")
logger.WithField("state", state).Debug("recv state")
return xMSG, nil
}
return nil, nil
@ -145,7 +153,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
} else {
xMSG.Extensions = append(xMSG.Extensions, stanza.StateInactive{})
}
logger.Debug(msg.String())
logger.WithField("on", msg.OnOff).Debug("recv typing")
return xMSG, nil
}
return nil, errors.New("not known data format")

View File

@ -25,9 +25,13 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) {
"from_t": from,
"to": to,
})
msg3To := o3.NewIDString(to)
msg3From := o3.NewIDString(from)
msg3ID := o3.NewMsgID()
header := &o3.MessageHeader{
Sender: o3.NewIDString(from),
ID: msg3ID,
Recipient: o3.NewIDString(to),
PubNick: a.ThreemaID.Nick,
}
chatState := false
chatStateComposing := false
@ -66,13 +70,9 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) {
return nil, err
}
drm := &o3.DeliveryReceiptMessage{
MessageHeader: &o3.MessageHeader{
Sender: msg3From,
ID: id,
Recipient: msg3To,
PubNick: a.ThreemaID.Nick,
},
MessageHeader: header,
Status: o3.MSGDELIVERED,
MessageID: id,
}
if msgStateRead {
drm.Status = o3.MSGREAD
@ -85,31 +85,21 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) {
}
if chatState {
tnm := &o3.TypingNotificationMessage{
MessageHeader: &o3.MessageHeader{
Sender: msg3From,
Recipient: msg3To,
PubNick: a.ThreemaID.Nick,
},
MessageHeader: header,
}
if chatStateComposing {
tnm.OnOff = 0x1
}
logger.WithFields(map[string]interface{}{
"state": chatStateComposing,
"on": tnm.OnOff,
}).Debug("send typing")
return tnm, nil
}
}
msg3ID := o3.NewMsgID()
// send text message
msg3 := &o3.TextMessage{
MessageHeader: &o3.MessageHeader{
Sender: o3.NewIDString(string(a.AccountThreema.TID)),
ID: msg3ID,
Recipient: msg3To,
PubNick: a.ThreemaID.Nick,
},
MessageHeader: header,
Body: msg.Body,
}
a.deliveredMSG[msg3ID] = msg.Id