@rmdes/indiekit-endpoint-microsub 1.0.25 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,6 +83,9 @@ export async function createChannel(application, { name, userId }) {
83
83
  return channel;
84
84
  }
85
85
 
86
+ // Retention period for unread count (only count recent items)
87
+ const UNREAD_RETENTION_DAYS = 30;
88
+
86
89
  /**
87
90
  * Get all channels for a user
88
91
  * @param {object} application - Indiekit application
@@ -101,12 +104,17 @@ export async function getChannels(application, userId) {
101
104
  .sort({ order: 1 })
102
105
  .toArray();
103
106
 
104
- // Get unread counts for each channel
107
+ // Calculate cutoff date for unread counts (only count recent items)
108
+ const cutoffDate = new Date();
109
+ cutoffDate.setDate(cutoffDate.getDate() - UNREAD_RETENTION_DAYS);
110
+
111
+ // Get unread counts for each channel (only recent items)
105
112
  const channelsWithCounts = await Promise.all(
106
113
  channels.map(async (channel) => {
107
114
  const unreadCount = await itemsCollection.countDocuments({
108
115
  channelId: channel._id,
109
116
  readBy: { $ne: userId },
117
+ published: { $gte: cutoffDate },
110
118
  });
111
119
 
112
120
  return {
@@ -562,6 +562,9 @@ export async function deleteItemsForFeed(application, feedId) {
562
562
  return result.deletedCount;
563
563
  }
564
564
 
565
+ // Retention period for unread count (only count recent items)
566
+ const UNREAD_RETENTION_DAYS = 30;
567
+
565
568
  /**
566
569
  * Get unread count for a channel
567
570
  * @param {object} application - Indiekit application
@@ -574,9 +577,14 @@ export async function getUnreadCount(application, channelId, userId) {
574
577
  const objectId =
575
578
  typeof channelId === "string" ? new ObjectId(channelId) : channelId;
576
579
 
580
+ // Only count items from the last UNREAD_RETENTION_DAYS
581
+ const cutoffDate = new Date();
582
+ cutoffDate.setDate(cutoffDate.getDate() - UNREAD_RETENTION_DAYS);
583
+
577
584
  return collection.countDocuments({
578
585
  channelId: objectId,
579
586
  readBy: { $ne: userId },
587
+ published: { $gte: cutoffDate },
580
588
  });
581
589
  }
582
590
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-microsub",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "Microsub endpoint for Indiekit. Enables subscribing to feeds and reading content using the Microsub protocol.",
5
5
  "keywords": [
6
6
  "indiekit",