Skip to content

Auto-default homeserver suffix for username and room during interactive login#219

Open
Itz-Agasta wants to merge 5 commits into
8go:mainfrom
Itz-Agasta:feat/ux
Open

Auto-default homeserver suffix for username and room during interactive login#219
Itz-Agasta wants to merge 5 commits into
8go:mainfrom
Itz-Agasta:feat/ux

Conversation

@Itz-Agasta

Copy link
Copy Markdown

During --login password (and other interactive login flows), the homeserver is entered first. If the user then types a bare username (@agasta) or default room (!roomid) without the :homeserver suffix, the prompt rejected it with "Invalid username/room format" and forced the user to retype the full id.

Now, if the input is missing the :homeserver part, it's auto-appended using the homeserver already entered, same UX improvement.

Closes #217

matrix2.mp4

Comment thread src/main.rs Outdated
@Benjamin-Loison

Copy link
Copy Markdown
Collaborator

The changes look decent, I have not checked them yet, I am waiting answer to my comment.

…e login

The interactive login asks for the homeserver first. For username and
default room, accept either a bare local part (e.g. "john", "someRoomId")
— appending the homeserver automatically — or a full id pasted from a
client (e.g. "@john:server", "!room:server"), which is used verbatim.
Comment thread src/main.rs
@Itz-Agasta

Itz-Agasta commented Jul 3, 2026

Copy link
Copy Markdown
Author

I finalized with this rule:

If the input already contains :, treat it as a full Matrix identifier and use it verbatim. Otherwise, treat it as a local identifier and append the configured homeserver.

Field Input Result
Username agasta @agasta:matrix.org
Username @agasta:matrix.org Used as-is
Room ID ZYArk… !ZYArk…:matrix.org
Room ID !ZYArk…:matrix.org Used as-is

I originally wanted to accept only bare input--just agasta, with no leading @ and no server suffix. #219 (comment) That would keep things simple by always constructing the full Matrix ID ourselves.

but after thinking about it more (and looking at issue #220), I think the "accept either form" approach is better. The rule is consistent across usernames and room IDs, and it naturally supports delegated identifiers. If someone pastes @kcexton:mlug-au.org, we shouldn't silently append their server name with the configured homeserver.

room IDs are almost never typed manually--they're copied. Every Matrix client gives you the full !ZYArk…:matrix.org form. Requiring users to strip the :server suffix before pasting is unfriendly, and the bare-only approach even produced invalid IDs like !!id:server:server.

@Benjamin-Loison

Copy link
Copy Markdown
Collaborator

Do you have an idea of the wanted flow @8go?

@8go

8go commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Note that rooms can also be named rooms and start with #

Example: #family:matrix.myhomeserver.org

@8go

8go commented Jul 3, 2026

Copy link
Copy Markdown
Owner

For me personally there is NO doubt. User should have choice of entering either version, short or long.

It is up to the software to adapt. mc should accept pretty much everything (short, long) and then complete it if necessary.

Give the user the maximum choice please.

If you follow this then there are like 4 choices for rooms:
a) fully specified a:b.c or similar (use as-is, don't modify)
b) abc ==> here I would go with: !abc:base-url-from-well-known or !abc:default-as-given-by-user
c) !abc ==> convert to !abc:base-url-from-well-known or !abc:default-as-given-by-user
d) #abc ==> convert to #abc:base-url-from-well-known or #abc:default-as-given-by-user

@Itz-Agasta

Itz-Agasta commented Jul 4, 2026

Copy link
Copy Markdown
Author

guys have a look now

Room (get_room_default):

  • x:y (has :) -> verbatim
  • abc -> !abc:host
  • !abc -> !abc:host
  • #abc (named room) -> #abc:host

Username (get_user_login):

  • john -> @john:host
  • @john -> john:host (trim stray @, no @@)
  • @john:server -> verbatim

Comment thread src/main.rs Outdated
Comment thread src/main.rs
@Benjamin-Loison

Copy link
Copy Markdown
Collaborator
Personal notes concerning named room:

DuckDuckGo and Google search Element named room URI.

Benjamin_Loison/Voice_assistant/src/commit/016364787bf0b55593902d9ffd4f52acf8d99c7f/README.md?display=source#L342

is an example.

