This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Remove references to internal js-sdk type CryptoBackend
#12321
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ import { normalize } from "matrix-js-sdk/src/utils"; | |
import { ReEmitter } from "matrix-js-sdk/src/ReEmitter"; | ||
import { MediaHandler } from "matrix-js-sdk/src/webrtc/mediaHandler"; | ||
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature"; | ||
import { CryptoBackend } from "matrix-js-sdk/src/common-crypto/CryptoBackend"; | ||
import { MapperOpts } from "matrix-js-sdk/src/event-mapper"; | ||
// eslint-disable-next-line no-restricted-imports | ||
import { MatrixRTCSessionManager } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager"; | ||
|
@@ -441,9 +440,10 @@ export async function mkEncryptedEvent(opts: { | |
}; | ||
|
||
const mockCrypto = { | ||
decryptEvent: async (_ev): Promise<IEventDecryptionResult> => decryptionResult, | ||
} as CryptoBackend; | ||
decryptEvent: async (_ev: MatrixEvent): Promise<IEventDecryptionResult> => decryptionResult, | ||
}; | ||
|
||
// @ts-ignore `mockCrypto` is not a `CryptoBackend`, which is an internal type in the js-sdk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
await mxEvent.attemptDecryption(mockCrypto); | ||
return mxEvent; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes development harder as we won't get errors when the types for the provided fields are wrong (it'll tell you to cast to unknown first if sure) and are left to fend for our own, if we're not going to use the types then why have them in the first place. It can and will result in tests which end up testing things not conforming to interfaces, providing incorrect return types and the like. We should not be using ts-ignore anywhere if we can help it, I'm surprised it isn't linted against at this layer like we do at other layers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use
Parameters<typeof MatrixEvent["attemptDecryption"]>[0]
as an alternative for CryptoBackendThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an odd question. We have the type so that we can use it in the internals of js-sdk. The fact that a library defines a type in its internals does not necessarily mean that every application using that library can and should be using that type. Indeed, exposing those types makes a library way harder to use because it means application authors have to read through way more documentation to find the thing they are actually supposed to use.
The fundamental problem here is that we are poking into the innards of js-sdk in order to make a UTD event. Really, the problem is that we are calling
MatrixEvent.attemptDecryption
, which is an internal method (and yes, it's parameter is an iternal type). But I don't really have any great ideas for avoiding that.Mayyyybe? The existing code doesn't actually implement
CryptoBackend
; it just mocks out one function for it. Who is to say thatattemptDecryption
doesn't care about any of the rest of the interface? And once you're mocking a function, its declared interface seems the least of your problems: what it actually does is far more important for whether the test is realistic.I would strongly argue that having a
@ts-ignore
in test code is a lesser evil than makingCryptoBackend
part of js-sdk's public interface.Anyway, I have applied your suggestion, which seems to solve the problem here.