Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot override ServerTypes and default URL #8628

Closed
abeluck opened this issue Feb 14, 2019 · 7 comments
Closed

Cannot override ServerTypes and default URL #8628

abeluck opened this issue Feb 14, 2019 · 7 comments
Assignees
Labels
P3 S-Minor Impairs non-critical functionality or suitable workarounds exist T-Defect

Comments

@abeluck
Copy link
Contributor

abeluck commented Feb 14, 2019

Problem: The ServerTypeSelector module is too tightly coupled to the Registration component.

The template string yourMatrixAccountText = _t('Create your %(serverName)s account', { in RegistrationForm always has serverName set to matrix.org, even when you change default HS url in config.json.

Screenshot:
screenshot from 2019-02-14 14-55-45

Use case: In a custom matrix-react-sdk skin, I want to be able to override the default Free/Premium/Advanced server types. The simplest case is changing the default Free hs/is urls to be my own homeserver url. One expects that the UI should also reflect these skin changes.

Root Cause:
This block of code in Registration.js always has hsUrl defined as the static string from ServerTypeSelector. And even if I provide a component that replaces ServerTypeSelector, I cannot override the constant TYPES.

Replacing the Registration component as well is not really an option as it is over 500 LOC and provides lots of functionality that would be common to many skins.

@jryans
Copy link
Collaborator

jryans commented Feb 14, 2019

I agree these components are too tightly coupled at the moment. See also #8297.

Having said that, if you do configure a default HS in config.json, Riot should pre-select the advanced / other column and show the correct server name:

image

Do you see something else?

@abeluck
Copy link
Contributor Author

abeluck commented Feb 14, 2019

@jryans You are correct. That is the default behavior, and it is working as expected.

However, what I am trying to do is provide my own src/components/views/auth/MyOwnServerTypeSelector.js that replaces the default one. I want my HS to be treated like matrix.org in the current selector, and I'm removing the modular.im button (as it makes no sense in my context).

In my fork of riot-web, I've created this custom component, and it is working fine! However the "Create your matrix.org account" text still shows even though it connects to my own HS.

@lampholder lampholder added T-Defect P3 S-Minor Impairs non-critical functionality or suitable workarounds exist and removed redesign labels Mar 14, 2019
@turt2live turt2live self-assigned this Apr 21, 2019
@turt2live
Copy link
Member

This should be fixed by matrix-org/matrix-react-sdk#2941 now that the hsName is pushed into ServerTypeSelector.TYPES.FREE.serverConfig - assuming you can override that, it should be fine. A quick test of changing the hsName there to something other than matrix.org at least renders it as such, so in theory changing it in-code should also work.

@turt2live
Copy link
Member

Fixed by matrix-org/matrix-react-sdk#3001 - it won't make it into 1.2.0, but should be in the next regularly scheduled release.

@abeluck
Copy link
Contributor Author

abeluck commented Sep 10, 2019

Unfortunately, it is not fixed yet. auth/Registration still imports a function from auth/ServerTypeSelector that is impossible to override.

The problem is that matrix-react-sdk/src/components/structures/auth/Registration.js is importing the function getTypeFromServerConfig from the existing ServerTypeSelector.js.

In my project I've provided a different component that replaces ServerTypeSelector, and it is used.

However because this function is cherry-picked out of the default ServerTypeSelector file, I have no way to make changes to TYPES.FREE without patching matrix-react-sdk/src/components/views/auth/ServerTypeSelector.js

@turt2live said:

This should be fixed by matrix-org/matrix-react-sdk#2941 now that the hsName is pushed into ServerTypeSelector.TYPES.FREE.serverConfig - assuming you can override that, it should be fine.

That's exactly the problem, you can't override it.

Would it be possible to re-open this issue and take another look?

@turt2live
Copy link
Member

You should be able to override it with:

import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
import {TYPES} from "matrix-react-sdk/lib/components/views/auth/ServerTypeSelector";

TYPES.FREE.serverConfig = makeType(ValidatedServerConfig, {
    hsUrl: "https://example.org",
    hsName: "example.org",
    hsNameIsDifferent: false,
    isUrl: "https://vector.im",
});

at least, this is what worked for me in testing and just now.

@abeluck
Copy link
Contributor Author

abeluck commented Sep 10, 2019

@turt2live many thanks!

Sorry for the noise. I don't use js that often, so it didn't occur to me I could just monkey patch the TYPES object that way.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 S-Minor Impairs non-critical functionality or suitable workarounds exist T-Defect
Projects
None yet
Development

No branches or pull requests

4 participants