-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelper.go
More file actions
49 lines (45 loc) · 1.63 KB
/
Copy pathhelper.go
File metadata and controls
49 lines (45 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"strings"
"time"
)
// mentionVisible reports whether a mentioned user whose room subscription carries
// historySharedSince may see a thread reply whose parent was created at
// parentCreatedAt. Mirrors notification-worker.isRestricted (inverted to
// "visible"): a nil window means full access; a set window with a missing or
// older parent timestamp means no access.
func mentionVisible(historySharedSince, parentCreatedAt *time.Time) bool {
if historySharedSince == nil {
return true
}
if parentCreatedAt == nil {
return false
}
return !parentCreatedAt.Before(*historySharedSince)
}
// isBot returns true if account follows the bot naming convention used across
// the codebase (suffix `.bot` or prefix `p_`). Mirrors the predicate in
// message-gatekeeper/helper.go and room-service/helper.go — promoting to a
// shared pkg/botid is a future cleanup; keep these copies in sync if the
// convention changes.
func isBot(account string) bool {
return strings.HasSuffix(account, ".bot") || strings.HasPrefix(account, "p_")
}
// dedupedAccounts prepends sender to mentions, dropping later duplicates.
// Sender comes first so the deduped list shape is stable across the
// no-mention and mention paths regardless of whether the sender is also
// @-mentioned in the content.
func dedupedAccounts(sender string, mentions []string) []string {
out := make([]string, 0, 1+len(mentions))
seen := make(map[string]struct{}, 1+len(mentions))
out = append(out, sender)
seen[sender] = struct{}{}
for _, a := range mentions {
if _, ok := seen[a]; ok {
continue
}
seen[a] = struct{}{}
out = append(out, a)
}
return out
}