Comment thread src/main.rs
Comment thread src/main.rs
@Benjamin-Loison

Benjamin-Loison commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Changes look decent, but I have not tested them yet.

What do you (also @8go) think about using regex? This may help state that the expected format is not respected (if specify room: for instance), for instance if the user mistype.

Comment thread src/main.rs
@Itz-Agasta

Itz-Agasta commented Jul 5, 2026

Copy link
Copy Markdown
Author

What do you (also @8go) think about using regex? This may help state that the expected format is not respected (if specify room: for instance), for instance if the user mistype.

Mmmm yes && regex is already a dep so no new dependency. yk i'd like to keep the pattern loose, not a strict MXID grammar. A tight regex risks rejecting valid input , e.g. server_name can include a port or an IPv6 literal (!room:[::1]:8448), so "exactly one colon" or a strict charset would reject legit ids.....

so Something like validate only the structure on the verbatim (contains ':') path:

  • username: ^@[^:]+:.+$
  • room: ^[!#][^:]+:.+$

.+ after the colon still allows ports/IPv6/aliases, but it catches the real typo cases (room:, :server, bare @) with a clear "format not respected" message. The authoritative check still happens server-side at login.

@Benjamin-Loison

Benjamin-Loison commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Indeed a correct regex may not be trivial, let us forget about that. I'll give a try to your changes in less than 72 hours.

@8go

8go commented Jul 7, 2026

Copy link
Copy Markdown
Owner

My humble opinion:

Handling shortcuts and sigils and the simple and obvious cases (as done) IS GOOD ENOUGH.

I myself do not even know the full syntax of user and room names (I would have to look it up). I would NOT do a FULL and COMPLETE check. I would not to a FULL REGEX to try to capture ALL errors. The server already implements that. Let's not re-implement it. We try to be user friendly and we should handle cases to make it user friendly, but not more.

@8go

8go commented Jul 7, 2026

Copy link
Copy Markdown
Owner

@Itz-Agasta says:

The authoritative check still happens server-side at login.

I fully agree with that

@Benjamin-Loison

Copy link
Copy Markdown
Collaborator
cargo run -- --login password --credentials credentials.json --store store/
Output:
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/matrix-commander-rs --login password --credentials credentials.json --store store/`
Enter your Matrix homeserver (e.g. https://some.homeserver.org): https://matrix.org
Enter your Matrix username (e.g. john or @john:some.homeserver.org): @overclock3000:matrix.org
Enter Matrix password for this user: 
Enter your desired name for the Matrix device that is going to be created for you (e.g. matrix-commander-rs): matrix-commander-rs_instance-20230827-2235
Enter name of one of your Matrix rooms that you want to use as default room  (e.g. someRoomId or !someRoomId:some.homeserver.org): !sNARMdEsFZERaQAJzl:matrix.org
cargo run -- --login password --credentials credentials.json --store store/
Output:
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/matrix-commander-rs --login password --credentials credentials.json --store store/`
Enter your Matrix homeserver (e.g. https://some.homeserver.org): matrix.org
2026-07-08T10:52:23.209516Z ERROR matrix_commander_rs: Error: The syntax is incorrect. Homeserver must be a valid URL! Start with 'http://' or 'https://'. Details: relative URL without a base
Enter your Matrix homeserver (e.g. https://some.homeserver.org): 

In my opinion we could assume https, but I don't have a strong opinion, what do you think @8go?

cargo run -- --login password --credentials credentials.json --store store/
Output:
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/matrix-commander-rs --login password --credentials credentials.json --store store/`
Enter your Matrix homeserver (e.g. https://some.homeserver.org): https://matrix.org
Enter your Matrix username (e.g. john or @john:some.homeserver.org): @overclock3000
Enter Matrix password for this user: 
Enter your desired name for the Matrix device that is going to be created for you (e.g. matrix-commander-rs): matrix-commander-rs_instance-20230827-2235
Enter name of one of your Matrix rooms that you want to use as default room  (e.g. someRoomId or !someRoomId:some.homeserver.org): !sNARMdEsFZERaQAJzl
cargo run -- --login password --credentials credentials.json --store store/
Output:
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.26s
     Running `target/debug/matrix-commander-rs --login password --credentials credentials.json --store store/`
Enter your Matrix homeserver (e.g. https://some.homeserver.org): https://matrix.org
Enter your Matrix username (e.g. john or @john:some.homeserver.org): overclock3000
Enter Matrix password for this user: 
Enter your desired name for the Matrix device that is going to be created for you (e.g. matrix-commander-rs): matrix-commander-rs_instance-20230827-2235
Enter name of one of your Matrix rooms that you want to use as default room  (e.g. someRoomId or !someRoomId:some.homeserver.org): sNARMdEsFZERaQAJzl
cargo run -- --login password --credentials credentials.json --store store/
Output:
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/matrix-commander-rs --login password --credentials credentials.json --store store/`
Enter your Matrix homeserver (e.g. https://some.homeserver.org): https://matrix.org
Enter your Matrix username (e.g. john or @john:some.homeserver.org): overclock3000:matrix.org
Enter Matrix password for this user: 
Enter your desired name for the Matrix device that is going to be created for you (e.g. matrix-commander-rs): matrix-commander-rs_instance-20230827-2235
Enter name of one of your Matrix rooms that you want to use as default room  (e.g. someRoomId or !someRoomId:some.homeserver.org): sNARMdEsFZERaQAJzl:matrix.org
2026-07-08T11:00:05.409394Z ERROR matrix_sdk::http_client: Error while sending request: Api(Server(MatrixError(Error { status_code: 403, body: Standard(StandardErrorBody { kind: Forbidden, message: "Invalid username/password" }) })))
2026-07-08T11:00:05.409483Z ERROR matrix_commander_rs::mclient: Error: the server returned an error: [403 / M_FORBIDDEN] Invalid username/password
2026-07-08T11:00:05.409883Z ERROR matrix_commander_rs: Login to server failed or credentials information could not be written to disk. Check your arguments and try --login again. Reported error is: LoginFailed
Error: LoginFailed

@Itz-Agasta the latter command should work, no? I have verified twice that the credentials are correct. If you're fine with making it work, then please add a correcting commit.

Otherwise everything looks good to me, thank you.

Interactive login rejected a username or room entered with a ':' domain
but no leading sigil (e.g`overclock3000:matrix.org` or
`sNARMdEsFZERaQAJzl:matrix.org`), causing a 403 login failure since
Matrix requires the '@' / '!' sigil.

The ':'-present branch now prepends '@' for usernames and '!' for rooms
when no sigil is present, matching the sigil-less local-part branch.
@Itz-Agasta

Copy link
Copy Markdown
Author

the latter command should work, no?

Have a look it should work now... i have tested locally.. we are currently covering

# Field Input Normalized result
1 user @overclock3000:matrix.org @overclock3000:matrix.org
2 user @overclock3000 @overclock3000:matrix.org
3 user overclock3000 @overclock3000:matrix.org
4 user overclock3000:matrix.org @overclock3000:matrix.org
5 room !sNARMdEsFZERaQAJzl:matrix.org !sNARMdEsFZERaQAJzl:matrix.org
6 room !sNARMdEsFZERaQAJzl !sNARMdEsFZERaQAJzl:matrix.org
7 room sNARMdEsFZERaQAJzl !sNARMdEsFZERaQAJzl:matrix.org
8 room sNARMdEsFZERaQAJzl:matrix.org !sNARMdEsFZERaQAJzl:matrix.org

Lemme know if im missing something

Comment thread src/main.rs Outdated
@Benjamin-Loison

Copy link
Copy Markdown
Collaborator

Other changes look correct, but will be tested once you will address the comment I let.

'abc:server' is ambiguous: it can be the room id '!abc:server' or the
room alias '#abc:server', and nothing can tell them apart before login.
Prompt again instead of guessing '!'. Full room ids and full room
aliases are now stored verbatim.

User ids are unaffected: '@' is the only sigil there, so 'john:server'
remains an unambiguous completion.

Also mention the room alias form in the prompt, as it is accepted too.
'some.homeserver.org:8448' parses as a URL with scheme
'some.homeserver.org' and no host, so host_str().unwrap() panicked
while completing the user name and the room. Assume 'https://' unless
the input already is a URL with a host, which also lets the user enter
a bare 'some.homeserver.org'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid specifying already specified homeserver for username and room

3 participants