From bb76bc316f879847877c7215d38ecabe2b2bcee0 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 23 Jul 2021 14:12:50 -0700 Subject: [PATCH] models: Add message type field. --- zerver/migrations/0536_add_message_type.py | 26 ++++++++++++++++++++++ zerver/models/messages.py | 21 +++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 zerver/migrations/0536_add_message_type.py diff --git a/zerver/migrations/0536_add_message_type.py b/zerver/migrations/0536_add_message_type.py new file mode 100644 index 0000000000..71052b9c0d --- /dev/null +++ b/zerver/migrations/0536_add_message_type.py @@ -0,0 +1,26 @@ +# Generated by Django 5.0.6 on 2024-06-05 17:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0535_remove_realm_create_public_stream_policy"), + ] + + operations = [ + migrations.AddField( + model_name="archivedmessage", + name="type", + field=models.PositiveSmallIntegerField( + choices=[(1, "Normal"), (2, "Resolve Topic Notification")], db_default=1, default=1 + ), + ), + migrations.AddField( + model_name="message", + name="type", + field=models.PositiveSmallIntegerField( + choices=[(1, "Normal"), (2, "Resolve Topic Notification")], db_default=1, default=1 + ), + ), + ] diff --git a/zerver/models/messages.py b/zerver/models/messages.py index a67958f5df..ec5be1acaa 100644 --- a/zerver/models/messages.py +++ b/zerver/models/messages.py @@ -40,6 +40,27 @@ class AbstractMessage(models.Model): # Important for efficient indexes and sharding in multi-realm servers. realm = models.ForeignKey(Realm, on_delete=CASCADE) + class MessageType(models.IntegerChoices): + NORMAL = 1 + RESOLVE_TOPIC_NOTIFICATION = 2 + + # IMPORTANT: message.type is not to be confused with the + # "recipient type" ("channel" or "direct"), which is is sometimes + # called message_type in the APIs, CountStats or some variable + # names. We intend to rename those to recipient_type. + # + # Type of the message, used to distinguish between "normal" + # messages and some special kind of messages, such as notification + # messages that may be sent by system bots. + type = models.PositiveSmallIntegerField( + choices=MessageType.choices, + default=MessageType.NORMAL, + # Note: db_default is a new feature in Django 5.0, so we don't use + # it across the codebase yet. It's useful here to simplify the + # associated database migration, so we're making use of it. + db_default=MessageType.NORMAL, + ) + # The message's topic. # # Early versions of Zulip called this concept a "subject", as in an email