diff --git a/docs/pointer.md b/docs/pointer.md index 8f792c802c..44c9b5305d 100644 --- a/docs/pointer.md +++ b/docs/pointer.md @@ -108,3 +108,14 @@ use the product. The algorithm is as follows: These two simple rules, combined with the pointer logic above, end up matching user expectations well for whether the product should treat them as having read a set of messages (or not). + +## Testing and development + +In a Zulip development environment, you can use `manage.py +mark_all_messages_unread` to set every user's pointer to 0 and all +messages as unread, for convenience in testing unread count related +logic. + +It can be useful to combine this with `manage.py populate_db -n 3000` +(which rebuilds the database with 3000 initial messages) to ensure a +large number of messages are present. diff --git a/zilencer/management/commands/mark_all_messages_unread.py b/zilencer/management/commands/mark_all_messages_unread.py new file mode 100644 index 0000000000..b5317227a8 --- /dev/null +++ b/zilencer/management/commands/mark_all_messages_unread.py @@ -0,0 +1,19 @@ +from __future__ import absolute_import + +from typing import Any + +from django.conf import settings +from django.core.management.base import BaseCommand +from django.db.models import F +from django.core.cache import cache +from zerver.models import UserProfile, UserMessage + +class Command(BaseCommand): + help = """Script to mark all messages as unread.""" + + def handle(self, *args, **options): + # type: (*Any, **Any) -> None + assert settings.DEVELOPMENT + UserMessage.objects.all().update(flags=F('flags').bitand(~UserMessage.flags.read)) + UserProfile.objects.all().update(pointer=0) + cache._cache.flush_all()