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

Timestamp massaging in send_state_event #151

Open
gabrc52 opened this issue Jun 11, 2023 · 3 comments
Open

Timestamp massaging in send_state_event #151

gabrc52 opened this issue Jun 11, 2023 · 3 comments

Comments

@gabrc52
Copy link
Contributor

gabrc52 commented Jun 11, 2023

Some client API (application service) methods do not seem to have a way of doing timestamp massaging from within Mautrix methods.

Some methods like send_text, react and send_image do accept an undocumented timestamp parameter, but other methods like ensure_joined, invite_user, join_room, pin_message, etc do not have this.

This would be useful to write an application service that lets you import messages from another platform to Matrix, including room join and message pin events (instead of inviting and joining all ghost users prior to bridging messages).


Update: I see that only the methods to send message events and state events in the Matrix API itself let you change the timestamp, so for a join I'd need to manually send a state event. I can probably do that if it's more of a Matrix limitation then.


It would be nice for other methods that ultimately result in a state event (even if only in the homeserver backend) to accept the timestamp parameter as well, and manually send state events if it is specified. But first, timestamp needs to be supported in send_state_event.

@tulir
Copy link
Member

tulir commented Jun 11, 2023

Overriding query params like that isn't supported, the proper way is the timestamp parameter. Helper endpoints for sending state events don't support timestamp massaging either (although there are some MSCs to add support)

@gabrc52 gabrc52 changed the title Timestamp massaging in all methods Timestamp massaging in send_state_event Jul 20, 2023
@gabrc52
Copy link
Contributor Author

gabrc52 commented Jul 20, 2023

Thank you for letting me know of the timestamp parameter--I hadn't come across it.

The spec (v1.7) now says

The ts query string argument is only valid on the following endpoints:

PUT /rooms/{roomId}/send/{eventType}/{txnId}
PUT /rooms/{roomId}/state/{eventType}/{stateKey}

I just tried manually calling the REST API, and can confirm timestamp massaging works for sending custom state events, but not in /leave or /join, as the spec says. (PR where the feature was added in Synapse specifically)

However, if I try doing it directly from mautrix-python, timestamp massaging works for leave events, but not for join events:

# this does not work
await user_api.send_state_event(
    ROOM,
    EventType.ROOM_MEMBER,
    MemberStateEventContent(membership=Membership.JOIN),
    USER,
    timestamp=TIMESTAMP,
)

# this works
await user_api.send_text(ROOM, "hi!", timestamp=TIMESTAMP)

# this works
await user_api.send_state_event(
    ROOM,
    EventType.ROOM_MEMBER,
    MemberStateEventContent(membership=Membership.LEAVE),
    USER,
    timestamp=TIMESTAMP,
)

@gabrc52
Copy link
Contributor Author

gabrc52 commented Jul 20, 2023

This does seem to work:

await user_api.api.request(
    Method.PUT,
    Path.v3.rooms[ROOM].state['m.room.member'][USER],
    timestamp=TIMESTAMP,
    content={'membership': 'join'},
)

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

No branches or pull requests

2 participants