dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 0a1aeec11a296a900d9de797855120eac63fdb83
parent 4b365e30b882f4a60e9a0f3dce6c8c2be5d01496
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 24 Jan 2023 18:33:22 -0800

filter forum by author

Diffstat:
Mpkg/web/handlers/data.go | 1+
Mpkg/web/handlers/handlers.go | 27+++++++++++++++++++++++++++
Mpkg/web/public/views/pages/public-profile.gohtml | 1+
3 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go @@ -166,6 +166,7 @@ type ForumMessageSearch struct { type forumSearchData struct { Search string + AuthorFilter string ForumThreads []ForumThreadSearch ForumMessages []ForumMessageSearch } diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -1126,6 +1126,33 @@ func NewsHandler(c echo.Context) error { func ForumSearchHandler(c echo.Context) error { var data forumSearchData data.Search = c.QueryParam("search") + data.AuthorFilter = c.QueryParam("author") + + if data.AuthorFilter != "" { + if err := database.DB.Raw(`select +t.*, +u.username as author, +u.chat_color as author_chat_color, +lu.username as last_msg_author, +lu.chat_color as last_msg_chat_color, +lu.chat_font as last_msg_chat_font, +m.created_at as last_msg_created_at, +mmm.replies_count +from fts5_forum_threads ft +inner join forum_threads t on t.id = ft.id +-- Count replies +LEFT JOIN (SELECT mm.thread_id, COUNT(mm.id) as replies_count FROM forum_messages mm GROUP BY mm.thread_id) as mmm ON mmm.thread_id = t.id +-- Join author user +INNER JOIN users u ON u.id = t.user_id +-- Find last message for thread +LEFT JOIN forum_messages m ON m.thread_id = t.id AND m.id = (SELECT max(id) FROM forum_messages WHERE thread_id = t.id) +-- Join last message user +INNER JOIN users lu ON lu.id = m.user_id +where u.username = ? and t.is_club = 0 order by rank limit 100`, data.AuthorFilter).Scan(&data.ForumThreads).Error; err != nil { + logrus.Error(err) + } + return c.Render(http.StatusOK, "forum-search", data) + } if err := database.DB.Raw(`select m.uuid, snippet(fts5_forum_messages,-1, '[', ']', '...', 10) as snippet, t.uuid as thread_uuid, t.name as thread_name, u.username as author, diff --git a/pkg/web/public/views/pages/public-profile.gohtml b/pkg/web/public/views/pages/public-profile.gohtml @@ -44,6 +44,7 @@ <tr><td>Homepage:</td><td><span>{{ if .Data.User.Website }}<a href="{{ .Data.User.Website }}" rel="noopener noreferrer" target="_blank">{{ .Data.User.Website }}</a>{{ else }}none{{ end }}</span></td></tr> <tr><td>Email:</td><td><span>{{ if .Data.User.Email }}{{ .Data.User.Email }}{{ else }}none{{ end }}</span></td></tr> </table> + <a href="/forum/search?author={{ .Data.User.Username }}">forum threads</a> <div class="mt-3"> <label>Age public key:</label> <span style="color: #c0ebff;">{{ if .Data.User.AgePublicKey }}{{ .Data.User.AgePublicKey }}{{ else }}none{{ end }}</span>