setting to limit number of messages shown

This commit is contained in:
lowcarbdev
2026-04-29 23:11:50 -06:00
parent 32d6110733
commit 250b9030ea
5 changed files with 71 additions and 26 deletions
+20 -18
View File
@@ -176,8 +176,26 @@ func HandleMessages(c echo.Context) error {
// If type is "conversation", return combined messages and calls
if convType == "conversation" {
// Parse limit and offset parameters
limit := 100000 // Default to 100k (effectively unlimited for most users)
// Get user ID from context to fetch settings
userID, ok := c.Get("user_id").(string)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{
"error": "User not authenticated",
})
}
// Fetch user settings
settings, err := GetUserSettings(userID)
if err != nil {
slog.Error("Error getting user settings", "error", err)
settings = GetDefaultSettings()
}
// Use user's configured limit as default, allow query param override
limit := settings.Conversations.MessageLimit
if limit <= 0 {
limit = 100000
}
offset := 0
if limitStr := c.QueryParam("limit"); limitStr != "" {
@@ -192,22 +210,6 @@ func HandleMessages(c echo.Context) error {
}
}
// Get user ID from context to fetch settings
userID, ok := c.Get("user_id").(string)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{
"error": "User not authenticated",
})
}
// Fetch user settings to check if calls should be shown
settings, err := GetUserSettings(userID)
if err != nil {
slog.Error("Error getting user settings", "error", err)
// If we can't get settings, default to showing calls
settings = GetDefaultSettings()
}
activities, err := GetActivityByAddress(userDB, address, startDate, endDate, limit, offset)
if err != nil {
slog.Error("Error getting activity", "error", err)
+4 -2
View File
@@ -16,14 +16,16 @@ type Settings struct {
// ConversationSettings contains settings for the conversation view
type ConversationSettings struct {
ShowCalls bool `json:"show_calls"`
ShowCalls bool `json:"show_calls"`
MessageLimit int `json:"message_limit"`
}
// GetDefaultSettings returns the default settings
func GetDefaultSettings() Settings {
return Settings{
Conversations: ConversationSettings{
ShowCalls: true,
ShowCalls: true,
MessageLimit: 100000,
},
}
}