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 := 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 xMSG.Body = msg.Body
requestExtensions(&xMSG) 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 return xMSG, nil
case *o3.TextMessage: case *o3.TextMessage:
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: sender, To: a.XMPP.String(), Id: strconv.FormatUint(header.ID, 10)}) xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: sender, To: a.XMPP.String(), Id: strconv.FormatUint(header.ID, 10)})
xMSG.Body = msg.Body xMSG.Body = msg.Body
requestExtensions(&xMSG) 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 return xMSG, nil
/* /*
case o3.AudioMessage: case o3.AudioMessage:
@ -87,7 +95,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
} }
xMSG.Type = "chat" xMSG.Type = "chat"
requestExtensions(&xMSG) requestExtensions(&xMSG)
logger.WithField("url", xMSG.Body).Debug("send audio") logger.WithField("url", xMSG.Body).Debug("recv audio")
return xMSG, nil return xMSG, nil
case o3.ImageMessage: case o3.ImageMessage:
@ -106,7 +114,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
} }
xMSG.Type = "chat" xMSG.Type = "chat"
requestExtensions(&xMSG) requestExtensions(&xMSG)
logger.WithField("url", xMSG.Body).Debug("send image") logger.WithField("url", xMSG.Body).Debug("recv image")
return xMSG, nil return xMSG, nil
*/ */
case *o3.DeliveryReceiptMessage: case *o3.DeliveryReceiptMessage:
@ -134,7 +142,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
} }
if len(xMSG.Extensions) > 0 { if len(xMSG.Extensions) > 0 {
logger.WithField("state", state).Debug("send state") logger.WithField("state", state).Debug("recv state")
return xMSG, nil return xMSG, nil
} }
return nil, nil return nil, nil
@ -145,7 +153,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
} else { } else {
xMSG.Extensions = append(xMSG.Extensions, stanza.StateInactive{}) xMSG.Extensions = append(xMSG.Extensions, stanza.StateInactive{})
} }
logger.Debug(msg.String()) logger.WithField("on", msg.OnOff).Debug("recv typing")
return xMSG, nil return xMSG, nil
} }
return nil, errors.New("not known data format") 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, "from_t": from,
"to": to, "to": to,
}) })
msg3To := o3.NewIDString(to) msg3ID := o3.NewMsgID()
msg3From := o3.NewIDString(from) header := &o3.MessageHeader{
Sender: o3.NewIDString(from),
ID: msg3ID,
Recipient: o3.NewIDString(to),
PubNick: a.ThreemaID.Nick,
}
chatState := false chatState := false
chatStateComposing := false chatStateComposing := false
@ -66,13 +70,9 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) {
return nil, err return nil, err
} }
drm := &o3.DeliveryReceiptMessage{ drm := &o3.DeliveryReceiptMessage{
MessageHeader: &o3.MessageHeader{ MessageHeader: header,
Sender: msg3From, Status: o3.MSGDELIVERED,
ID: id, MessageID: id,
Recipient: msg3To,
PubNick: a.ThreemaID.Nick,
},
Status: o3.MSGDELIVERED,
} }
if msgStateRead { if msgStateRead {
drm.Status = o3.MSGREAD drm.Status = o3.MSGREAD
@ -85,32 +85,22 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) {
} }
if chatState { if chatState {
tnm := &o3.TypingNotificationMessage{ tnm := &o3.TypingNotificationMessage{
MessageHeader: &o3.MessageHeader{ MessageHeader: header,
Sender: msg3From,
Recipient: msg3To,
PubNick: a.ThreemaID.Nick,
},
} }
if chatStateComposing { if chatStateComposing {
tnm.OnOff = 0x1 tnm.OnOff = 0x1
} }
logger.WithFields(map[string]interface{}{ logger.WithFields(map[string]interface{}{
"state": chatStateComposing, "on": tnm.OnOff,
}).Debug("send typing") }).Debug("send typing")
return tnm, nil return tnm, nil
} }
} }
msg3ID := o3.NewMsgID()
// send text message // send text message
msg3 := &o3.TextMessage{ msg3 := &o3.TextMessage{
MessageHeader: &o3.MessageHeader{ MessageHeader: header,
Sender: o3.NewIDString(string(a.AccountThreema.TID)), Body: msg.Body,
ID: msg3ID,
Recipient: msg3To,
PubNick: a.ThreemaID.Nick,
},
Body: msg.Body,
} }
a.deliveredMSG[msg3ID] = msg.Id a.deliveredMSG[msg3ID] = msg.Id
a.readedMSG[msg3ID] = msg.Id a.readedMSG[msg3ID] = msg.Id