diff --git a/assets/openapi.json b/assets/openapi.json index ee3b874..b895e6a 100644 --- a/assets/openapi.json +++ b/assets/openapi.json @@ -500,15 +500,28 @@ "properties": { "component_type": { "enum": [ - 0, 1, + 10, + 11, + 12, + 13, + 14, + 16, + 17, + 18, + 19, 2, + 20, + 21, + 22, + 23, 3, 4, 5, 6, 7, - 8 + 8, + 9 ], "type": "number" }, @@ -2501,6 +2514,15 @@ "id": { "type": "string" }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, "icon": { "type": "string" }, @@ -2534,6 +2556,14 @@ "member_count": { "type": "integer" }, + "get_annotations": { + "type": "object", + "additionalProperties": false + }, + "clean_data": { + "type": "object", + "additionalProperties": false + }, "roles": { "type": "array", "items": { @@ -2688,13 +2718,16 @@ } }, "required": [ + "__@annotationsKey@12270", "bans", "channel_ordering", "channels", + "clean_data", "discovery_excluded", "discovery_weight", "emojis", "features", + "get_annotations", "id", "insert", "invites", @@ -7713,9 +7746,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "channel", "embeds", "flags", @@ -7883,9 +7926,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "created_at", "flags", "id", @@ -7941,9 +7994,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "channel", "channel_id", "closed", @@ -8142,9 +8205,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "bio", "bot", "connected_accounts", @@ -8241,9 +8314,19 @@ }, "session_nickname": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "activities", "client_info", "client_status", @@ -8534,9 +8617,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "from", "from_id", "id", @@ -8620,9 +8713,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "external_id", "id", "name", @@ -8824,9 +8927,19 @@ "view_nsfw_guilds": { "type": "boolean", "default": true + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "afk_timeout", "allow_accessibility_detection", "animate_emoji", @@ -8940,9 +9053,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "counter", "id", "key_id", @@ -9099,9 +9222,19 @@ }, "flags": { "$ref": "#/components/schemas/ThreadMemberFlags" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "channel", "flags", "id", @@ -9201,9 +9334,19 @@ }, "collectibles": { "$ref": "#/components/schemas/Collectibles" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "banner", "bio", "communication_disabled_until", @@ -9446,9 +9589,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "bans", "channel_ordering", "channels", @@ -9502,9 +9655,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "executor", "executor_id", "guild", @@ -9573,9 +9736,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "color", "colors", "flags", @@ -9647,9 +9820,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "code", "created_at", "creator", @@ -9706,9 +9889,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "animated", "available", "groups", @@ -9764,9 +9957,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "format_type", "id", "name", @@ -9800,9 +10003,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "id", "name", "stickers" @@ -9882,9 +10095,19 @@ }, "flags": { "type": "integer" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "channel", "channel_id", "code", @@ -9957,9 +10180,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "channel", "channel_id", "deaf", @@ -10033,9 +10266,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "application", "application_id", "avatar", @@ -10191,9 +10434,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "description", "discoverability_state", "discovery_eligibility_flags", @@ -10235,9 +10488,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "id", "members", "name", @@ -10274,9 +10537,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "id", "membership_state", "permissions", @@ -10531,39 +10804,74 @@ "last_message_id": { "type": "string" }, - "public_ack": { + "last_acked_id": { "type": "string" }, "notifications_cursor": { "type": "string" }, + "mention_count": { + "type": "integer" + }, + "badge_count": { + "type": "integer" + }, "last_pin_timestamp": { "type": "string", "format": "date-time" }, - "mention_count": { - "type": "integer" + "read_state_type": { + "$ref": "#/components/schemas/ReadStateType" }, - "manual": { - "type": "boolean" + "flags": { + "$ref": "#/components/schemas/ReadStateFlags" }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", + "badge_count", "channel", "channel_id", + "flags", "id", - "last_message_id", - "manual", "mention_count", "notifications_cursor", - "public_ack", + "read_state_type", "user", "user_id" ] }, + "ReadStateType": { + "type": "number", + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5 + ] + }, + "ReadStateFlags": { + "type": "number", + "enum": [ + 1, + 2, + 4 + ] + }, "ThreadMetadata": { "type": "object", "properties": { @@ -10618,9 +10926,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "channel", "channel_id", "id", @@ -10660,9 +10978,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "filename", "id", "message", @@ -11387,7 +11715,6 @@ "MessageComponentType": { "type": "number", "enum": [ - 0, 1, 2, 3, @@ -11395,7 +11722,21 @@ 5, 6, 7, - 8 + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23 ] }, "InteractionGuild": { @@ -13101,9 +13442,19 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "code", "consumed", "expired", @@ -13213,9 +13564,19 @@ }, "icon": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "id", "is_primary", "localizations", @@ -13592,9 +13953,19 @@ }, "link": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "required": [ + "__@annotationsKey@12270", "description", "icon", "id" diff --git a/assets/schemas.json b/assets/schemas.json index 289dec6..5007bef 100644 --- a/assets/schemas.json +++ b/assets/schemas.json @@ -499,15 +499,28 @@ "properties": { "component_type": { "enum": [ - 0, 1, + 10, + 11, + 12, + 13, + 14, + 16, + 17, + 18, + 19, 2, + 20, + 21, + 22, + 23, 3, 4, 5, 6, 7, - 8 + 8, + 9 ], "type": "number" }, @@ -2627,6 +2640,15 @@ "id": { "type": "string" }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, "icon": { "type": "string" }, @@ -2660,6 +2682,14 @@ "member_count": { "type": "integer" }, + "get_annotations": { + "type": "object", + "additionalProperties": false + }, + "clean_data": { + "type": "object", + "additionalProperties": false + }, "roles": { "type": "array", "items": { @@ -2823,13 +2853,16 @@ }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "bans", "channel_ordering", "channels", + "clean_data", "discovery_excluded", "discovery_weight", "emojis", "features", + "get_annotations", "id", "insert", "invites", @@ -8192,10 +8225,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "channel", "embeds", "flags", @@ -8368,10 +8411,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "created_at", "flags", "id", @@ -8429,10 +8482,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "channel", "channel_id", "closed", @@ -8632,10 +8695,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "bio", "bot", "connected_accounts", @@ -8733,10 +8806,20 @@ }, "session_nickname": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "activities", "client_info", "client_status", @@ -9036,10 +9119,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "from", "from_id", "id", @@ -9125,10 +9218,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "external_id", "id", "name", @@ -9333,10 +9436,20 @@ "view_nsfw_guilds": { "type": "boolean", "default": true + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "afk_timeout", "allow_accessibility_detection", "animate_emoji", @@ -9463,10 +9576,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "counter", "id", "key_id", @@ -9646,10 +9769,20 @@ }, "flags": { "$ref": "#/definitions/ThreadMemberFlags" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "channel", "flags", "id", @@ -9750,10 +9883,20 @@ }, "collectibles": { "$ref": "#/definitions/Collectibles" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "banner", "bio", "communication_disabled_until", @@ -10005,10 +10148,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "bans", "channel_ordering", "channels", @@ -10063,10 +10216,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "executor", "executor_id", "guild", @@ -10136,10 +10299,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "color", "colors", "flags", @@ -10214,10 +10387,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "code", "created_at", "creator", @@ -10275,10 +10458,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "animated", "available", "groups", @@ -10335,10 +10528,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "format_type", "id", "name", @@ -10373,10 +10576,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "id", "name", "stickers" @@ -10459,10 +10672,20 @@ }, "flags": { "type": "integer" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "channel", "channel_id", "code", @@ -10536,10 +10759,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "channel", "channel_id", "deaf", @@ -10614,10 +10847,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "application", "application_id", "avatar", @@ -10775,10 +11018,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "description", "discoverability_state", "discovery_eligibility_flags", @@ -10821,10 +11074,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "id", "members", "name", @@ -10862,10 +11125,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "id", "membership_state", "permissions", @@ -11141,41 +11414,78 @@ "last_message_id": { "type": "string" }, - "public_ack": { + "last_acked_id": { "type": "string" }, "notifications_cursor": { "type": "string" }, + "mention_count": { + "type": "integer" + }, + "badge_count": { + "type": "integer" + }, "last_pin_timestamp": { "type": "string", "format": "date-time" }, - "mention_count": { - "type": "integer" + "read_state_type": { + "$ref": "#/definitions/ReadStateType" }, - "manual": { - "type": "boolean" + "flags": { + "$ref": "#/definitions/ReadStateFlags" }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", + "badge_count", "channel", "channel_id", + "flags", "id", - "last_message_id", - "manual", "mention_count", "notifications_cursor", - "public_ack", + "read_state_type", "user", "user_id" ], "$schema": "http://json-schema.org/draft-07/schema#" }, + "ReadStateType": { + "type": "number", + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5 + ], + "$schema": "http://json-schema.org/draft-07/schema#" + }, + "ReadStateFlags": { + "type": "number", + "enum": [ + 1, + 2, + 4 + ], + "$schema": "http://json-schema.org/draft-07/schema#" + }, "ThreadMetadata": { "type": "object", "properties": { @@ -11232,10 +11542,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "channel", "channel_id", "id", @@ -11276,10 +11596,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "filename", "id", "message", @@ -12049,7 +12379,6 @@ "MessageComponentType": { "type": "number", "enum": [ - 0, 1, 2, 3, @@ -12057,7 +12386,21 @@ 5, 6, 7, - 8 + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23 ], "$schema": "http://json-schema.org/draft-07/schema#" }, @@ -13895,10 +14238,20 @@ }, "id": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "code", "consumed", "expired", @@ -14023,10 +14376,20 @@ }, "icon": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "id", "is_primary", "localizations", @@ -14432,10 +14795,20 @@ }, "link": { "type": "string" + }, + "__@annotationsKey@12270": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } } }, "additionalProperties": false, "required": [ + "__@annotationsKey@12270", "description", "icon", "id" diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index d19b73a..f78827e 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -51,7 +51,7 @@ } from "@spacebar/util"; import { HTTPError } from "lambert-server"; import { In, Or, Equal, IsNull } from "typeorm"; -import { ChannelType, Embed, EmbedType, MessageCreateAttachment, MessageCreateCloudAttachment, MessageCreateSchema, MessageType, Reaction } from "@spacebar/schemas"; +import { ChannelType, Embed, EmbedType, MessageCreateAttachment, MessageCreateCloudAttachment, MessageCreateSchema, MessageType, Reaction, ReadStateType } from "@spacebar/schemas"; const allow_empty = false; // TODO: check webhook, application, system author, stickers // TODO: embed gifs/videos/images @@ -444,7 +444,7 @@ await fillInMissingIDs((await Member.find({ where: { guild_id: channel.guild_id } })).map(({ id }) => id)); } const repository = ReadState.getRepository(); - const condition = { channel_id: channel.id }; + const condition = { channel_id: channel.id, type: ReadStateType.CHANNEL }; await repository.update({ ...condition, mention_count: IsNull() }, { mention_count: 0 }); await repository.increment(condition, "mention_count", 1); } else { @@ -467,11 +467,9 @@ } if (users.size) { const repository = ReadState.getRepository(); - const condition = { user_id: Or(...[...users].map((id) => Equal(id))), channel_id: channel.id }; + const condition = { user_id: Or(...[...users].map((id) => Equal(id))), channel_id: channel.id, read_state_type: ReadStateType.CHANNEL }; await fillInMissingIDs([...users]); - - await repository.update({ ...condition, mention_count: IsNull() }, { mention_count: 0 }); await repository.increment(condition, "mention_count", 1); } } diff --git a/src/util/entities/ReadState.ts b/src/util/entities/ReadState.ts index e334cd7..b4638fd 100644 --- a/src/util/entities/ReadState.ts +++ b/src/util/entities/ReadState.ts @@ -20,6 +20,7 @@ import { BaseClass } from "./BaseClass"; import { Channel } from "./Channel"; import { User } from "./User"; +import { ReadStateFlags, ReadStateType } from "@spacebar/schemas"; // for read receipts // notification cursor and public read receipt need to be forwards-only (the former to prevent re-pinging when marked as unread, and the latter to be acceptable as a legal acknowledgement in criminal proceedings), and private read marker needs to be advance-rewind capable @@ -50,25 +51,43 @@ }) user: User; - // fully read marker @Column({ nullable: true }) - last_message_id: string; + last_message_id?: string; - // public read receipt @Column({ nullable: true }) - public_ack: string; + last_acked_id?: string; - // notification cursor / private read receipt @Column({ nullable: true }) notifications_cursor: string; + @Column({ default: 0 }) + mention_count: number; + + @Column({ default: 0 }) + badge_count: number; + @Column({ nullable: true }) last_pin_timestamp?: Date; - @Column({ nullable: true }) - mention_count: number; + @Column({ default: ReadStateType.CHANNEL }) + read_state_type: ReadStateType; - // @Column({ nullable: true }) - // TODO: derive this from (last_message_id=notifications_cursor=public_ack)=true - manual: boolean; + @Column({ default: 0 }) + flags: ReadStateFlags; + + toJSON() { + const res = { ...this } as Partial; + if (this.read_state_type === ReadStateType.CHANNEL) { + delete res.badge_count; + delete res.last_acked_id; + } else { + delete res.mention_count; // mutually exclusive with badge_count + delete res.last_message_id; // mutually exclusive with last_acked_id + // these only apply to channels: + delete res.last_pin_timestamp; + delete res.flags; + // delete res.last_viewed; // TODO + } + return res; + } } diff --git a/src/util/migration/postgres/1771825341528-MoreReadStateFields.ts b/src/util/migration/postgres/1771825341528-MoreReadStateFields.ts new file mode 100644 index 0000000..3b0d05a --- /dev/null +++ b/src/util/migration/postgres/1771825341528-MoreReadStateFields.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class MoreReadStateFields1771825341528 implements MigrationInterface { + name = "MoreReadStateFields1771825341528"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "read_states" DROP COLUMN "public_ack"`); + await queryRunner.query(`ALTER TABLE "read_states" ADD "last_acked_id" character varying`); + await queryRunner.query(`ALTER TABLE "read_states" ADD "badge_count" integer NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE "read_states" ADD "read_state_type" integer NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE "read_states" ADD "flags" integer NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE "read_states" ALTER COLUMN "mention_count" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "read_states" ALTER COLUMN "mention_count" SET DEFAULT '0'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "read_states" ALTER COLUMN "mention_count" DROP DEFAULT`); + await queryRunner.query(`ALTER TABLE "read_states" ALTER COLUMN "mention_count" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "read_states" DROP COLUMN "flags"`); + await queryRunner.query(`ALTER TABLE "read_states" DROP COLUMN "read_state_type"`); + await queryRunner.query(`ALTER TABLE "read_states" DROP COLUMN "badge_count"`); + await queryRunner.query(`ALTER TABLE "read_states" DROP COLUMN "last_acked_id"`); + await queryRunner.query(`ALTER TABLE "read_states" ADD "public_ack" character varying`); + } +}