Skip to content

Commit 9c14883

Browse files
committed
Fix categories digest to only include relevant posts for each category
1 parent b295ea1 commit 9c14883

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

notifier/digest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def make_categories_digest(
157157
# Sort categories by notification count
158158
for category_id in frequent_ids(grouped_posts):
159159
category_posts = grouped_posts[category_id]
160-
threads = make_threads_digest(posts, lexicon)
160+
threads = make_threads_digest(category_posts, lexicon)
161161
digests.append(
162162
lexicon["category"].format(
163163
category_name=category_posts[0].get("category_name")

tests/test_digest.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
)
1414
from notifier.formatter import convert_syntax
1515
from notifier.types import CachedUserConfig, PostInfo
16+
from notifier.digest import make_categories_digest
17+
1618

1719
fake_user_config: CachedUserConfig = { # TODO Subscriptions
1820
"user_id": "1000",
@@ -179,6 +181,97 @@ def test_full_interpolation_en() -> None:
179181
assert "{" not in digest
180182

181183

184+
def test_categories_digest_duplication_bug() -> None:
185+
"""Test that categories only show their own posts, not all posts."""
186+
187+
digester = Digester(str(Path.cwd() / "config" / "lang.toml"))
188+
lexicon = digester.make_lexicon("en")
189+
190+
# Create posts in two different categories
191+
posts_category_1: List[PostInfo] = [
192+
{
193+
"id": "post-1",
194+
"posted_timestamp": 100,
195+
"title": "Post in Category 1",
196+
"snippet": "Content for category 1",
197+
"username": "User1",
198+
"wiki_id": "test-wiki",
199+
"wiki_name": "Test Wiki",
200+
"wiki_secure": 1,
201+
"category_id": "cat-1",
202+
"category_name": "Category 1",
203+
"thread_id": "thread-1",
204+
"thread_timestamp": 100,
205+
"thread_title": "Thread 1",
206+
"thread_creator": "User1",
207+
"parent_post_id": None,
208+
"parent_posted_timestamp": None,
209+
"parent_title": None,
210+
"parent_username": None,
211+
"flag_user_subscribed_to_thread": True,
212+
"flag_user_subscribed_to_post": False,
213+
"flag_user_started_thread": False,
214+
"flag_user_posted_parent": False,
215+
}
216+
]
217+
218+
posts_category_2: List[PostInfo] = [
219+
{
220+
"id": "post-2",
221+
"posted_timestamp": 200,
222+
"title": "Post in Category 2",
223+
"snippet": "Content for category 2",
224+
"username": "User2",
225+
"wiki_id": "test-wiki",
226+
"wiki_name": "Test Wiki",
227+
"wiki_secure": 1,
228+
"category_id": "cat-2",
229+
"category_name": "Category 2",
230+
"thread_id": "thread-2",
231+
"thread_timestamp": 200,
232+
"thread_title": "Thread 2",
233+
"thread_creator": "User2",
234+
"parent_post_id": None,
235+
"parent_posted_timestamp": None,
236+
"parent_title": None,
237+
"parent_username": None,
238+
"flag_user_subscribed_to_thread": True,
239+
"flag_user_subscribed_to_post": False,
240+
"flag_user_started_thread": False,
241+
"flag_user_posted_parent": False,
242+
}
243+
]
244+
245+
all_posts = posts_category_1 + posts_category_2
246+
categories_digest = make_categories_digest(all_posts, lexicon)
247+
assert len(categories_digest) == 2
248+
category_1_digest = (
249+
categories_digest[0]
250+
if "Category 1" in categories_digest[0]
251+
else categories_digest[1]
252+
)
253+
category_2_digest = (
254+
categories_digest[1]
255+
if "Category 2" in categories_digest[1]
256+
else categories_digest[0]
257+
)
258+
259+
assert "Content for category 1" in category_1_digest
260+
assert "Content for category 2" not in category_1_digest
261+
262+
assert "Content for category 2" in category_2_digest
263+
assert "Content for category 1" not in category_2_digest
264+
265+
assert (
266+
"1 plural(1|notification|notifications) in 1 plural(1|thread|threads)"
267+
in category_1_digest
268+
)
269+
assert (
270+
"1 plural(1|notification|notifications) in 1 plural(1|thread|threads)"
271+
in category_2_digest
272+
)
273+
274+
182275
def test_full_interpolation_all_languages() -> None:
183276
"""Verify that there's no leftover interpolation in any language's digest."""
184277

0 commit comments

Comments
 (0)