@@ -6,18 +6,19 @@ import (
66 "time"
77
88 "github.com/google/uuid"
9+
910 "github.com/kdudkov/goatak/pkg/cot"
1011 "github.com/kdudkov/goatak/pkg/cotproto"
1112)
1213
1314type ChatMessage struct {
14- msg * cot.CotMessage
15+ msg * cot.CotMessage
1516 received time.Time
1617}
1718
1819func FromCot (c * cot.CotMessage ) * ChatMessage {
1920 return & ChatMessage {
20- msg : c ,
21+ msg : c ,
2122 received : time .Now (),
2223 }
2324}
@@ -26,59 +27,71 @@ func (c *ChatMessage) GetMessageID() string {
2627 if c == nil || c .msg == nil {
2728 return ""
2829 }
29-
30+
3031 return c .msg .GetDetail ().GetFirst ("__chat" ).GetAttr ("messageId" )
3132}
3233
3334func (c * ChatMessage ) GetChatroom () string {
3435 if c == nil || c .msg == nil {
3536 return ""
3637 }
37-
38+
3839 return c .msg .GetDetail ().GetFirst ("__chat" ).GetAttr ("chatroom" )
3940}
4041
4142func (c * ChatMessage ) GetCallsignFrom () string {
4243 if c == nil || c .msg == nil {
4344 return ""
4445 }
45-
46- return c .msg .GetDetail ().GetFirst ("__chat" ).GetAttr ("senderCallsign" )
46+
47+ if cs := c .msg .GetDetail ().GetFirst ("__chat" ).GetAttr ("senderCallsign" ); cs != "" {
48+ return cs
49+ }
50+
51+ if cs := c .msg .GetDetail ().GetFirst ("fileshare" ).GetAttr ("senderCallsign" ); cs != "" {
52+ return cs
53+ }
54+
55+ return ""
4756}
4857
4958func (c * ChatMessage ) GetUIDTo () string {
5059 if c == nil || c .msg == nil {
5160 return ""
5261 }
53-
62+
5463 return c .msg .GetDetail ().GetFirst ("__chat" ).GetAttr ("id" )
5564}
5665
5766func (c * ChatMessage ) GetUIDFrom () string {
5867 if c == nil || c .msg == nil {
5968 return ""
6069 }
61-
70+
6271 if uid := c .msg .GetDetail ().GetFirst ("__chat" ).GetFirst ("chatgrp" ).GetAttr ("uid0" ); uid != "" {
6372 return uid
6473 }
65-
74+
75+ if uid := c .msg .GetDetail ().GetFirst ("fileshare" ).GetAttr ("senderUid" ); uid != "" {
76+ return uid
77+ }
78+
6679 if uid := c .msg .GetFirstLink ("p-p" ).GetAttr ("uid" ); uid != "" {
67- return uid
80+ return uid
6881 }
69-
82+
7083 return ""
7184}
7285
7386func (c * ChatMessage ) GetText () string {
7487 if c == nil || c .msg == nil {
7588 return ""
7689 }
77-
90+
7891 if rem := c .msg .GetDetail ().GetFirst ("remarks" ); rem != nil {
7992 return html .UnescapeString (rem .GetText ())
8093 }
81-
94+
8295 return ""
8396}
8497
@@ -119,7 +132,7 @@ func (c *ChatMessage) GetText() string {
119132
120133// return c
121134// }
122- //
135+ //
123136
124137func MakeChatMessage (toUID , fromUID , chatroom , from , parent , text string ) * cotproto.TakMessage {
125138 t := time .Now ().UTC ().Format (time .RFC3339 )
@@ -143,4 +156,4 @@ func MakeChatMessage(toUID, fromUID, chatroom, from, parent, text string) *cotpr
143156 msg .CotEvent .Detail = & cotproto.Detail {XmlDetail : xd .AsXMLString ()}
144157
145158 return msg
146- }
159+ }
0 commit comments