Skip to content

Commit 2698ca9

Browse files
authored
remove hardcoded subreddit (#104)
1 parent 5c2da7c commit 2698ca9

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb
1515
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
1616
github.com/json-iterator/go v1.1.5
17-
github.com/kevinburke/go-bindata v3.21.0+incompatible // indirect
17+
github.com/kevinburke/go-bindata v3.23.0+incompatible // indirect
1818
github.com/labstack/echo v3.2.6+incompatible
1919
github.com/labstack/gommon v0.2.2-0.20170925052817-57409ada9da0
2020
github.com/magiconair/properties v1.7.6

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ github.com/kevinburke/go-bindata v3.16.0+incompatible h1:TFzFZop2KxGhqNwsyjgmIh5
2929
github.com/kevinburke/go-bindata v3.16.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
3030
github.com/kevinburke/go-bindata v3.21.0+incompatible h1:baK7hwFJDlAHrOqmE9U3u8tow1Uc5ihN9E/b7djcK2g=
3131
github.com/kevinburke/go-bindata v3.21.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
32+
github.com/kevinburke/go-bindata v3.23.0+incompatible h1:rqNOXZlqrYhMVVAsQx8wuc+LaA73YcfbQ407wAykyS8=
33+
github.com/kevinburke/go-bindata v3.23.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
3234
github.com/labstack/echo v3.2.6+incompatible h1:28U/uXFFKBIP+VQIqq641LuYhMS7Br9ZlwEXERaohCc=
3335
github.com/labstack/echo v3.2.6+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
3436
github.com/labstack/gommon v0.2.2-0.20170925052817-57409ada9da0 h1:7AIW1qc9sYYTZLamTsRKSmVvJDXkZZrIWXHDK4Gq4X0=

server/index_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var index = `<!DOCTYPE html><html>
6868
</footer>
6969
</div>
7070
71-
<script src="static/index.js?v6"></script>
71+
<script src="static/index.js?v7"></script>
7272
</body>
7373
</html>`
7474

server/reddit_comment.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type RedditComment struct {
1313
PostId string `json:"post_id"`
1414
PostTitle string `json:"post_title"`
1515
Time time.Time `json:"time"`
16+
17+
// Added in August 2022. Comments stored before then may not have this.
18+
Subreddit string `json:"subreddit"`
1619
}
1720

1821
func (c *RedditComment) ActivityTime() time.Time {
@@ -25,9 +28,17 @@ func (c *RedditComment) ActivityKey() uint32 {
2528
}
2629

2730
func (c *RedditComment) PostURL() string {
28-
return fmt.Sprintf("https://www.reddit.com/r/pathofexile/comments/%v/", c.PostId)
31+
subreddit := "pathofexile"
32+
if c.Subreddit != "" {
33+
subreddit = c.Subreddit
34+
}
35+
return fmt.Sprintf("https://www.reddit.com/r/%v/comments/%v/", subreddit, c.PostId)
2936
}
3037

3138
func (c *RedditComment) CommentURL() string {
32-
return fmt.Sprintf("https://www.reddit.com/r/pathofexile/comments/%v/-/%v/?context=3", c.PostId, c.Id)
39+
subreddit := "pathofexile"
40+
if c.Subreddit != "" {
41+
subreddit = c.Subreddit
42+
}
43+
return fmt.Sprintf("https://www.reddit.com/r/%v/comments/%v/-/%v/?context=3", subreddit, c.PostId, c.Id)
3344
}

server/reddit_indexer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func ParseRedditActivity(b []byte) ([]Activity, string, error) {
8383
CreatedUTC float64 `json:"created_utc"`
8484
LinkId string `json:"link_id"`
8585
LinkTitle string `json:"link_title"`
86+
Subreddit string `json:"subreddit"`
8687
} `json:"data"`
8788
} `json:"children"`
8889
} `json:"data"`
@@ -105,6 +106,7 @@ func ParseRedditActivity(b []byte) ([]Activity, string, error) {
105106
PostId: strings.TrimPrefix(thing.Data.LinkId, "t3_"),
106107
PostTitle: thing.Data.LinkTitle,
107108
Time: time.Unix(int64(thing.Data.CreatedUTC), 0),
109+
Subreddit: thing.Data.Subreddit,
108110
})
109111
case "t3":
110112
activity = append(activity, &RedditPost{
@@ -115,6 +117,7 @@ func ParseRedditActivity(b []byte) ([]Activity, string, error) {
115117
Title: thing.Data.Title,
116118
URL: thing.Data.URL,
117119
Time: time.Unix(int64(thing.Data.CreatedUTC), 0),
120+
Subreddit: thing.Data.Subreddit,
118121
})
119122
}
120123
}

