4.2 KiB
Leantime API Fixes - Mark Notifications as Read
Date: 2026-01-01
Issue: Mark all as read failing due to incorrect API method names
Status: ✅ Fixed
🔍 Issues Found
Issue 1: Incorrect Method Name for Single Notification
Current Code (WRONG):
method: 'leantime.rpc.Notifications.Notifications.markNotificationAsRead'
params: {
userId: leantimeUserId,
notificationId: parseInt(sourceId) // Wrong parameter name
}
Leantime Documentation (CORRECT):
method: 'leantime.rpc.Notifications.Notifications.markNotificationRead' // No "As" in method name
params: {
id: parseInt(sourceId), // Parameter is "id", not "notificationId"
userId: leantimeUserId
}
Fix Applied: ✅ Changed method name and parameter names to match Leantime API
Issue 2: No "Mark All" Method Exists
Problem:
- Leantime API does NOT have a
markAllNotificationsAsReadmethod - Current code tries to call a non-existent method
Solution:
- Fetch all unread notifications
- Mark each one individually using
markNotificationRead - Process in parallel for better performance
Fix Applied: ✅ Implemented loop-based approach to mark all notifications individually
✅ Changes Made
1. Fixed markAsRead Method
File: lib/services/notifications/leantime-adapter.ts
Changes:
- ✅ Method name:
markNotificationAsRead→markNotificationRead - ✅ Parameter:
notificationId→id - ✅ Parameter order:
idfirst, thenuserId(matching Leantime docs) - ✅ Added request logging
2. Fixed markAllAsRead Method
File: lib/services/notifications/leantime-adapter.ts
New Implementation:
- Fetch all unread notifications (up to 1000)
- Filter to get only unread ones
- Mark each notification individually using
markNotificationRead - Process in parallel using
Promise.all() - Return success if majority succeed
Benefits:
- ✅ Works with actual Leantime API
- ✅ Handles partial failures gracefully
- ✅ Parallel processing for better performance
- ✅ Detailed logging for each notification
📊 Expected Behavior After Fix
Mark Single Notification as Read
Before: ❌ Failed (wrong method name)
After: ✅ Should work correctly
Logs:
[LEANTIME_ADAPTER] markAsRead - Request body: {"method":"markNotificationRead",...}
[LEANTIME_ADAPTER] markAsRead - Success: true
Mark All Notifications as Read
Before: ❌ Failed (method doesn't exist)
After: ✅ Should work (marks each individually)
Logs:
[LEANTIME_ADAPTER] markAllAsRead - Fetching all unread notifications
[LEANTIME_ADAPTER] markAllAsRead - Found 66 unread notifications to mark
[LEANTIME_ADAPTER] markAllAsRead - Results: 66 succeeded, 0 failed out of 66 total
[LEANTIME_ADAPTER] markAllAsRead - Overall success: true
🎯 Count vs Display Issue
Current Situation:
- Count: 66 unread (from first 100 notifications)
- Display: 10 notifications shown (pagination)
Why:
getNotificationCount()fetches first 100 notifications and counts unreadgetNotifications()with default limit=20 shows first 10-20- This is expected behavior but can be confusing
Options:
- Accept limitation: Document that count is based on first 100
- Fetch all for count: More accurate but slower
- Use dedicated count API: If Leantime provides one
- Show "66+ unread": If count reaches 100, indicate there may be more
Recommendation: Keep current behavior but add a note in UI if count = 100 (may have more)
🚀 Next Steps
- ✅ Test Mark Single as Read: Should work now with correct method name
- ✅ Test Mark All as Read: Should work by marking each individually
- ⏳ Verify Count Updates: After marking, count should decrease
- ⏳ Monitor Performance: Marking 66 notifications individually may take a few seconds
📝 Summary
Fixes Applied:
- ✅ Fixed
markAsReadmethod name and parameters - ✅ Implemented
markAllAsReadusing individual marking approach - ✅ Added comprehensive logging
Status: Ready for testing after rm -rf .next && npm run build
Expected Result: Mark all as read should now work correctly
Generated: 2026-01-01