Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
remove hardcoded subreddit
  • Loading branch information
ccbrown committed Aug 9, 2022
commit 2bb0261a02d6d95ba9fbbcf16d623c3d89d4902b
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
github.com/json-iterator/go v1.1.5
github.com/kevinburke/go-bindata v3.21.0+incompatible // indirect
github.com/kevinburke/go-bindata v3.23.0+incompatible // indirect
github.com/labstack/echo v3.2.6+incompatible
github.com/labstack/gommon v0.2.2-0.20170925052817-57409ada9da0
github.com/magiconair/properties v1.7.6
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/kevinburke/go-bindata v3.16.0+incompatible h1:TFzFZop2KxGhqNwsyjgmIh5
github.com/kevinburke/go-bindata v3.16.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/kevinburke/go-bindata v3.21.0+incompatible h1:baK7hwFJDlAHrOqmE9U3u8tow1Uc5ihN9E/b7djcK2g=
github.com/kevinburke/go-bindata v3.21.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/kevinburke/go-bindata v3.23.0+incompatible h1:rqNOXZlqrYhMVVAsQx8wuc+LaA73YcfbQ407wAykyS8=
github.com/kevinburke/go-bindata v3.23.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/labstack/echo v3.2.6+incompatible h1:28U/uXFFKBIP+VQIqq641LuYhMS7Br9ZlwEXERaohCc=
github.com/labstack/echo v3.2.6+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/gommon v0.2.2-0.20170925052817-57409ada9da0 h1:7AIW1qc9sYYTZLamTsRKSmVvJDXkZZrIWXHDK4Gq4X0=
Expand Down
2 changes: 1 addition & 1 deletion server/index_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var index = `<!DOCTYPE html><html>
</footer>
</div>

<script src="static/index.js?v6"></script>
<script src="static/index.js?v7"></script>
</body>
</html>`

Expand Down
15 changes: 13 additions & 2 deletions server/reddit_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type RedditComment struct {
PostId string `json:"post_id"`
PostTitle string `json:"post_title"`
Time time.Time `json:"time"`

// Added in August 2022. Comments stored before then may not have this.
Subreddit string `json:"subreddit"`
}

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

func (c *RedditComment) PostURL() string {
return fmt.Sprintf("https://www.reddit.com/r/pathofexile/comments/%v/", c.PostId)
subreddit := "pathofexile"
if c.Subreddit != "" {
subreddit = c.Subreddit
}
return fmt.Sprintf("https://www.reddit.com/r/%v/comments/%v/", subreddit, c.PostId)
}

func (c *RedditComment) CommentURL() string {
return fmt.Sprintf("https://www.reddit.com/r/pathofexile/comments/%v/-/%v/?context=3", c.PostId, c.Id)
subreddit := "pathofexile"
if c.Subreddit != "" {
subreddit = c.Subreddit
}
return fmt.Sprintf("https://www.reddit.com/r/%v/comments/%v/-/%v/?context=3", subreddit, c.PostId, c.Id)
}
3 changes: 3 additions & 0 deletions server/reddit_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func ParseRedditActivity(b []byte) ([]Activity, string, error) {
CreatedUTC float64 `json:"created_utc"`
LinkId string `json:"link_id"`
LinkTitle string `json:"link_title"`
Subreddit string `json:"subreddit"`
} `json:"data"`
} `json:"children"`
} `json:"data"`
Expand All @@ -105,6 +106,7 @@ func ParseRedditActivity(b []byte) ([]Activity, string, error) {
PostId: strings.TrimPrefix(thing.Data.LinkId, "t3_"),
PostTitle: thing.Data.LinkTitle,
Time: time.Unix(int64(thing.Data.CreatedUTC), 0),
Subreddit: thing.Data.Subreddit,
})
case "t3":
activity = append(activity, &RedditPost{
Expand All @@ -115,6 +117,7 @@ func ParseRedditActivity(b []byte) ([]Activity, string, error) {
Title: thing.Data.Title,
URL: thing.Data.URL,
Time: time.Unix(int64(thing.Data.CreatedUTC), 0),
Subreddit: thing.Data.Subreddit,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/reddit_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ func TestParseRedditComments(t *testing.T) {
assert.Equal(t, "/r/pathofexile/comments/5q12qc/another_update_on_singapore_fibre_cuts/", post.Permalink)
assert.Equal(t, "Another Update on Singapore Fibre Cuts", post.Title)
assert.Equal(t, time.Unix(1485316926, 0), post.Time)
assert.Equal(t, "pathofexile", post.Subreddit)

comment, ok := activity[1].(*RedditComment)
require.True(t, ok)
assert.Equal(t, "chris_wilson", comment.Author)
assert.Equal(t, "5plxw0", comment.PostId)
assert.Equal(t, "Development Manifesto: Solo Self-Found Support in 2.6.0", comment.PostTitle)
assert.Equal(t, time.Unix(1485287813, 0), comment.Time)
assert.Equal(t, "pathofexile", comment.Subreddit)
}
3 changes: 3 additions & 0 deletions server/reddit_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type RedditPost struct {
BodyHTML string `json:"body_html,omitempty"`
Permalink string `json:"permalink"`
Time time.Time `json:"time"`

// Added in August 2022. Comments stored before then may not have this.
Subreddit string `json:"subreddit"`
}

func (p *RedditPost) ActivityTime() time.Time {
Expand Down
9 changes: 5 additions & 4 deletions server/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function loadActivity() {
for (var i = 0; i < data.activity.length; ++i) {
var type = data.activity[i].type;
var activity = data.activity[i].data;
var subreddit = activity.subreddit || 'pathofexile';
var $tr = $('<tr>').addClass(type == 'forum_post' ? 'forum' : 'reddit').addClass(type.replace('/_/', '-'));

var $toggleTD = $('<td class="toggle">');
Expand All @@ -42,7 +43,7 @@ function loadActivity() {
));
} else if (type == 'reddit_comment') {
$tr.append($('<td class="icon">').append($('<a>')
.attr('href', 'https://www.reddit.com/r/pathofexile/comments/' + activity.post_id)
.attr('href', 'https://www.reddit.com/r/' + subreddit + '/comments/' + activity.post_id)
.append($('<img src="static/images/snoo.png" />'))
));
} else {
Expand All @@ -64,7 +65,7 @@ function loadActivity() {
));
} else if (type == "reddit_comment") {
$tr.append($('<td class="title">').append($('<a>')
.attr('href', 'https://www.reddit.com/r/pathofexile/comments/' + activity.post_id + '/-/' + activity.id + '/?context=3')
.attr('href', 'https://www.reddit.com/r/' + subreddit + '/comments/' + activity.post_id + '/-/' + activity.id + '/?context=3')
.text(activity.post_title)
));
}
Expand All @@ -90,8 +91,8 @@ function loadActivity() {
));
} else {
$tr.append($('<td class="forum">').append($('<a>')
.attr('href', 'https://www.reddit.com/r/pathofexile')
.text('pathofexile')
.attr('href', 'https://www.reddit.com/r/' + subreddit)
.text(subreddit)
));
}

Expand Down