Skip to content

Commit 5bf5147

Browse files
committed
fmt
1 parent 3e1636f commit 5bf5147

24 files changed

+141
-54
lines changed

cmd/goatak_server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (app *App) Run() {
9696
if err := app.messages.Start(); err != nil {
9797
log.Fatal(err)
9898
}
99-
99+
100100
ctx, cancel := context.WithCancel(context.Background())
101101

102102
if addr := app.config.String("udp_addr"); addr != "" {

cmd/goatak_server/processors.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (app *App) InitMessageProcessors() {
3636

3737
app.AddEventProcessor("metrics", app.metricsProcessor, "t-x-c-m")
3838
app.AddEventProcessor("remove", app.removeItemProcessor, "t-x-d-d")
39-
app.AddEventProcessor("chat", app.chatProcessor, "b-t-f", "b-t-f-")
39+
app.AddEventProcessor("chat", app.chatProcessor, "b-t-f", "b-t-f-", "b-f-t-")
4040
app.AddEventProcessor("items", app.saveItemProcessor, "a-", "b-", "u-")
4141
app.AddEventProcessor("filter_control", filterProcessor, "t-")
4242

@@ -94,7 +94,7 @@ func (app *App) removeItemProcessor(msg *cot.CotMessage) bool {
9494
}
9595

9696
func (app *App) chatProcessor(msg *cot.CotMessage) bool {
97-
if msg.IsChat() {
97+
if msg.IsChat() || msg.IsFileTransfer() {
9898
c := chat.FromCot(msg)
9999
app.messages.Add(c)
100100

@@ -125,7 +125,6 @@ func (app *App) saveItemProcessor(msg *cot.CotMessage) bool {
125125
if cl == model.CONTACT && !online {
126126
app.newContact(c, lastSeen)
127127
}
128-
129128
} else {
130129
app.logger.Info(fmt.Sprintf("new %s %s (%s) %s", cl, msg.GetUID(), msg.GetCallsign(), msg.GetType()))
131130
item := model.FromMsg(msg)

cmd/goatak_server/tak_ws/tak_ws.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tak_ws
33
import (
44
"bufio"
55
"bytes"
6+
"errors"
67
"fmt"
78
"log/slog"
89
"strings"
@@ -114,7 +115,7 @@ func (w *WsClientHandler) SendCot(msg *cotproto.TakMessage) error {
114115
return nil
115116
}
116117

117-
return fmt.Errorf("client is off")
118+
return errors.New("client is off")
118119
}
119120

120121
func (w *WsClientHandler) tryAddPacket(msg []byte) bool {

pkg/chat/chat_message.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1314
type ChatMessage struct {
14-
msg *cot.CotMessage
15+
msg *cot.CotMessage
1516
received time.Time
1617
}
1718

1819
func 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

3334
func (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

4142
func (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

4958
func (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

5766
func (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

7386
func (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

124137
func 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+
}

pkg/chat/storage.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ func (s *Storage) Add(c *ChatMessage) {
2525

2626
func (s *Storage) Start() error {
2727
go func() {
28-
for range time.Tick(time.Second*60) {
28+
for range time.Tick(time.Second * 60) {
2929
s.clean()
3030
}
31-
3231
}()
33-
32+
3433
return nil
3534
}
3635

@@ -59,13 +58,15 @@ func (s *Storage) GetFor(item *model.Item, t time.Time) []*cot.CotMessage {
5958
if dest := c.msg.GetDetail().GetDestCallsign(); len(dest) > 0 {
6059
if slices.Contains(dest, item.GetCallsign()) {
6160
res = append(res, c.msg)
61+
6262
return true
6363
}
6464

6565
return true
6666
}
6767

6868
res = append(res, c.msg)
69+
6970
return true
7071
})
7172

pkg/cot/cotmessage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ func (m *CotMessage) IsChatReceipt() bool {
207207
return false
208208
}
209209

210-
return m.GetType() == "b-t-f-r" || m.GetType() == "b-t-f-d"
210+
return m.GetType() == "b-t-f-d" || m.GetType() == "b-t-f-p" ||
211+
m.GetType() == "b-t-f-r" || m.GetType() == "b-t-f-s" || m.GetType() == "b-t-f-u"
211212
}
212213

213214
func (m *CotMessage) IsFileTransfer() bool {

pkg/cot/messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var messages = map[string]string{
6868
"b-t-f-p": "Chat pending receipt",
6969
"b-t-f-r": "Chat read receipt",
7070
"b-t-f-s": "Chat delivery failure",
71+
"b-t-f-u": "Chat ??",
7172
"b-w": "Weather",
7273
"c": "Capability",
7374
"r": "Area restrictions",

pkg/cot/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
package cot
33

44
import (
5-
"slices"
65
"bytes"
76
"encoding/xml"
87
"fmt"
8+
"slices"
99
"strings"
1010
)
1111

pkg/cotproto/binarypayload.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cotproto/contact.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)