dkforest

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

commit 6591a8106d5729653c96d5ba69d74e9526affaf3
parent 2bb946ec3ffe131f24f73d9678908ccc9610693d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 28 Jan 2023 18:48:43 -0800

allow to display an error message on the "messages" page

Diffstat:
Mpkg/web/handlers/api/v1/data.go | 2++
Mpkg/web/handlers/api/v1/handlers.go | 10++++++++++
Mpkg/web/public/views/pages/chat-messages.gohtml | 5+++++
3 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/pkg/web/handlers/api/v1/data.go b/pkg/web/handlers/api/v1/data.go @@ -35,6 +35,8 @@ type chatMessagesData struct { OfficialRooms []database.ChatRoomAug SubscribedRooms []database.ChatRoomAug ForceManualRefresh bool + Error string + ErrorTs int64 } func (c chatMessagesData) MarshalJSON() ([]byte, error) { diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go @@ -127,6 +127,16 @@ func ChatMessagesHandler(c echo.Context) error { var data chatMessagesData + data.Error = c.QueryParam("error") + if data.Error != "" { + errorDisplayTime := int64(4) // Time in seconds + nowUnix := time.Now().Unix() + data.ErrorTs = utils.DoParseInt64(c.QueryParam("errorTs")) + if nowUnix > data.ErrorTs+errorDisplayTime { + data.Error = "" + } + } + // If your tutorial was reset (you are not a new user), force display manual refresh popup if ((room.IsOfficialRoom() || (room.IsListed && !room.IsProtected())) && !authUser.TutorialCompleted()) && authUser.GeneralMessagesCount > 0 { diff --git a/pkg/web/public/views/pages/chat-messages.gohtml b/pkg/web/public/views/pages/chat-messages.gohtml @@ -165,6 +165,7 @@ .mt-5px { margin-top: 5px; } .mt-10px { margin-top: 10px; } .notif, .notif:hover { color: #e74c3c; } + #msg-err { background-color: #8f2d2d; color: #ffffff; padding: 1px 5px 2px 5px; display: block; text-decoration: none; } </style> </head> <body> @@ -185,6 +186,10 @@ </div> {{ end }} + {{- if .Data.Error -}} + <a href="/api/v1/chat/messages/{{ .Data.RoomName }}" id="msg-err">× {{ .Data.Error }}</a> + {{- end -}} + <div id="msgs"> {{ $baseTopBarURL := (print "/api/v1/chat/top-bar/" $.Data.RoomName) }} {{ $readMarkerRendered := false }}