Skip to content

Commit 37df847

Browse files
committed
welcome_msg per scope
1 parent 82cdd78 commit 37df847

4 files changed

Lines changed: 57 additions & 8 deletions

File tree

cmd/goatak_server/processors.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,27 @@ func (app *App) saveItemProcessor(msg *cot.CotMessage) bool {
123123
app.items.Store(c)
124124

125125
if cl == model.CONTACT && !online {
126-
app.newContact(c, lastSeen)
126+
app.processNewContact(c, lastSeen)
127127
}
128128
} else {
129129
app.logger.Info(fmt.Sprintf("new %s %s (%s) %s", cl, msg.GetUID(), msg.GetCallsign(), msg.GetType()))
130130
item := model.FromMsg(msg)
131131
app.items.Store(item)
132132

133133
if cl == model.CONTACT {
134-
app.newContact(item, time.Now().Add(-1*model.StaleContactDelete))
134+
app.processNewContact(item, time.Now().Add(-1*model.StaleContactDelete))
135135
}
136136
}
137137

138138
return true
139139
}
140140

141-
func (app *App) newContact(item *model.Item, lastSeen time.Time) {
142-
if time.Since(lastSeen) > time.Hour*24 && app.config.WelcomeMsg() != "" {
143-
chat := chat.MakeChatMessage(item.GetUID(), WELCOME_MESSAGE_FROM_UID, item.GetCallsign(), "", "RootContactGroup", app.config.WelcomeMsg())
144-
app.sendToUID(item.GetUID(), cot.LocalCotMessage(chat))
141+
func (app *App) processNewContact(item *model.Item, lastSeen time.Time) {
142+
if time.Since(lastSeen) > time.Hour*24 {
143+
if msg := app.config.WelcomeForScope(item.GetScope()); msg != "" {
144+
chat := chat.MakeChatMessage(item.GetUID(), WELCOME_MESSAGE_FROM_UID, item.GetCallsign(), "", "RootContactGroup", msg)
145+
app.sendToUID(item.GetUID(), cot.LocalCotMessage(chat))
146+
}
145147
}
146148

147149
msgs := app.messages.GetFor(item, lastSeen)

goatak_server.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ log: false
2020
data_dir: data
2121
# Webtak files root folder
2222
webtak_root: ""
23-
23+
welcome_msg:
24+
test: "Welcome to test group"
25+
2426
me:
2527
lat: 35.462939
2628
lon: -97.537283

internal/config/config.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ func (c *AppConfig) UsersFile() string {
102102
}
103103

104104
func (c *AppConfig) WelcomeMsg() string {
105-
return c.k.String("welcome_msg")
105+
if len(c.k.StringMap("welcome_msg")) == 0 {
106+
return c.k.String("welcome_msg")
107+
}
108+
109+
return ""
110+
}
111+
112+
func (c *AppConfig) WelcomeForScope(scope string) string {
113+
return c.k.StringMap("welcome_msg")[scope]
106114
}
107115

108116
func (c *AppConfig) LogAll() bool {

internal/config/config_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package config
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestWelcome(t *testing.T) {
12+
f, err := os.CreateTemp("", "atak_test")
13+
require.NoError(t, err)
14+
15+
fmt.Fprint(f, "---\nwelcome_msg:\n aaa\n")
16+
f.Close()
17+
18+
c := NewAppConfig()
19+
c.Load(f.Name())
20+
21+
require.Empty(t, c.WelcomeForScope("test"))
22+
require.Equal(t, "aaa", c.WelcomeMsg())
23+
}
24+
25+
func TestWelcomeScope(t *testing.T) {
26+
f, err := os.CreateTemp("", "atak_test")
27+
require.NoError(t, err)
28+
29+
fmt.Fprint(f, "---\nwelcome_msg:\n test: \"aaa\"\n")
30+
f.Close()
31+
32+
c := NewAppConfig()
33+
c.Load(f.Name())
34+
35+
require.Empty(t, c.WelcomeMsg())
36+
require.Equal(t, "aaa", c.WelcomeForScope("test"))
37+
}

0 commit comments

Comments
 (0)