From 250b9030ea40f54fddd75abc06d81f2d8e52aa9f Mon Sep 17 00:00:00 2001 From: lowcarbdev Date: Wed, 29 Apr 2026 23:11:50 -0600 Subject: [PATCH] setting to limit number of messages shown --- frontend/src/App.jsx | 7 ++-- frontend/src/components/MessageThread.jsx | 3 +- frontend/src/components/SettingsModal.jsx | 43 +++++++++++++++++++++-- internal/handlers.go | 38 ++++++++++---------- internal/settings.go | 6 ++-- 5 files changed, 71 insertions(+), 26 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 5ea459b..2547e67 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -34,7 +34,8 @@ function App() { const [version, setVersion] = useState('...') const [settings, setSettings] = useState({ conversations: { - show_calls: true + show_calls: true, + message_limit: 100000 } }) @@ -89,7 +90,8 @@ function App() { // Use default settings if fetch fails setSettings({ conversations: { - show_calls: true + show_calls: true, + message_limit: 100000 } }) } @@ -372,6 +374,7 @@ function App() { conversation={selectedConversation} startDate={startDate} endDate={endDate} + messageLimit={settings.conversations.message_limit} /> diff --git a/frontend/src/components/MessageThread.jsx b/frontend/src/components/MessageThread.jsx index 262f907..6b5e9e8 100644 --- a/frontend/src/components/MessageThread.jsx +++ b/frontend/src/components/MessageThread.jsx @@ -7,7 +7,7 @@ import MediaGrid from './MediaGrid' const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8085/api' -function MessageThread({ conversation, startDate, endDate }) { +function MessageThread({ conversation, startDate, endDate, messageLimit }) { const location = useLocation() const [items, setItems] = useState([]) const [loading, setLoading] = useState(false) @@ -235,6 +235,7 @@ function MessageThread({ conversation, startDate, endDate }) { } if (startDate) params.start = startDate.toISOString() if (endDate) params.end = endDate.toISOString() + if (messageLimit) params.limit = messageLimit const response = await axios.get(`${API_BASE}/messages`, { params }) setItems(response.data || []) diff --git a/frontend/src/components/SettingsModal.jsx b/frontend/src/components/SettingsModal.jsx index d03a625..520ac0c 100644 --- a/frontend/src/components/SettingsModal.jsx +++ b/frontend/src/components/SettingsModal.jsx @@ -3,10 +3,20 @@ import axios from 'axios' const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8085/api' +const MESSAGE_LIMIT_OPTIONS = [ + { value: 100, label: '100' }, + { value: 1000, label: '1,000' }, + { value: 10000, label: '10,000' }, + { value: 100000, label: '100,000' }, + { value: 200000, label: '200,000' }, + { value: 500000, label: '500,000' }, +] + function SettingsModal({ show, onClose, onSettingsUpdated }) { const [settings, setSettings] = useState({ conversations: { - show_calls: true + show_calls: true, + message_limit: 100000 } }) const [loading, setLoading] = useState(true) @@ -38,7 +48,6 @@ function SettingsModal({ show, onClose, onSettingsUpdated }) { setError('') await axios.put(`${API_BASE}/settings`, settings) - // Notify parent component that settings were updated if (onSettingsUpdated) { onSettingsUpdated(settings) } @@ -62,6 +71,16 @@ function SettingsModal({ show, onClose, onSettingsUpdated }) { }) } + const handleMessageLimitChange = (e) => { + setSettings({ + ...settings, + conversations: { + ...settings.conversations, + message_limit: parseInt(e.target.value, 10) + } + }) + } + if (!show) return null return ( @@ -89,7 +108,7 @@ function SettingsModal({ show, onClose, onSettingsUpdated }) {
Conversations
-
+
+ +
+ + +
+ Maximum number of messages shown when opening a conversation. +
+
)}
diff --git a/internal/handlers.go b/internal/handlers.go index 8b39cad..bbc3e99 100644 --- a/internal/handlers.go +++ b/internal/handlers.go @@ -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) diff --git a/internal/settings.go b/internal/settings.go index e76cf59..cae0770 100644 --- a/internal/settings.go +++ b/internal/settings.go @@ -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, }, } }