1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Used to show the landing page of the application
package home
import (
"archives/pkg/app/popular"
"archives/pkg/config"
"archives/pkg/database"
"archives/pkg/models"
"github.com/go-pg/pg/v10/orm"
"net/http"
"time"
)
// Show renders a template to show the landing page of the application
func Show(w http.ResponseWriter, r *http.Request) {
var mailingLists []models.MailingList
for _, mailingList := range config.IndexMailingLists() {
var messages []*models.Message
database.DBCon.Model(&messages).
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
q = q.WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE '[` + mailingList[0] + `]%'`).
WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE 'Re: [` + mailingList[0] + `]%'`)
return q, nil
}).
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
q = q.WhereOr(`headers::jsonb->>'To' LIKE '%` + mailingList[0] + `@lists.gentoo.org%'`).
WhereOr(`headers::jsonb->>'Cc' LIKE '%` + mailingList[0] + `@lists.gentoo.org%'`).
WhereOr(`headers::jsonb->>'To' LIKE '%` + mailingList[0] + `@gentoo.org%'`).
WhereOr(`headers::jsonb->>'Cc' LIKE '%` + mailingList[0] + `@gentoo.org%'`)
return q, nil
}).
Order("date DESC").
Limit(5).
Select()
mailingLists = append(mailingLists, models.MailingList{
Name: mailingList[0],
Description: mailingList[1],
Messages: messages,
})
}
//
// Get popular threads
//
popularThreads, err := popular.GetPopularThreads(10, "2020-06-01")
if err != nil {
http.NotFound(w, r)
return
}
if len(popularThreads) > 5 {
popularThreads = popularThreads[:5]
}
templateData := struct {
MailingLists []models.MailingList
PopularThreads models.Threads
MessageCount string
CurrentMonth string
}{
MailingLists: mailingLists,
PopularThreads: popularThreads,
MessageCount: formatMessageCount(getAllMessagesCount()),
CurrentMonth: time.Now().Format("2006-01"),
}
renderIndexTemplate(w, templateData)
}
|