setting to limit number of messages shown
This commit is contained in:
@@ -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}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -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 || [])
|
||||
|
||||
@@ -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 }) {
|
||||
|
||||
<h6 className="mb-3">Conversations</h6>
|
||||
|
||||
<div className="form-check form-switch">
|
||||
<div className="form-check form-switch mb-3">
|
||||
<input
|
||||
className="form-check-input"
|
||||
type="checkbox"
|
||||
@@ -105,6 +124,24 @@ function SettingsModal({ show, onClose, onSettingsUpdated }) {
|
||||
When enabled, phone calls will appear in the conversation list alongside messages.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mb-3">
|
||||
<label htmlFor="messageLimitSelect" className="form-label">Messages to load</label>
|
||||
<select
|
||||
className="form-select"
|
||||
id="messageLimitSelect"
|
||||
value={settings.conversations.message_limit || 100000}
|
||||
onChange={handleMessageLimitChange}
|
||||
disabled={saving}
|
||||
>
|
||||
{MESSAGE_LIMIT_OPTIONS.map(opt => (
|
||||
<option key={opt.value} value={opt.value}>{opt.label}</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="form-text">
|
||||
Maximum number of messages shown when opening a conversation.
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
+20
-18
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user