diff --git a/server/activity_handler.go b/server/activity_handler.go index 7f883f1..fc45567 100644 --- a/server/activity_handler.go +++ b/server/activity_handler.go @@ -16,7 +16,21 @@ type jsonResponse struct { func ActivityHandler(db Database) echo.HandlerFunc { return func(c echo.Context) error { - activity, next, err := db.Activity(LocaleForRequest(c.Request()), c.QueryParam("next"), 50) + locale := LocaleForRequest(c.Request()) + filter := func(a Activity) bool { + return true + } + if c.QueryParam("nohelp") == "true" { + filter = func(a Activity) bool { + if fp, ok := a.(*ForumPost); ok { + if fp.ForumId == locale.HelpForumId { + return false + } + } + return true + } + } + activity, next, err := db.Activity(locale, c.QueryParam("next"), 50, filter) if err != nil { return err } diff --git a/server/bolt_database.go b/server/bolt_database.go index 5a83aec..5b23285 100644 --- a/server/bolt_database.go +++ b/server/bolt_database.go @@ -43,7 +43,7 @@ func (db *BoltDatabase) AddActivity(activity []Activity) error { }) } -func (db *BoltDatabase) Activity(locale *Locale, start string, count int) ([]Activity, string, error) { +func (db *BoltDatabase) Activity(locale *Locale, start string, count int, filter func(a Activity) bool) ([]Activity, string, error) { ret := []Activity(nil) next := "" if err := db.db.View(func(tx *bolt.Tx) error { @@ -66,7 +66,7 @@ func (db *BoltDatabase) Activity(locale *Locale, start string, count int) ([]Act activity, err := unmarshalActivity(k, v) if err != nil { return err - } else if activity != nil && locale.ActivityFilter(activity) { + } else if activity != nil && locale.ActivityFilter(activity) && filter(activity) { ret = append(ret, activity) next = base64.RawURLEncoding.EncodeToString(k) } diff --git a/server/database.go b/server/database.go index e144320..8118b45 100644 --- a/server/database.go +++ b/server/database.go @@ -17,7 +17,7 @@ const ( type Database interface { AddActivity(activity []Activity) error - Activity(locale *Locale, start string, count int) ([]Activity, string, error) + Activity(locale *Locale, start string, count int, filter func(a Activity) bool) ([]Activity, string, error) Close() error } diff --git a/server/database_test.go b/server/database_test.go index 6654c54..4193c8b 100644 --- a/server/database_test.go +++ b/server/database_test.go @@ -31,21 +31,23 @@ func testDatabase_ForumPosts(t *testing.T, db Database) { db.AddActivity([]Activity{post1, post2}) - posts, next, err := db.Activity(locale, "", 1) + all := func(a Activity) bool { return true } + + posts, next, err := db.Activity(locale, "", 1, all) require.NoError(t, err) require.Equal(t, 1, len(posts)) assert.Equal(t, post1.Id, posts[0].(*ForumPost).Id) assert.Equal(t, post1.Poster, posts[0].(*ForumPost).Poster) assert.Equal(t, post1.Time.Unix(), posts[0].(*ForumPost).Time.Unix()) - posts, next, err = db.Activity(locale, next, 1) + posts, next, err = db.Activity(locale, next, 1, all) require.NoError(t, err) require.Equal(t, 1, len(posts)) assert.Equal(t, post2.Id, posts[0].(*ForumPost).Id) assert.Equal(t, post2.Poster, posts[0].(*ForumPost).Poster) assert.Equal(t, post2.Time.Unix(), posts[0].(*ForumPost).Time.Unix()) - posts, _, err = db.Activity(locale, next, 1) + posts, _, err = db.Activity(locale, next, 1, all) require.NoError(t, err) require.Equal(t, 0, len(posts)) } diff --git a/server/dynamodb_database.go b/server/dynamodb_database.go index b339081..d498949 100644 --- a/server/dynamodb_database.go +++ b/server/dynamodb_database.go @@ -82,7 +82,7 @@ func (db *DynamoDBDatabase) AddActivity(activity []Activity) error { return nil } -func (db *DynamoDBDatabase) Activity(locale *Locale, start string, count int) ([]Activity, string, error) { +func (db *DynamoDBDatabase) Activity(locale *Locale, start string, count int, filter func(a Activity) bool) ([]Activity, string, error) { var activity []Activity var startKey map[string]dynamodb.AttributeValue @@ -120,7 +120,7 @@ func (db *DynamoDBDatabase) Activity(locale *Locale, start string, count int) ([ for _, item := range result.Items { if a, err := unmarshalActivity(item["rk"].B, item["v"].B); err != nil { return nil, "", err - } else if a != nil { + } else if a != nil && filter(a) { activity = append(activity, a) } } diff --git a/server/index_handler.go b/server/index_handler.go index f5ac837..927177e 100644 --- a/server/index_handler.go +++ b/server/index_handler.go @@ -43,6 +43,7 @@ var index = `

{{call $.Translate "Activity"}}

+
diff --git a/server/localization.go b/server/localization.go index f09210e..860211d 100644 --- a/server/localization.go +++ b/server/localization.go @@ -17,6 +17,7 @@ type Locale struct { IncludeReddit bool Translations map[string]string ParseTime func(s string, tz *time.Location) (time.Time, error) + HelpForumId int forumIds atomic.Value } @@ -95,6 +96,7 @@ var Locales = []*Locale{ { IncludeReddit: true, Image: "static/images/locales/gb.png", + HelpForumId: 584, }, { Subdomain: "br", @@ -106,6 +108,7 @@ var Locales = []*Locale{ "Time": "Hora", "Forum": "Fórum", }, + HelpForumId: 774, }, { Subdomain: "ru", @@ -119,8 +122,9 @@ var Locales = []*Locale{ }, }, { - Subdomain: "th", - Image: "static/images/locales/th.png", + Subdomain: "th", + Image: "static/images/locales/th.png", + HelpForumId: 1011, }, { Subdomain: "de", @@ -132,6 +136,7 @@ var Locales = []*Locale{ "Time": "Datum", "Forum": "Forum", }, + HelpForumId: 1123, }, { Subdomain: "fr", @@ -143,6 +148,7 @@ var Locales = []*Locale{ "Time": "Date", "Forum": "Forum", }, + HelpForumId: 1051, }, { Subdomain: "es", @@ -154,6 +160,7 @@ var Locales = []*Locale{ "Time": "Fecha", "Forum": "Foro", }, + HelpForumId: 1193, }, { Subdomain: "jp", diff --git a/server/rss_handler.go b/server/rss_handler.go index 8982272..cf520bc 100644 --- a/server/rss_handler.go +++ b/server/rss_handler.go @@ -43,7 +43,7 @@ type rssResponse struct { func RSSHandler(db Database) echo.HandlerFunc { return func(c echo.Context) error { - activity, _, err := db.Activity(LocaleForRequest(c.Request()), c.QueryParam("next"), 50) + activity, _, err := db.Activity(LocaleForRequest(c.Request()), c.QueryParam("next"), 50, func(a Activity) bool { return true }) if err != nil { return err } diff --git a/server/static/index.js b/server/static/index.js index 9c8aed3..f402423 100644 --- a/server/static/index.js +++ b/server/static/index.js @@ -16,14 +16,20 @@ var POE = { }; function loadActivity() { - var page = location.hash.replace(/^#page=/, ''); + var params = new URLSearchParams(location.hash.replace(/^#/, '')); + var page = params.get('page') || ''; + var nohelp = params.get('nohelp') || ''; if (currentPage !== undefined && page == currentPage) { return; } var previousPage = currentPage; currentPage = page; - $.get('activity.json?next=' + page, function(data) { + if (nohelp == 'true') { + $('#activity-table tbody').empty().append($('').append($('
').attr('colspan', 6).text('Loading...'))) + } + + $.get('activity.json?next=' + page + '&nohelp=' + nohelp, function(data) { var $tbody = $('#activity-table tbody'); $tbody.empty(); @@ -135,7 +141,21 @@ function loadActivity() { $tbody.append($tr); } - $('#activity-nav').empty().append($('').text('Next Page').attr('href', '#page=' + data.next).click(function() { + var nohelpText; + var nohelpHref; + if (nohelp != 'true') { + nohelpText = 'Hide Help Forum'; + nohelpHref = '#page=' + page + '&nohelp=true'; + } else { + nohelpText = 'Show Help Forum'; + nohelpHref = '#page=' + page + '&nohelp=false'; + } + $('#help-toggle').empty().append($('').text(nohelpText).attr('href', nohelpHref).click(function() { + currentPage = undefined; + window.scrollTo(0, 0); + })); + + $('#activity-nav').empty().append($('').text('Next Page').attr('href', '#page=' + data.next + '&nohelp=' + nohelp).click(function() { window.scrollTo(0, 0); })); }).fail(function() { diff --git a/server/static/style.css b/server/static/style.css index 1a5cf08..f6714c3 100644 --- a/server/static/style.css +++ b/server/static/style.css @@ -99,6 +99,12 @@ div.container { opacity: 1.0; } +#help-toggle { + position: absolute; + top: 24px; + right: 50px; +} + div.content-box h1 { padding: 6px; padding-top: 0px;