commit 96042ffc51b0f4a37af126f4fb08df395ceecefd
parent 5ed515b061b4157d8c39e6eb157985cd08bea75c
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 11 Nov 2022 22:41:29 -0800
optional afk indicator
Diffstat:
7 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go
@@ -87,6 +87,7 @@ type User struct {
HideRightColumn bool
ChatBarAtBottom bool
AutocompleteCommandsEnabled bool
+ AfkIndicatorEnabled bool
SignupMetadata string
CollectMetadata bool
CaptchaRequired bool
diff --git a/pkg/managers/managers.go b/pkg/managers/managers.go
@@ -19,28 +19,30 @@ func init() {
}
type UserInfo struct {
- UserID int64
- Username string
- Color string
- RefreshRate int64
- LastUpdate time.Time
- LastActivity *time.Time
- IsModerator bool
- IsIncognito bool
- IsHellbanned bool
+ UserID int64
+ Username string
+ Color string
+ RefreshRate int64
+ LastUpdate time.Time
+ LastActivity *time.Time
+ IsModerator bool
+ IsIncognito bool
+ IsHellbanned bool
+ AfkIndicatorEnabled bool
}
func NewUserInfo(user database.User, lastActivity *time.Time) UserInfo {
return UserInfo{
- UserID: user.ID,
- Username: user.Username,
- RefreshRate: user.RefreshRate,
- Color: user.ChatColor,
- IsModerator: user.IsModerator(),
- IsIncognito: user.IsIncognito,
- IsHellbanned: user.IsHellbanned,
- LastUpdate: time.Now(),
- LastActivity: lastActivity,
+ UserID: user.ID,
+ Username: user.Username,
+ RefreshRate: user.RefreshRate,
+ Color: user.ChatColor,
+ IsModerator: user.IsModerator(),
+ IsIncognito: user.IsIncognito,
+ IsHellbanned: user.IsHellbanned,
+ AfkIndicatorEnabled: user.AFK && user.AfkIndicatorEnabled,
+ LastUpdate: time.Now(),
+ LastActivity: lastActivity,
}
}
diff --git a/pkg/migrations/112.sql b/pkg/migrations/112.sql
@@ -0,0 +1,4 @@
+-- +migrate Up
+ALTER TABLE users ADD COLUMN afk_indicator_enabled TINYINT(1) NOT NULL DEFAULT 0;
+
+-- +migrate Down
diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go
@@ -581,6 +581,7 @@ type settingsChatData struct {
HideRightColumn bool
ChatBarAtBottom bool
AutocompleteCommandsEnabled bool
+ AfkIndicatorEnabled bool
DisplayDeleteButton bool
DisplayKickButton bool
DisplayHellbanButton bool
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -2383,6 +2383,7 @@ func SettingsChatHandler(c echo.Context) error {
data.HideRightColumn = authUser.HideRightColumn
data.ChatBarAtBottom = authUser.ChatBarAtBottom
data.AutocompleteCommandsEnabled = authUser.AutocompleteCommandsEnabled
+ data.AfkIndicatorEnabled = authUser.AfkIndicatorEnabled
data.HideIgnoredUsersFromList = authUser.HideIgnoredUsersFromList
data.RefreshRate = authUser.RefreshRate
data.NotifyNewMessage = authUser.NotifyNewMessage
@@ -2989,6 +2990,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error {
data.HideRightColumn = utils.DoParseBool(c.Request().PostFormValue("hide_right_column"))
data.ChatBarAtBottom = utils.DoParseBool(c.Request().PostFormValue("chat_bar_at_bottom"))
data.AutocompleteCommandsEnabled = utils.DoParseBool(c.Request().PostFormValue("autocomplete_commands_enabled"))
+ data.AfkIndicatorEnabled = utils.DoParseBool(c.Request().PostFormValue("afk_indicator_enabled"))
data.ChatItalic = utils.DoParseBool(c.Request().PostFormValue("chat_italic"))
data.NotifyNewMessage = utils.DoParseBool(c.Request().PostFormValue("notify_new_message"))
data.NotifyTagged = utils.DoParseBool(c.Request().PostFormValue("notify_tagged"))
@@ -3028,6 +3030,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error {
authUser.HideRightColumn = data.HideRightColumn
authUser.ChatBarAtBottom = data.ChatBarAtBottom
authUser.AutocompleteCommandsEnabled = data.AutocompleteCommandsEnabled
+ authUser.AfkIndicatorEnabled = data.AfkIndicatorEnabled
authUser.NotifyNewMessage = data.NotifyNewMessage
authUser.NotifyTagged = data.NotifyTagged
authUser.NotifyPmmed = data.NotifyPmmed
diff --git a/pkg/web/public/views/pages/chat-messages.gohtml b/pkg/web/public/views/pages/chat-messages.gohtml
@@ -355,11 +355,19 @@
<div style="font-weight: bolder; color: #ced4da;">In this room:</div>
{{ range .Data.Members }}
{{ if eq .Username $.AuthUser.Username }}
- <div style="color: {{ .Color }};">{{ .Username }}</div>
+ <div>
+ <span style="color: {{ .Color }};">{{ .Username }}</span>
+ {{ if .AfkIndicatorEnabled }}
+ <small style="color: #ff9a27">afk</small>
+ {{ end }}
+ </div>
{{ else }}
{{ if or (not .IsHellbanned) (eq $.AuthUser.ID .UserID) (and .IsHellbanned $.AuthUser.IsHellbanned) $.AuthUser.DisplayHellbanned }}
<div>
<a href="/api/v1/chat/top-bar/{{ $.Data.RoomName }}?tag={{ .Username }}{{ $.Data.TopBarQueryParams | safeURL }}" target="iframe1" style="color: {{ .Color }};{{ if and (.IsHellbanned) $.AuthUser.DisplayHellbanned }} background-color: rgba(0, 0, 0, 0.7);{{ end }}">{{ .Username | first }}</a><a href="/api/v1/chat/top-bar/{{ $.Data.RoomName }}?pm={{ .Username }}{{ $.Data.TopBarQueryParams | safeURL }}" target="iframe1" style="color: {{ .Color }};{{ if and (.IsHellbanned) $.AuthUser.DisplayHellbanned }} background-color: rgba(0, 0, 0, 0.7);{{ end }}">{{ .Username | rest }}</a>
+ {{ if .AfkIndicatorEnabled }}
+ <small style="color: #ff9a27">afk</small>
+ {{ end }}
</div>
{{ end }}
{{ end }}
@@ -371,11 +379,19 @@
<div style="font-weight: bolder; color: #ced4da;">In other rooms:</div>
{{ range .Data.MembersInChat }}
{{ if eq .Username $.AuthUser.Username }}
- <div style="color: {{ .Color }};">{{ .Username }}</div>
+ <div>
+ <span style="color: {{ .Color }};">{{ .Username }}</span>
+ {{ if .AfkIndicatorEnabled }}
+ <small style="color: #ff9a27">afk</small>
+ {{ end }}
+ </div>
{{ else }}
{{ if or (not .IsHellbanned) (eq $.AuthUser.ID .UserID) (and .IsHellbanned $.AuthUser.IsHellbanned) $.AuthUser.DisplayHellbanned }}
<div>
<a href="/api/v1/chat/top-bar/{{ $.Data.RoomName }}?tag={{ .Username }}{{ $.Data.TopBarQueryParams | safeURL }}" target="iframe1" style="color: {{ .Color }};{{ if and (.IsHellbanned) $.AuthUser.DisplayHellbanned }} background-color: rgba(0, 0, 0, 0.7);{{ end }}">{{ .Username | first }}</a><a href="/api/v1/chat/top-bar/{{ $.Data.RoomName }}?pm={{ .Username }}{{ $.Data.TopBarQueryParams | safeURL }}" target="iframe1" style="color: {{ .Color }};{{ if and (.IsHellbanned) $.AuthUser.DisplayHellbanned }} background-color: rgba(0, 0, 0, 0.7);{{ end }}">{{ .Username | rest }}</a>
+ {{ if .AfkIndicatorEnabled }}
+ <small style="color: #ff9a27">afk</small>
+ {{ end }}
</div>
{{ end }}
{{ end }}
diff --git a/pkg/web/public/views/pages/settings/chat.gohtml b/pkg/web/public/views/pages/settings/chat.gohtml
@@ -113,6 +113,10 @@
<label class="form-check-label" for="autocomplete_commands_enabled">{{ t "Autocomplete slash commands" . }}</label>
</div>
<div class="form-check">
+ <input type="checkbox" class="form-check-input" name="afk_indicator_enabled" id="afk_indicator_enabled" value="1"{{ if .Data.AfkIndicatorEnabled }} checked{{ end }} />
+ <label class="form-check-label" for="afk_indicator_enabled">{{ t "Display afk indicator" . }}</label>
+ </div>
+ <div class="form-check">
<input type="checkbox" class="form-check-input" name="display_delete_button" id="display_delete_button" value="1"{{ if .Data.DisplayDeleteButton }} checked{{ end }} />
<label class="form-check-label" for="display_delete_button">{{ t "Display delete button" . }}</label>
</div>