Skip to content

Conversation

@hmhealey
Copy link
Member

@hmhealey hmhealey commented Nov 26, 2025

Summary

Typing the WebSocket code means we're less likely to break stuff in the future, and it provides an interface for people working with WebSocket code so that they know what to expect when handling WebSocket events. We could also generate some docs from these type defintions now as well.

For developers adding a new WS event, they will now:

  1. Instead of adding a message type constant to utils/constants or mattermost-redux/constants/websocket, add that to platform/client/src/websocket_events.ts. Now, there's only one place for that to go instead of having multiple confliciting places for that.
  2. To add the type for the event message, add a new type to platform/client/src/websocket_message.ts for the message body, and then add that type to the union type in platform/client/src/websocket_messages.ts so that the type inference for the WS messages works.
  3. Finally, add a new case in websocket_actions as before. The type inference should all give you a properly typed event and everything

Ticket Link

Release Note

NONE

@mm-cloud-bot mm-cloud-bot added the release-note-none Denotes a PR that doesn't merit a release note. label Nov 26, 2025
@hmhealey
Copy link
Member Author

This is going to conflict with the burn-on-read feature branch which adds some new WS event types (#34601) and new WS event handling

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

⚠️ One or more flaky tests detected ⚠️

  • Failing job: github.com/mattermost/mattermost:Postgres
  • Double check your code to ensure you haven't introduced a flaky test.
  • If this seems to be unrelated to your changes, submit a separate pull request to skip the flaky tests (e.g. 23360) and file JIRA ticket (e.g. MM-52743) for later investigation.
TestRetries
Postgres (Results)
com/mattermost/mattermost/server/v8/channels/app.TestAddUserToChannelCreatesChannelMemberHistoryRecord1

@hmhealey hmhealey changed the title Add TS type defintions for all WebSocket messages Define types for WebSocket messages and migrate WebSocket handling to TS Jan 13, 2026
@hmhealey hmhealey changed the title Define types for WebSocket messages and migrate WebSocket handling to TS Define types for WebSocket messages and migrate WebSocket actions to TS Jan 13, 2026
WebsocketEventReactionRemoved WebsocketEventType = "reaction_removed"
WebsocketEventResponse WebsocketEventType = "response"
WebsocketEventEmojiAdded WebsocketEventType = "emoji_added"
WebsocketEventChannelViewed WebsocketEventType = "channel_viewed"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed a few events that aren't used any more. This one was replaced by multiple_channels_viewed, and I couldn't find any references to that Cloud one


const msgPropsPost: Post = JSON.parse(msgProps.post);
const attachments = isMessageAttachmentArray(msgPropsPost?.props?.attachments) ? msgPropsPost.props.attachments : [];
const attachments = isMessageAttachmentArray(post.props?.attachments) ? post.props.attachments : [];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already parsed the post before, so I don't know why we were parsing it again

dispatch(completePostReceive(post, websocketMessageProps, myChannelMemberDoesntExist));

if (msg && msg.data) {
if (msg && msg.data && 'channel_type' in msg.data) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to differentiate between posted and ephemeral_post events

};

/**
* @deprecated Use WebSocketEvents from @mattermost/client instead.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would've removed this entirely, but there's a few extra WS events left over which come from the Apps plugin which I didn't want to move into the new code

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import type * as WebSocketMessages from './websocket_messages';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just re-exporting these types like we do below, I decided to do this slightly differently to wrap all of these message types in sort of a namespace. That means you have to use these types like WebSocketMessages.Posted instead of something like WebSocketPostedMessage, but it also means that we don't need to import 80+ individual message types into websocket_actions.ts. If we went back to writing more imports like import * as Utils from ..., that would be less of a problem, but I think this is a reasonable middleground

import type {WebSocketEvents} from './websocket_events';
import type * as Messages from './websocket_messages';

export type WebSocketMessage = (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, you wouldn't need to define this union type, the constant, and the actual type separately, but without looking into generating TS types (which I've briefly tried multiple times), we're stuck with a bit of boilerplate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be split up, but I felt like that would make the boilerplate feeling worse

@github-actions
Copy link

github-actions bot commented Jan 13, 2026

⚠️ One or more flaky tests detected ⚠️

  • Failing job: github.com/mattermost/mattermost:Postgres
  • Double check your code to ensure you haven't introduced a flaky test.
  • If this seems to be unrelated to your changes, submit a separate pull request to skip the flaky tests (e.g. 23360) and file JIRA ticket (e.g. MM-52743) for later investigation.
TestRetries
Postgres (Results)
com/mattermost/mattermost/server/v8/channels/api4.TestCreatePost/should_prevent_creating_post_with_files_when_user_lacks_upload_file_permission_in_target_channel1
com/mattermost/mattermost/server/v8/channels/api4.TestCreatePost/should_allow_creating_post_with_files_when_user_has_upload_file_permission1
com/mattermost/mattermost/server/v8/channels/api4.TestCreatePost1

@hmhealey hmhealey added the E2E/Run Initiate an E2E run in a PR label Jan 13, 2026
@unified-ci-app unified-ci-app bot removed the E2E/Run Initiate an E2E run in a PR label Jan 13, 2026
@github-actions
Copy link

E2E test run is starting for commit 7efb1ec7a4dd0381037dc857594c30bf349f7f62.
To check the run progress:

  • Cypress: look for commit status E2E Tests/test or the access the Automation Dashboard Cycle URL.
  • Playwright: look for commit status E2E Tests/test-playwright.

You can also look at the E2E test's Workflow Run URL (run ID 20972454362).

@github-actions
Copy link

E2E test has completed for commit 7efb1ec7a4dd0381037dc857594c30bf349f7f62.
Results summary:

  • Cypress: pass rate is unknown (see Automation Dashboard and commit status check E2E Tests/test).
  • Playwright: pass rate is 100.00% (see Playwright Report URL and commit status check E2E Tests/test-playwright).

The run summary artifacts are available in the corresponding Workflow Run.

@hmhealey hmhealey added E2E/Run Initiate an E2E run in a PR 2: Dev Review Requires review by a developer 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review labels Jan 19, 2026
@hmhealey hmhealey marked this pull request as ready for review January 19, 2026 16:50
Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

display_name: msgProps.channel_display_name,
type: msgProps.channel_type,
};
} as Channel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often do we go through this branch? How safe is to do this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's no less safe than what we're currently doing. I think you might actually be the one who added this fallback previously 😛

Looking through the code below though, we only use the 4 fields specified here in every case except for when we pass it to a plugin hook (registerDesktopNotificationHook) where there's an as any. It's totally safe then except for the plugin case which was previously a potential issue anyway.

Thinking about the code as a whole though, we currently assume that the user has all of their channels loaded, so this branch should never actually trigger

@unified-ci-app unified-ci-app bot removed the E2E/Run Initiate an E2E run in a PR label Jan 19, 2026
@github-actions
Copy link

E2E test run is starting for commit f62ffc6bea02fa4bd9389bae1715f80ab5559356.
To check the run progress:

  • Cypress: look for commit status E2E Tests/test or the access the Automation Dashboard Cycle URL.
  • Playwright: look for commit status E2E Tests/test-playwright.

You can also look at the E2E test's Workflow Run URL (run ID 21146071287).

@github-actions
Copy link

E2E test has completed for commit f62ffc6bea02fa4bd9389bae1715f80ab5559356.
Results summary:

  • Cypress: pass rate is unknown (see Automation Dashboard and commit status check E2E Tests/test).
  • Playwright: pass rate is 99.44% (see Playwright Report URL and commit status check E2E Tests/test-playwright).

The run summary artifacts are available in the corresponding Workflow Run.

@hmhealey hmhealey added the E2E/Run Initiate an E2E run in a PR label Jan 20, 2026
@unified-ci-app unified-ci-app bot removed the E2E/Run Initiate an E2E run in a PR label Jan 20, 2026
@github-actions
Copy link

E2E test run is starting for commit 26bc2d69d618367ef8721f183b383ffddc18192b.
To check the run progress:

  • Cypress: look for commit status E2E Tests/test or the access the Automation Dashboard Cycle URL.
  • Playwright: look for commit status E2E Tests/test-playwright.

You can also look at the E2E test's Workflow Run URL (run ID 21180952212).

@github-actions
Copy link

E2E test has completed for commit 26bc2d69d618367ef8721f183b383ffddc18192b.
Results summary:

  • Cypress: pass rate is 100.00% (see Automation Dashboard and commit status check E2E Tests/test).
  • Playwright: pass rate is 100.00% (see Playwright Report URL and commit status check E2E Tests/test-playwright).

The run summary artifacts are available in the corresponding Workflow Run.

Copy link
Member

@harshilsharma63 harshilsharma63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved ✅

@hmhealey
Copy link
Member Author

@yasserfaraazkhan This is another PR that shouldn't have any effect on users, and any functional changes are hopefully just for handling edge cases which may or may not be possible. I'm not sure if you want to smoke test this or if the E2E tests passing is sufficient

@yasserfaraazkhan yasserfaraazkhan added the Setup Cloud Test Server Setup an on-prem test server label Jan 23, 2026
@mm-cloud-bot
Copy link

Mattermost Spinwick PR #34603 🎉

Test server created!

Access here: https://mattermost-pr-34603-aba57.test.mattermost.cloud

Installation ID: ucxo7rbntpd5bbr6s7cq5hqdio
Logs: Click here

Credentials: Posted securely in this Mattermost channel - Look for PR #34603

@hmhealey hmhealey added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a developer 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review labels Jan 23, 2026
@hmhealey hmhealey merged commit 777867d into master Jan 23, 2026
99 checks passed
@hmhealey hmhealey deleted the hh_nov26-websocket-events branch January 23, 2026 19:29
@mattermost-build mattermost-build removed the Setup Cloud Test Server Setup an on-prem test server label Jan 23, 2026
@mm-cloud-bot
Copy link

Test server destroyed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4: Reviews Complete All reviewers have approved the pull request release-note-none Denotes a PR that doesn't merit a release note.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants