Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

models: Add message type field.

Tim Abbottbb76bc316f87
diff --git a/zerver/migrations/0536_add_message_type.py b/zerver/migrations/0536_add_message_type.py
new file mode 100644
index 00000000000..71052b9c0dc
--- /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 a67958f5dff..ec5be1acaa7 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