dkforest

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

commit 503e6aec68993baccf5fa84bbfdbb64e0304ab15
parent 27df20ddda68ddecd2ea8cc5cfcfd7f2f5365b9c
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri, 26 May 2023 06:05:54 -0700

perf

Diffstat:
Mpkg/database/database.go | 4++--
Mpkg/database/tableChatRooms.go | 13+++++++++----
Mpkg/web/handlers/api/v1/data.go | 4++--
3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/pkg/database/database.go b/pkg/database/database.go @@ -137,7 +137,7 @@ type IDkfDB interface { GetMemes() (out []Meme, err error) GetModeratorsUsers() (out []User, err error) GetOfficialChatRooms() (out []ChatRoom, err error) - GetOfficialChatRooms1(userID UserID) (out []ChatRoomAug, err error) + GetOfficialChatRooms1(userID UserID) (out []ChatRoomAug1, err error) GetOnionBlacklist(hash string) (out OnionBlacklist, err error) GetPmBlacklistedByUsers(userID UserID) (out []PmBlacklistedUsers, err error) GetPmBlacklistedUsers(userID UserID) (out []PmBlacklistedUsers, err error) @@ -175,7 +175,7 @@ type IDkfDB interface { GetUserPublicNotes(userID UserID) (out UserPublicNote, err error) GetUserReadMarker(userID UserID, roomID RoomID) (out ChatReadMarker, err error) GetUserRoomGroups(userID UserID, roomID RoomID) (out []ChatRoomUserGroup, err error) - GetUserRoomSubscriptions(userID UserID) (out []ChatRoomAug, err error) + GetUserRoomSubscriptions(userID UserID) (out []ChatRoomAug1, err error) GetUserSessionNotifications(sessionToken string) (msgs []SessionNotification, err error) GetUserSessionNotificationsCount(sessionToken string) (count int64) GetUserSnippets(userID UserID) (out []Snippet, err error) diff --git a/pkg/database/tableChatRooms.go b/pkg/database/tableChatRooms.go @@ -145,9 +145,14 @@ type ChatRoomAug struct { IsUnread bool } +type ChatRoomAug1 struct { + Name string + IsUnread bool +} + // GetOfficialChatRooms1 returns official chat rooms with additional information such as "IsUnread" -func (d *DkfDB) GetOfficialChatRooms1(userID UserID) (out []ChatRoomAug, err error) { - err = d.db.Raw(`SELECT r.*, +func (d *DkfDB) GetOfficialChatRooms1(userID UserID) (out []ChatRoomAug1, err error) { + err = d.db.Raw(`SELECT r.name, COALESCE((rr.read_at < m.created_at), 1) as is_unread FROM chat_rooms r -- Find last message for room @@ -159,8 +164,8 @@ ORDER BY r.id ASC`, userID, userID).Scan(&out).Error return } -func (d *DkfDB) GetUserRoomSubscriptions(userID UserID) (out []ChatRoomAug, err error) { - err = d.db.Raw(`SELECT r.*, +func (d *DkfDB) GetUserRoomSubscriptions(userID UserID) (out []ChatRoomAug1, err error) { + err = d.db.Raw(`SELECT r.name, COALESCE((rr.read_at < m.created_at), 1) as is_unread FROM user_room_subscriptions s INNER JOIN chat_rooms r ON r.id = s.room_id diff --git a/pkg/web/handlers/api/v1/data.go b/pkg/web/handlers/api/v1/data.go @@ -20,8 +20,8 @@ type chatTopBarData struct { type ChatMenuData struct { InboxCount int64 - OfficialRooms []database.ChatRoomAug - SubscribedRooms []database.ChatRoomAug + OfficialRooms []database.ChatRoomAug1 + SubscribedRooms []database.ChatRoomAug1 Members []managers.UserInfo MembersInChat []managers.UserInfo VisibleMemberInChat bool // either or not at least 1 user is "visible" (not hellbanned)