zulip/zerver
Sai eaa2ece4e1 slack: Fix bugs during import of thread messages.
Consider the following messages JSON (taken from real data, redacted):
```json
[
    {
        "subtype": "bot_message",
        "text": "",
        "attachments": [
            {
                "fallback": "Open Slack to cast your vote in this Simple Poll",
                "title": "Should we do a thing?",
                "id": 1,
                "color": "6ecadc",
                "fields": [
                    {
                        "title": "",
                        "value": "1️⃣ Yes 👍\n\n"",
                        "short": false
                    },
                    {
                        "title": "",
                        "value": "2️⃣ No 👎\n\n",
                        "short": false
                    },
                    {
                        "title": "",
                        "value": "3️⃣ Abstain :spock-hand:\n\n",
                        "short": false
                    }
                ],
                "mrkdwn_in": [
                    "fields"
                ]
            },
            {
                "callback_id": "12345678-1234-1234-1234-123456789abc",
                "fallback": "Open Slack to cast your vote in this Simple Poll",
                "id": 2,
                "color": "6ecadc",
                "actions": [
                    {
                        "id": "1",
                        "name": "vote",
                        "text": "1️⃣",
                        "type": "button",
                        "value": "1",
                        "style": ""
                    },
                    {
                        "id": "2",
                        "name": "vote",
                        "text": "2️⃣",
                        "type": "button",
                        "value": "2",
                        "style": ""
                    },
                    {
                        "id": "3",
                        "name": "vote",
                        "text": "3️⃣",
                        "type": "button",
                        "value": "3",
                        "style": ""
                    },
                    {
                        "id": "4",
                        "name": "delete-v2",
                        "text": "Delete Poll",
                        "type": "button",
                        "value": "",
                        "style": "danger",
                        "confirm": {
                            "text": "Are you sure you want to delete the Poll?",
                            "title": "Delete Poll?",
                            "ok_text": "Yes",
                            "dismiss_text": "No"
                        }
                    }
                ]
            },
            {
                "callback_id": "12345678-1234-1234-1234-123456789abc",
                "fallback": "Open Slack to cast your vote in this Simple Poll",
                "footer": "Simple Poll        <https:\/\/simplepoll.rocks\/dashboard\/redacted\/settings\/|Edit Settings>",
                "id": 3,
                "footer_icon": "https:\/\/simplepoll.rocks\/static\/main\/favicon.png",
                "color": "6ecadc"
            }
        ],
        "type": "message",
        "ts": "1234567890.123456",
        "bot_id": "B1ABCDEF1",
        "thread_ts": "1234567890.123456",
        "reply_count": 1,
        "reply_users_count": 1,
        "latest_reply": "1234567890.765432",
        "reply_users": [
            "U1ABC1234"
        ],
        "replies": [
            {
                "user": "U1ABC1234",
                "ts": "1234567890.765432"
            }
        ],
        "is_locked": false,
        "subscribed": false
    },
    {
        "user": "U1ABC1234",
        "type": "message",
        "ts": "1234567890.765432",
        "text": "Maybe do qux instead",
        "team": "T1AB23456",
        "user_team": "T1AB23456",
        "source_team": "T1AB23456",
        "user_profile": {
            "avatar_hash": "a123456789ab",
            "image_72": "https:\/\/avatars.slack-edge.com\/2017-01-01\/123456789abc_def123456789abcdef12_72.jpg",
            "first_name": "Alice",
            "real_name": "Alice Smith",
            "display_name": "a.smith",
            "team": "T1AB23456",
            "name": "a.smith",
            "is_restricted": false,
            "is_ultra_restricted": false
        },
        "thread_ts": "1234567890.123456",
        "blocks": [
            {
                "type": "rich_text",
                "block_id": "EoBdt",
                "elements": [
                    {
                        "type": "rich_text_section",
                        "elements": [
                            {
                                "type": "text",
                                "text": "Maybe do qux instead"
                            }
                        ]
                    }
                ]
            }
        ]
    }
]
```

533f177175/zerver/data_import/slack.py (L922-L924)
fails for the first message, because it lacks a 'user' key. It should fall back to the bot_id.

533f177175/zerver/data_import/slack.py (L925-L926)
fails for the second message, because it lacks a 'parent_user_id' key.
However, the thread root will have been processed earlier, so
memoization of thread parents fixes this issue. Because the original
message may not be in the same file, the memoization needs to be global
rather than in `channel_message_to_zerver_message`.
2025-09-16 11:35:53 -07:00
..
actions zephyr: Remove Zephyr mirroring support. 2025-09-16 11:18:18 -07:00
data_import slack: Fix bugs during import of thread messages. 2025-09-16 11:35:53 -07:00
lib events: Remove realm_is_zephyr_mirror_realm from API. 2025-09-16 11:23:10 -07:00
management update_subscriber_counts: Fix calling without any flags. 2025-09-12 12:59:46 -07:00
migrations streams: Remove is_in_zephyr_realm field from database. 2025-09-16 11:23:11 -07:00
models streams: Remove is_in_zephyr_realm field from database. 2025-09-16 11:23:11 -07:00
openapi events: Remove realm_is_zephyr_mirror_realm from API. 2025-09-16 11:23:10 -07:00
tests events: Remove realm_is_zephyr_mirror_realm from API. 2025-09-16 11:23:10 -07:00
tornado zephyr: Remove Zephyr mirroring support. 2025-09-16 11:18:18 -07:00
transaction_tests test_user_groups: Add durable=True to the independent transaction. 2024-11-21 14:55:15 -08:00
views zephyr: Remove Zephyr mirroring support. 2025-09-16 11:18:18 -07:00
webhooks grafana: Be more forgiving of missing alert keys. 2025-07-22 12:20:04 -07:00
worker thumbnail: Avoid BytesIO.getbuffer. 2025-08-13 14:11:05 -07:00
__init__.py
apps.py forms: Use monkey-patched SetPasswordForm generic. 2025-07-15 07:32:44 -07:00
context_processors.py realm_creation_form: Capture import_from if realm import enabled. 2025-04-30 00:06:43 -07:00
decorator.py zephyr: Remove Zephyr mirroring support. 2025-09-16 11:18:18 -07:00
filters.py filters: Do not report AVATAR_SALT, or other salts. 2025-03-13 09:36:07 -07:00
forms.py zephyr: Remove Zephyr mirroring support. 2025-09-16 11:18:18 -07:00
logging_handlers.py ruff: Fix UP007 Use X | Y for type annotations. 2024-07-13 22:28:22 -07:00
middleware.py zephyr: Remove Zephyr mirroring support. 2025-09-16 11:18:18 -07:00
signals.py send_email: Set the Date header according to local enqueue time. 2025-03-10 16:48:08 -07:00