-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
65 lines (55 loc) · 1.56 KB
/
activity.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"github.com/hugolgst/rich-go/client"
lfm "github.com/twangodev/lfm-api"
"golang.org/x/net/html"
)
func createActivity(s lfm.Scrobble, songLink bool) client.Activity {
var songButton *client.Button
// Determines whether to display profile link in buttons
if songLink {
dataLinkTitle := s.DataLinkTitle
dataLink := s.DataLink
if dataLinkTitle == "" {
dataLinkTitle = "View scrobble on Last.fm"
dataLink = fmt.Sprintf("%vmusic/%v/%v", lfm.LastFmUrl, html.EscapeString(s.Artist), html.EscapeString(s.Name))
}
songButton = &client.Button{Label: dataLinkTitle, Url: dataLink}
}
var buttons []*client.Button
if songButton != nil {
buttons = []*client.Button{songButton}
}
if showProfile {
buttons = []*client.Button{{Label: "Visit last.fm Profile", Url: profileUrl}}
}
if showProfile && songButton != nil {
buttons = []*client.Button{{Label: "Visit last.fm Profile", Url: profileUrl}, songButton}
}
// Determines whether to display the heart for the smallImage
smallUrl := "lfm_logo"
if showLoved && s.Loved { // Change small image to heart if user enable loved and scrobble is loved
smallUrl = "heart"
}
var coverUrl string
if covers {
coverUrl = s.CoverArtUrl
}
var timestamps *client.Timestamps
if elapsed {
timestamps = &client.Timestamps{
Start: &s.DataTimestamp,
}
}
return client.Activity{
Details: s.Name,
State: fmt.Sprintf("by %v", s.Artist),
LargeImage: coverUrl,
LargeText: s.Album,
SmallImage: smallUrl,
SmallText: info,
Timestamps: timestamps,
Buttons: buttons,
}
}