mirror of https://github.com/zulip/zulip.git
unread: Add tool for marking all messages as unread for testing.
This tool can save a lot of manual work in testing our unread counts logic.
This commit is contained in:
parent
cb2181d42d
commit
60225012e6
|
@ -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.
|
||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue