Skip to content

Commit a11db20

Browse files
committed
add filtering of help posts
1 parent bcc3536 commit a11db20

File tree

5 files changed

+77
-9
lines changed

5 files changed

+77
-9
lines changed

server/activity_handler.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package server
22

33
import (
44
"github.com/labstack/echo"
5+
log "github.com/sirupsen/logrus"
56
)
67

78
type jsonResponseActivity struct {
@@ -16,7 +17,7 @@ type jsonResponse struct {
1617

1718
func ActivityHandler(db Database) echo.HandlerFunc {
1819
return func(c echo.Context) error {
19-
activity, next, err := db.Activity(LocaleForRequest(c.Request()), c.QueryParam("next"), 50)
20+
activity, next, err := fetchActivity(db, LocaleForRequest(c.Request()), c.QueryParam("next"), c.QueryParam("nohelp") == "true")
2021
if err != nil {
2122
return err
2223
}
@@ -41,3 +42,44 @@ func ActivityHandler(db Database) echo.HandlerFunc {
4142
return c.JSON(200, response)
4243
}
4344
}
45+
46+
const MinPageSize = 50
47+
const DbRequestSize = 50
48+
const MaxDbRequests = 10
49+
50+
func fetchActivity(db Database, locale *Locale, start string, nohelp bool) ([]Activity, string, error) {
51+
activity := []Activity{}
52+
next := start
53+
for i := 0; i < MaxDbRequests && len(activity) < MinPageSize; i++ {
54+
as, n, err := db.Activity(locale, next, DbRequestSize)
55+
if err != nil {
56+
return nil, "", err
57+
}
58+
next = n
59+
if len(as) == 0 && n == "" {
60+
log.Debug("end of activity db")
61+
break
62+
}
63+
skipped := 0
64+
if nohelp {
65+
for _, a := range as {
66+
if fp, ok := a.(*ForumPost); ok {
67+
if fp.ForumId == locale.HelpForumId {
68+
skipped++
69+
continue
70+
}
71+
}
72+
activity = append(activity, a)
73+
}
74+
} else {
75+
activity = append(activity, as...)
76+
}
77+
log.WithFields(log.Fields{
78+
"count": len(as),
79+
"buffered": len(activity),
80+
"skipped": skipped,
81+
"next": next,
82+
}).Debug("processed activity batch")
83+
}
84+
return activity, next, nil
85+
}

server/index_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var index = `<!DOCTYPE html><html>
5858
<tbody>
5959
</tbody>
6060
</table>
61-
<div id="activity-nav" class="right"></div>
61+
<div id="activity-nav"></div>
6262
</div>
6363
<footer>
6464
<p>This site is not affiliated with Path of Exile or Grinding Gear Games in any way.</p>

server/localization.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Locale struct {
1717
IncludeReddit bool
1818
Translations map[string]string
1919
ParseTime func(s string, tz *time.Location) (time.Time, error)
20+
HelpForumId int
2021

2122
forumIds atomic.Value
2223
}
@@ -95,6 +96,7 @@ var Locales = []*Locale{
9596
{
9697
IncludeReddit: true,
9798
Image: "static/images/locales/gb.png",
99+
HelpForumId: 584,
98100
},
99101
{
100102
Subdomain: "br",
@@ -106,6 +108,7 @@ var Locales = []*Locale{
106108
"Time": "Hora",
107109
"Forum": "Fórum",
108110
},
111+
HelpForumId: 774,
109112
},
110113
{
111114
Subdomain: "ru",
@@ -119,8 +122,9 @@ var Locales = []*Locale{
119122
},
120123
},
121124
{
122-
Subdomain: "th",
123-
Image: "static/images/locales/th.png",
125+
Subdomain: "th",
126+
Image: "static/images/locales/th.png",
127+
HelpForumId: 1011,
124128
},
125129
{
126130
Subdomain: "de",
@@ -132,6 +136,7 @@ var Locales = []*Locale{
132136
"Time": "Datum",
133137
"Forum": "Forum",
134138
},
139+
HelpForumId: 1123,
135140
},
136141
{
137142
Subdomain: "fr",
@@ -143,6 +148,7 @@ var Locales = []*Locale{
143148
"Time": "Date",
144149
"Forum": "Forum",
145150
},
151+
HelpForumId: 1051,
146152
},
147153
{
148154
Subdomain: "es",
@@ -154,6 +160,7 @@ var Locales = []*Locale{
154160
"Time": "Fecha",
155161
"Forum": "Foro",
156162
},
163+
HelpForumId: 1193,
157164
},
158165
{
159166
Subdomain: "jp",

server/static/index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ var POE = {
1616
};
1717

1818
function loadActivity() {
19-
var page = location.hash.replace(/^#page=/, '');
19+
var params = new URLSearchParams(location.hash.replace(/^#/, ''));
20+
var page = params.get('page') || '';
21+
var nohelp = params.get('nohelp') || '';
2022
if (currentPage !== undefined && page == currentPage) {
2123
return;
2224
}
2325
var previousPage = currentPage;
2426
currentPage = page;
2527

26-
$.get('activity.json?next=' + page, function(data) {
28+
$.get('activity.json?next=' + page + '&nohelp=' + nohelp, function(data) {
2729
var $tbody = $('#activity-table tbody');
2830
$tbody.empty();
2931

@@ -135,7 +137,23 @@ function loadActivity() {
135137
$tbody.append($tr);
136138
}
137139

138-
$('#activity-nav').empty().append($('<a>').text('Next Page').attr('href', '#page=' + data.next).click(function() {
140+
var activityNav = $('#activity-nav').empty();
141+
142+
var nohelpText;
143+
var nohelpHref;
144+
if (nohelp != 'true') {
145+
nohelpText = 'Hide Help Forum';
146+
nohelpHref = '#page=' + page + '&nohelp=true';
147+
} else {
148+
nohelpText = 'Show Help Forum';
149+
nohelpHref = '#page=' + page + '&nohelp=false';
150+
}
151+
activityNav.append($('<a>').text(nohelpText).attr('href', nohelpHref).click(function() {
152+
currentPage = undefined;
153+
window.scrollTo(0, 0);
154+
}));
155+
156+
activityNav.append($('<a>').text('Next Page').attr('href', '#page=' + data.next + '&nohelp=' + nohelp).click(function() {
139157
window.scrollTo(0, 0);
140158
}));
141159
}).fail(function() {

server/static/style.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ td {
4848
border-bottom: 1px solid #363636;
4949
}
5050

51-
.right {
52-
text-align: right;
51+
#activity-nav {
52+
display: flex;
53+
justify-content: space-between;
5354
}
5455

5556
div.notice {

0 commit comments

Comments
 (0)