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
7 changes: 3 additions & 4 deletions server/activity_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ type jsonResponse struct {
func ActivityHandler(db Database) echo.HandlerFunc {
return func(c echo.Context) error {
locale := LocaleForRequest(c.Request())
filter := func(a Activity) bool {
return true
}
if c.QueryParam("nohelp") == "true" {
var filter func(Activity) bool
if c.QueryParams().Has("nohelp") && c.QueryParam("nohelp") != "false" {
filter = func(a Activity) bool {
if fp, ok := a.(*ForumPost); ok {
if fp.ForumId == locale.HelpForumId {
Expand Down Expand Up @@ -52,6 +50,7 @@ func ActivityHandler(db Database) echo.HandlerFunc {
Data: a,
})
}
c.Response().Header().Add("Cache-Control", "max-age=120")
return c.JSON(200, response)
}
}
2 changes: 1 addition & 1 deletion server/bolt_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (db *BoltDatabase) Activity(locale *Locale, start string, count int, filter
activity, err := unmarshalActivity(k, v)
if err != nil {
return err
} else if activity != nil && locale.ActivityFilter(activity) && filter(activity) {
} else if activity != nil && locale.ActivityFilter(activity) && (filter == nil || filter(activity)) {
ret = append(ret, activity)
next = base64.RawURLEncoding.EncodeToString(k)
}
Expand Down
22 changes: 18 additions & 4 deletions server/dynamodb_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,42 @@ func (db *DynamoDBDatabase) Activity(locale *Locale, start string, count int, fi
}

for len(activity) < count {
batchSize := count - len(activity)
if filter != nil {
// if we're filtering results, fetch extra
batchSize = count * 4
if batchSize < 50 {
batchSize = 50
} else if batchSize > 1000 {
batchSize = 1000
}
}
result, err := db.client.QueryRequest(&dynamodb.QueryInput{
TableName: aws.String(db.tableName),
KeyConditionExpression: aws.String(condition),
ExpressionAttributeValues: attributeValues,
ExclusiveStartKey: startKey,
Limit: aws.Int64(int64(count - len(activity))),
Limit: aws.Int64(int64(batchSize)),
ScanIndexForward: aws.Bool(false),
}).Send(context.Background())
if err != nil {
return nil, "", err
}
startKey = result.LastEvaluatedKey
for _, item := range result.Items {
if a, err := unmarshalActivity(item["rk"].B, item["v"].B); err != nil {
return nil, "", err
} else if a != nil && filter(a) {
} else if a != nil && (filter == nil || filter(a)) {
activity = append(activity, a)
if len(activity) == count {
startKey = item
break
}
}
}
if result.LastEvaluatedKey == nil {
if result.LastEvaluatedKey == nil || len(activity) == count {
break
}
startKey = result.LastEvaluatedKey
}

var next string
Expand Down
15 changes: 8 additions & 7 deletions server/index_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var index = `<!DOCTYPE html><html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>GGG Tracker</title>
<link rel="shortcut icon" href="static/favicon.ico" />
<link rel="stylesheet" type="text/css" href="static/style.css?v6" />
<link rel="stylesheet" type="text/css" href="static/style.css?v7" />
<link rel="alternate" type="application/rss+xml" title="GGG Tracker Forum Feed" href="rss" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
Expand All @@ -37,13 +37,14 @@ var index = `<!DOCTYPE html><html>
{{end}}
</ul>
</header>
<div class="notice">
<p>Tala moana, warrior! This website is approaching its <strong>12th</strong> birthday! If you've found it useful over the years, you can now show your appreciation in the form of a <a href="https://github.com/sponsors/ccbrown" target="_blank">recurring or one-time donation on GitHub</a>! In addition to showing your appreciation, this offsets server costs and helps support further feature developments (Twitter/X support? Search? GenAI?).</p>
<p>Thanks, and stay safe out there, Exile. ❤️</p>
</div>
<div class="content-box">
<h1>{{call $.Translate "Activity"}}</h1>
<div id="help-toggle"></div>
{{if ne $.Locale.HelpForumId 0}}
<div id="help-toggle">
<a href="#" id="hide-help-forum" style="display: none;">{{call $.Translate "Hide Help Forum"}}</a>
<a href="#" id="show-help-forum" style="display: none;">{{call $.Translate "Show Help Forum"}}</a>
</div>
{{end}}
<a href="rss"><img src="static/images/rss-icon-28.png" class="rss-icon" /></a>
<table id="activity-table" class="list">
<thead>
Expand Down Expand Up @@ -73,7 +74,7 @@ var index = `<!DOCTYPE html><html>
</footer>
</div>

<script src="static/index.js?v8"></script>
<script src="static/index.js?v9"></script>
</body>
</html>`

Expand Down
74 changes: 47 additions & 27 deletions server/localization.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,63 +102,83 @@ var Locales = []*Locale{
Subdomain: "br",
Image: "static/images/locales/br.png",
Translations: map[string]string{
"Activity": "Atividade",
"Thread": "Discussão",
"Poster": "Autor",
"Time": "Hora",
"Forum": "Fórum",
"Activity": "Atividade",
"Thread": "Discussão",
"Poster": "Autor",
"Time": "Hora",
"Forum": "Fórum",
"Hide Help Forum": "Ocultar Fórum de Ajuda",
"Show Help Forum": "Mostrar Fórum de Ajuda",
},
HelpForumId: 774,
},
{
Subdomain: "ru",
Image: "static/images/locales/ru.png",
Translations: map[string]string{
"Activity": "Активность",
"Thread": "Тема",
"Poster": "Автор",
"Time": "Время",
"Forum": "Форум",
"Activity": "Активность",
"Thread": "Тема",
"Poster": "Автор",
"Time": "Время",
"Forum": "Форум",
"Hide Help Forum": "Скрыть форум помощи",
"Show Help Forum": "Показать Форум Помощи",
},
HelpForumId: 1281,
},
{
Subdomain: "th",
Image: "static/images/locales/th.png",
Subdomain: "th",
Image: "static/images/locales/th.png",
Translations: map[string]string{
"Activity": "กิจกรรม",
"Thread": "กระทู้",
"Poster": "ผู้โพสต์",
"Time": "เวลา",
"Forum": "ฟอรั่ม",
"Hide Help Forum": "ซ่อนฟอรั่มช่วยเหลือ",
"Show Help Forum": "แสดงฟอรั่มช่วยเหลือ",
},
HelpForumId: 1011,
},
{
Subdomain: "de",
Image: "static/images/locales/de.png",
Translations: map[string]string{
"Activity": "Aktivität",
"Thread": "Beitrag",
"Poster": "Verfasser",
"Time": "Datum",
"Forum": "Forum",
"Activity": "Aktivität",
"Thread": "Beitrag",
"Poster": "Verfasser",
"Time": "Datum",
"Forum": "Forum",
"Hide Help Forum": "Hilfeforum ausblenden",
"Show Help Forum": "Hilfeforum anzeigen",
},
HelpForumId: 1123,
},
{
Subdomain: "fr",
Image: "static/images/locales/fr.png",
Translations: map[string]string{
"Activity": "Activité",
"Thread": "Fil de discussion",
"Poster": "Posteur",
"Time": "Date",
"Forum": "Forum",
"Activity": "Activité",
"Thread": "Fil de discussion",
"Poster": "Posteur",
"Time": "Date",
"Forum": "Forum",
"Hide Help Forum": "Masquer le forum d'aide",
"Show Help Forum": "Afficher le forum d'aide",
},
HelpForumId: 1051,
},
{
Subdomain: "es",
Image: "static/images/locales/es.png",
Translations: map[string]string{
"Activity": "Actividad",
"Thread": "Tema",
"Poster": "Autor",
"Time": "Fecha",
"Forum": "Foro",
"Activity": "Actividad",
"Thread": "Tema",
"Poster": "Autor",
"Time": "Fecha",
"Forum": "Foro",
"Hide Help Forum": "Ocultar el foro de ayuda",
"Show Help Forum": "Mostrar el foro de ayuda",
},
HelpForumId: 1193,
},
Expand Down
37 changes: 18 additions & 19 deletions server/static/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var currentPage = undefined;
var currentHideHelp = undefined;

var POE = {
Forum: {
Expand All @@ -18,18 +19,21 @@ var POE = {
function loadActivity() {
var params = new URLSearchParams(location.hash.replace(/^#/, ''));
var page = params.get('page') || '';
var nohelp = params.get('nohelp') || '';
if (currentPage !== undefined && page == currentPage) {
var hideHelp = params.has('nohelp') && params.get('nohelp') !== 'false';
if (currentPage !== undefined && page == currentPage && currentHideHelp !== undefined && hideHelp == currentHideHelp) {
return;
}
var previousPage = currentPage;
var previousHideHelp = currentHideHelp;

currentPage = page;
currentHideHelp = hideHelp;

if (nohelp == 'true') {
$('#activity-table tbody').empty().append($('<tr>').append($('<td>').attr('colspan', 6).text('Loading...')))
}
var canonicalNohelpParam = hideHelp ? '&nohelp' : '';

$('#activity-table tbody').empty().append($('<tr>').append($('<td>').attr('colspan', 6).text('Loading...')))

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

Expand Down Expand Up @@ -141,28 +145,23 @@ function loadActivity() {
$tbody.append($tr);
}

var nohelpText;
var nohelpHref;
if (nohelp != 'true') {
nohelpText = 'Hide Help Forum';
nohelpHref = '#page=' + page + '&nohelp=true';
if (hideHelp) {
$('#hide-help-forum').hide();
$('#show-help-forum').attr('href', page ? '#page=' + page : '#').show();
} else {
nohelpText = 'Show Help Forum';
nohelpHref = '#page=' + page + '&nohelp=false';
$('#show-help-forum').hide();
$('#hide-help-forum').attr('href', (page ? '#page=' + page + '&' : '#') + 'nohelp').show();
}
$('#help-toggle').empty().append($('<a>').text(nohelpText).attr('href', nohelpHref).click(function() {
currentPage = undefined;
window.scrollTo(0, 0);
}));

$('#activity-nav').empty().append($('<a>').text('Next Page').attr('href', '#page=' + data.next + '&nohelp=' + nohelp).click(function() {
$('#activity-nav').empty().append($('<a>').text('Next Page').attr('href', '#page=' + data.next + canonicalNohelpParam).click(function() {
window.scrollTo(0, 0);
}));
}).fail(function() {
alert('Something went wrong. Better luck next time.');
currentPage = previousPage
if (currentPage !== undefined) {
window.location.hash = 'page=' + currentPage;
var previousNohelpParam = previousHideHelp ? '&nohelp' : '';
window.location.hash = 'page=' + currentPage + previousNohelpParam;
} else {
window.location.hash = '';
}
Expand Down
Loading