commit 75838f1859af7e4d897d8c086d8dfed981813f99
parent 073681db2b9edcafa82741c060a63174fbd566d4
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 26 May 2023 05:04:42 -0700
cleanup
Diffstat:
3 files changed, 9 insertions(+), 28 deletions(-)
diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go
@@ -145,12 +145,8 @@ func chatMessages(c echo.Context) (status int, data ChatMessagesData) {
pmOnlyQuery := dutils.DoParsePmDisplayMode(c.QueryParam("pmonly"))
mentionsOnlyQuery := utils.DoParseBool(c.QueryParam("mentionsOnly"))
- room, err := db.GetChatRoomByName(roomName)
+ room, roomKey, err := dutils.GetRoomAndKey(db, c, roomName)
if err != nil {
- return http.StatusNotFound, data
- }
- hasAccess, roomKey := room.HasAccess(c)
- if !hasAccess {
return http.StatusForbidden, data
}
@@ -277,15 +273,11 @@ func ChatMessagesWSHandler(c echo.Context) error {
func RoomNotifierHandler(c echo.Context) error {
authUser := c.Get("authUser").(*database.User)
db := c.Get("database").(*database.DkfDB)
- roomID := dutils.DoParseRoomID(c.Param("roomID"))
+ roomName := c.Param("roomName")
lastKnownDate := c.Request().PostFormValue("last_known_date")
- room, err := db.GetChatRoomByID(roomID)
+ room, roomKey, err := dutils.GetRoomAndKey(db, c, roomName)
if err != nil {
- return c.NoContent(http.StatusNotFound)
- }
- hasAccess, roomKey := room.HasAccess(c)
- if !hasAccess {
return c.NoContent(http.StatusForbidden)
}
@@ -294,7 +286,7 @@ func RoomNotifierHandler(c echo.Context) error {
displayHellbanned := authUser.DisplayHellbanned || authUser.IsHellbanned
mentionsOnly := false
displayIgnoredMessages := false
- msgs, err := db.GetChatMessages(roomID, roomKey, authUser.Username, authUser.ID, database.PmNoFilter, mentionsOnly,
+ msgs, err := db.GetChatMessages(room.ID, roomKey, authUser.Username, authUser.ID, database.PmNoFilter, mentionsOnly,
displayHellbanned, authUser.DisplayIgnored, authUser.DisplayModerators, displayIgnoredMessages, 0)
if err != nil {
return c.NoContent(http.StatusInternalServerError)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -3274,13 +3274,9 @@ func ChatArchiveHandler(c echo.Context) error {
var data chatArchiveData
data.DateFormat = authUser.GetDateFormat()
roomName := c.Param("roomName")
- room, err := db.GetChatRoomByName(roomName)
- if err != nil {
- return c.Redirect(http.StatusFound, "/")
- }
- hasAccess, roomKey := room.HasAccess(c)
- if !hasAccess {
+ room, roomKey, err := dutils.GetRoomAndKey(db, c, roomName)
+ if err != nil {
return c.Redirect(http.StatusFound, "/chat")
}
@@ -4874,11 +4870,8 @@ func ChatStreamMenuHandler(c echo.Context) error {
authUser := c.Get("authUser").(*database.User)
roomName := c.Param("roomName")
- room, err := db.GetChatRoomByName(roomName)
+ room, _, err := dutils.GetRoomAndKey(db, c, roomName)
if err != nil {
- return c.NoContent(http.StatusNotFound)
- }
- if hasAccess, _ := room.HasAccess(c); !hasAccess {
return c.NoContent(http.StatusForbidden)
}
@@ -5020,12 +5013,8 @@ func ChatStreamMessagesHandler(c echo.Context) error {
authUser := c.Get("authUser").(*database.User)
roomName := c.Param("roomName")
- room, err := db.GetChatRoomByName(roomName)
+ room, roomKey, err := dutils.GetRoomAndKey(db, c, roomName)
if err != nil {
- return c.Redirect(http.StatusFound, "/")
- }
- hasAccess, roomKey := room.HasAccess(c)
- if !hasAccess {
return c.Redirect(http.StatusForbidden, "/")
}
diff --git a/pkg/web/web.go b/pkg/web/web.go
@@ -137,7 +137,7 @@ func getMainServer(db *database.DkfDB, i18nBundle *i18n.Bundle, renderer *tmp.Te
authGroup.GET("/two-factor-authentication/disable", handlers.TwoFactorAuthenticationDisableHandler)
authGroup.POST("/two-factor-authentication/disable", handlers.TwoFactorAuthenticationDisableHandler, middlewares.AuthRateLimitMiddleware(1*time.Second, 2))
authGroup.GET("/api/v1/captcha-svc", v1.GetCaptchaHandler)
- authGroup.POST("/api/v1/chat/:roomID/notifier", v1.RoomNotifierHandler)
+ authGroup.POST("/api/v1/chat/:roomName/notifier", v1.RoomNotifierHandler)
authGroup.POST("/api/v1/battleship", v1.BattleshipHandler)
authGroup.POST("/api/v1/chess", v1.ChessHandler)
authGroup.POST("/api/v1/werewolf", v1.WerewolfHandler)