-
Notifications
You must be signed in to change notification settings - Fork 0
/
decorate.go
33 lines (30 loc) · 814 Bytes
/
decorate.go
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
package wallet
import (
"context"
"github.com/adamwalz/keybase-client/go/chat/utils"
"github.com/adamwalz/keybase-client/go/protocol/chat1"
)
func DecorateWithPayments(ctx context.Context, body string, payments []chat1.TextPayment) string {
var added int
seen := make(map[string]struct{})
paymentMap := make(map[string]chat1.TextPayment)
for _, p := range payments {
paymentMap[p.PaymentText] = p
}
offset := 0
parsed := FindChatTxCandidates(body)
for _, p := range parsed {
payment, ok := paymentMap[p.Full]
if !ok {
continue
}
if _, ok := seen[p.Full]; ok {
continue
}
seen[p.Full] = struct{}{}
body, added = utils.DecorateBody(ctx, body, p.Position[0]+offset, p.Position[1]-p.Position[0],
chat1.NewUITextDecorationWithPayment(payment))
offset += added
}
return body
}