dkforest

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

commit 7fe4f47ec395735d9534c49871469c1bea77fe26
parent 1dbe1c2629986c93633a444549c7ed07b049139f
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 24 Jun 2023 14:35:24 -0700

cleanup

Diffstat:
Mpkg/utils/utils.go | 9+++++++++
Mpkg/web/handlers/interceptors/msgInterceptor.go | 14++++----------
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go @@ -14,6 +14,7 @@ import ( "crypto/x509" "dkforest/pkg/bfchroma" bf "dkforest/pkg/blackfriday/v2" + "dkforest/pkg/hashset" "dkforest/pkg/utils/crypto" "encoding/base32" "encoding/binary" @@ -1133,3 +1134,11 @@ func identityKeyFromAddress(onionAddr string) ed25519.PublicKey { decodedAddr, _ := base32.StdEncoding.DecodeString(upperAddr) return decodedAddr[:32] } + +func Slice2Set[T any, U comparable](s []T, f func(T) U) hashset.HashSet[U] { + h := hashset.HashSet[U]{} + for _, e := range s { + h.Set(f(e)) + } + return h +} diff --git a/pkg/web/handlers/interceptors/msgInterceptor.go b/pkg/web/handlers/interceptors/msgInterceptor.go @@ -225,25 +225,19 @@ func sendInboxes(db *database.DkfDB, room database.ChatRoom, authUser, toUser *d } blacklistedBy, _ := db.GetPmBlacklistedByUsers(authUser.ID) - blacklistedByMap := make(map[database.UserID]struct{}) - for _, b := range blacklistedBy { - blacklistedByMap[b.UserID] = struct{}{} - } + blacklistedBySet := utils.Slice2Set(blacklistedBy, func(el database.PmBlacklistedUsers) database.UserID { return el.UserID }) ignoredBy, _ := db.GetIgnoredByUsers(authUser.ID) - ignoredByMap := make(map[database.UserID]struct{}) - for _, b := range ignoredBy { - ignoredByMap[b.UserID] = struct{}{} - } + ignoredBySet := utils.Slice2Set(ignoredBy, func(el database.IgnoredUser) database.UserID { return el.UserID }) sendInbox := func(user database.User, isPM, modCh bool) { if !managers.ActiveUsers.IsUserActiveInRoom(user.ID, room) || user.AFK { // Do not send notification if receiver is blacklisting you - if _, ok := blacklistedByMap[user.ID]; ok { + if blacklistedBySet.Contains(user.ID) { return } // Do not send notification if receiver is ignoring you - if _, ok := ignoredByMap[user.ID]; ok { + if ignoredBySet.Contains(user.ID) { return } db.CreateInboxMessage(html, room.ID, authUser.ID, user.ID, isPM, modCh, &msgID)