server/reddit_indexer_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ func TestParseRedditComments(t *testing.T) {
3030
assert.Equal(t, "/r/pathofexile/comments/5q12qc/another_update_on_singapore_fibre_cuts/", post.Permalink)
3131
assert.Equal(t, "Another Update on Singapore Fibre Cuts", post.Title)
3232
assert.Equal(t, time.Unix(1485316926, 0), post.Time)
33+
assert.Equal(t, "pathofexile", post.Subreddit)
3334

3435
comment, ok := activity[1].(*RedditComment)
3536
require.True(t, ok)
3637
assert.Equal(t, "chris_wilson", comment.Author)
3738
assert.Equal(t, "5plxw0", comment.PostId)
3839
assert.Equal(t, "Development Manifesto: Solo Self-Found Support in 2.6.0", comment.PostTitle)
3940
assert.Equal(t, time.Unix(1485287813, 0), comment.Time)
41+
assert.Equal(t, "pathofexile", comment.Subreddit)
4042
}

server/reddit_post.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type RedditPost struct {
1313
BodyHTML string `json:"body_html,omitempty"`
1414
Permalink string `json:"permalink"`
1515
Time time.Time `json:"time"`
16+
17+
// Added in August 2022. Comments stored before then may not have this.
18+
Subreddit string `json:"subreddit"`
1619
}
1720

1821
func (p *RedditPost) ActivityTime() time.Time {

server/static/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function loadActivity() {
3030
for (var i = 0; i < data.activity.length; ++i) {
3131
var type = data.activity[i].type;
3232
var activity = data.activity[i].data;
33+
var subreddit = activity.subreddit || 'pathofexile';
3334
var $tr = $('<tr>').addClass(type == 'forum_post' ? 'forum' : 'reddit').addClass(type.replace('/_/', '-'));
3435

3536
var $toggleTD = $('<td class="toggle">');
@@ -42,7 +43,7 @@ function loadActivity() {
4243
));
4344
} else if (type == 'reddit_comment') {
4445
$tr.append($('<td class="icon">').append($('<a>')
45-
.attr('href', 'https://www.reddit.com/r/pathofexile/comments/' + activity.post_id)
46+
.attr('href', 'https://www.reddit.com/r/' + subreddit + '/comments/' + activity.post_id)
4647
.append($('<img src="static/images/snoo.png" />'))
4748
));
4849
} else {
@@ -64,7 +65,7 @@ function loadActivity() {
6465
));
6566
} else if (type == "reddit_comment") {
6667
$tr.append($('<td class="title">').append($('<a>')
67-
.attr('href', 'https://www.reddit.com/r/pathofexile/comments/' + activity.post_id + '/-/' + activity.id + '/?context=3')
68+
.attr('href', 'https://www.reddit.com/r/' + subreddit + '/comments/' + activity.post_id + '/-/' + activity.id + '/?context=3')
6869
.text(activity.post_title)
6970
));
7071
}
@@ -90,8 +91,8 @@ function loadActivity() {
9091
));
9192
} else {
9293
$tr.append($('<td class="forum">').append($('<a>')
93-
.attr('href', 'https://www.reddit.com/r/pathofexile')
94-
.text('pathofexile')
94+
.attr('href', 'https://www.reddit.com/r/' + subreddit)
95+
.text(subreddit)
9596
));
9697
}
9798

0 commit comments

Comments
 (0)