diff --git a/appservice/intent.go b/appservice/intent.go index 96a8430..9dc8a6c 100644 --- a/appservice/intent.go +++ b/appservice/intent.go @@ -296,6 +296,7 @@ func (intent *IntentAPI) SendText(roomID id.RoomID, text string) (*mautrix.RespS return intent.Client.SendText(roomID, text) } +// Deprecated: This does not allow setting image metadata, you should prefer SendMessageEvent with a properly filled &event.MessageEventContent func (intent *IntentAPI) SendImage(roomID id.RoomID, body string, url id.ContentURI) (*mautrix.RespSendEvent, error) { if err := intent.EnsureJoined(roomID); err != nil { return nil, err @@ -303,6 +304,7 @@ func (intent *IntentAPI) SendImage(roomID id.RoomID, body string, url id.Content return intent.Client.SendImage(roomID, body, url) } +// Deprecated: This does not allow setting video metadata, you should prefer SendMessageEvent with a properly filled &event.MessageEventContent func (intent *IntentAPI) SendVideo(roomID id.RoomID, body string, url id.ContentURI) (*mautrix.RespSendEvent, error) { if err := intent.EnsureJoined(roomID); err != nil { return nil, err diff --git a/client.go b/client.go index 8f15b14..ea9913a 100644 --- a/client.go +++ b/client.go @@ -1,6 +1,6 @@ // Package mautrix implements the Matrix Client-Server API. // -// Specification can be found at http://matrix.org/docs/spec/client_server/r0.4.0.html +// Specification can be found at https://spec.matrix.org/v1.2/client-server-api/ package mautrix import ( @@ -47,7 +47,6 @@ type Stringifiable interface { // Client represents a Matrix client. type Client struct { HomeserverURL *url.URL // The base homeserver URL - Prefix URLPath // The API prefix eg '/_matrix/client/r0' UserID id.UserID // The user ID of the client. Used for forming HTTP paths which use the client's user ID. DeviceID id.DeviceID // The device ID of the client. AccessToken string // The access_token for the client. @@ -66,9 +65,9 @@ type Client struct { txnID int32 - // The ?user_id= query parameter for application services. This must be set *prior* to calling a method. If this is empty, - // no user_id parameter will be sent. - // See http://matrix.org/docs/spec/application_service/unstable.html#identity-assertion + // The ?user_id= query parameter for application services. This must be set *prior* to calling a method. + // If this is empty, no user_id parameter will be sent. + // See https://spec.matrix.org/v1.2/application-service-api/#identity-assertion AppServiceUserID id.UserID syncingID uint32 // Identifies the current Sync. Only one Sync can be active at any given time. @@ -89,7 +88,7 @@ type IdentityServerInfo struct { // DiscoverClientAPI resolves the client API URL from a Matrix server name. // Use ParseUserID to extract the server name from a user ID. -// https://matrix.org/docs/spec/client_server/r0.6.0#server-discovery +// https://spec.matrix.org/v1.2/client-server-api/#server-discovery func DiscoverClientAPI(serverName string) (*ClientWellKnown, error) { wellKnownURL := url.URL{ Scheme: "https", @@ -484,21 +483,21 @@ func (cli *Client) executeCompiledRequest(req *http.Request, retries int, backof return handler(req, res, responseJSON) } -// Whoami gets the user ID of the current user. See https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-join +// Whoami gets the user ID of the current user. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3accountwhoami func (cli *Client) Whoami() (resp *RespWhoami, err error) { - urlPath := cli.BuildURL("account", "whoami") + urlPath := cli.BuildClientURL("v3", "account", "whoami") _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } -// CreateFilter makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter +// CreateFilter makes an HTTP request according to https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3useruseridfilter func (cli *Client) CreateFilter(filter *Filter) (resp *RespCreateFilter, err error) { - urlPath := cli.BuildURL("user", cli.UserID, "filter") + urlPath := cli.BuildClientURL("v3", "user", cli.UserID, "filter") _, err = cli.MakeRequest("POST", urlPath, filter, &resp) return } -// SyncRequest makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync +// SyncRequest makes an HTTP request according to https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3sync func (cli *Client) SyncRequest(timeout int, since, filterID string, fullState bool, setPresence event.Presence, ctx context.Context) (resp *RespSync, err error) { return cli.FullSyncRequest(ReqSync{ Timeout: timeout, @@ -540,9 +539,9 @@ func (req *ReqSync) BuildQuery() map[string]string { return query } -// FullSyncRequest makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync +// FullSyncRequest makes an HTTP request according to https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3sync func (cli *Client) FullSyncRequest(req ReqSync) (resp *RespSync, err error) { - urlPath := cli.BuildURLWithQuery(URLPath{"sync"}, req.BuildQuery()) + urlPath := cli.BuildURLWithQuery(ClientURLPath{"v3", "sync"}, req.BuildQuery()) fullReq := FullRequest{ Method: http.MethodGet, URL: urlPath, @@ -589,15 +588,15 @@ func (cli *Client) register(url string, req *ReqRegister) (resp *RespRegister, u return } -// Register makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register +// Register makes an HTTP request according to https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3register // // Registers with kind=user. For kind=guest, see RegisterGuest. func (cli *Client) Register(req *ReqRegister) (*RespRegister, *RespUserInteractive, error) { - u := cli.BuildURL("register") + u := cli.BuildClientURL("v3", "register") return cli.register(u, req) } -// RegisterGuest makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register +// RegisterGuest makes an HTTP request according to https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3register // with kind=guest. // // For kind=user, see Register. @@ -605,11 +604,11 @@ func (cli *Client) RegisterGuest(req *ReqRegister) (*RespRegister, *RespUserInte query := map[string]string{ "kind": "guest", } - u := cli.BuildURLWithQuery(URLPath{"register"}, query) + u := cli.BuildURLWithQuery(ClientURLPath{"v3", "register"}, query) return cli.register(u, req) } -// RegisterDummy performs m.login.dummy registration according to https://matrix.org/docs/spec/client_server/r0.2.0.html#dummy-auth +// RegisterDummy performs m.login.dummy registration according to https://spec.matrix.org/v1.2/client-server-api/#dummy-auth // // Only a username and password need to be provided on the ReqRegister struct. Most local/developer homeservers will allow registration // this way. If the homeserver does not, an error is returned. @@ -641,17 +640,18 @@ func (cli *Client) RegisterDummy(req *ReqRegister) (*RespRegister, error) { return res, nil } +// GetLoginFlows fetches the login flows that the homeserver supports using https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3login func (cli *Client) GetLoginFlows() (resp *RespLoginFlows, err error) { - urlPath := cli.BuildURL("login") + urlPath := cli.BuildClientURL("v3", "login") _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } -// Login a user to the homeserver according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login +// Login a user to the homeserver according to https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3login func (cli *Client) Login(req *ReqLogin) (resp *RespLogin, err error) { _, err = cli.MakeFullRequest(FullRequest{ Method: http.MethodPost, - URL: cli.BuildURL("login"), + URL: cli.BuildClientURL("v3", "login"), RequestJSON: req, ResponseJSON: &resp, SensitiveContent: len(req.Password) > 0 || len(req.Token) > 0, @@ -674,70 +674,70 @@ func (cli *Client) Login(req *ReqLogin) (resp *RespLogin, err error) { return } -// Logout the current user. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout +// Logout the current user. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3logout // This does not clear the credentials from the client instance. See ClearCredentials() instead. func (cli *Client) Logout() (resp *RespLogout, err error) { - urlPath := cli.BuildURL("logout") + urlPath := cli.BuildClientURL("v3", "logout") _, err = cli.MakeRequest("POST", urlPath, nil, &resp) return } -// LogoutAll logs out all the devices of the current user. See https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-logout-all +// LogoutAll logs out all the devices of the current user. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3logoutall // This does not clear the credentials from the client instance. See ClearCredentials() instead. func (cli *Client) LogoutAll() (resp *RespLogout, err error) { - urlPath := cli.BuildURL("logout", "all") + urlPath := cli.BuildClientURL("v3", "logout", "all") _, err = cli.MakeRequest("POST", urlPath, nil, &resp) return } -// Versions returns the list of supported Matrix versions on this homeserver. See http://matrix.org/docs/spec/client_server/r0.6.1.html#get-matrix-client-versions +// Versions returns the list of supported Matrix versions on this homeserver. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientversions func (cli *Client) Versions() (resp *RespVersions, err error) { - urlPath := cli.BuildBaseURL("_matrix", "client", "versions") + urlPath := cli.BuildClientURL("versions") _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } -// JoinRoom joins the client to a room ID or alias. See http://matrix.org/docs/spec/client_server/r0.6.1.html#post-matrix-client-r0-join-roomidoralias +// JoinRoom joins the client to a room ID or alias. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3joinroomidoralias // // If serverName is specified, this will be added as a query param to instruct the homeserver to join via that server. If content is specified, it will // be JSON encoded and used as the request body. func (cli *Client) JoinRoom(roomIDorAlias, serverName string, content interface{}) (resp *RespJoinRoom, err error) { var urlPath string if serverName != "" { - urlPath = cli.BuildURLWithQuery(URLPath{"join", roomIDorAlias}, map[string]string{ + urlPath = cli.BuildURLWithQuery(ClientURLPath{"v3", "join", roomIDorAlias}, map[string]string{ "server_name": serverName, }) } else { - urlPath = cli.BuildURL("join", roomIDorAlias) + urlPath = cli.BuildClientURL("v3", "join", roomIDorAlias) } _, err = cli.MakeRequest("POST", urlPath, content, &resp) return } -// JoinRoomByID joins the client to a room ID. See https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-join +// JoinRoomByID joins the client to a room ID. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidjoin // // Unlike JoinRoom, this method can only be used to join rooms that the server already knows about. // It's mostly intended for bridges and other things where it's already certain that the server is in the room. func (cli *Client) JoinRoomByID(roomID id.RoomID) (resp *RespJoinRoom, err error) { - _, err = cli.MakeRequest("POST", cli.BuildURL("rooms", roomID, "join"), nil, &resp) + _, err = cli.MakeRequest("POST", cli.BuildClientURL("v3", "rooms", roomID, "join"), nil, &resp) return } -// GetDisplayName returns the display name of the user with the specified MXID. See https://matrix.org/docs/spec/client_server/r0.6.1.html#get-matrix-client-r0-profile-userid-displayname +// GetDisplayName returns the display name of the user with the specified MXID. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3profileuseriddisplayname func (cli *Client) GetDisplayName(mxid id.UserID) (resp *RespUserDisplayName, err error) { - urlPath := cli.BuildURL("profile", mxid, "displayname") + urlPath := cli.BuildClientURL("v3", "profile", mxid, "displayname") _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } -// GetOwnDisplayName returns the user's display name. See https://matrix.org/docs/spec/client_server/r0.6.1.html#get-matrix-client-r0-profile-userid-displayname +// GetOwnDisplayName returns the user's display name. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3profileuseriddisplayname func (cli *Client) GetOwnDisplayName() (resp *RespUserDisplayName, err error) { return cli.GetDisplayName(cli.UserID) } -// SetDisplayName sets the user's profile display name. See http://matrix.org/docs/spec/client_server/r0.6.1.html#put-matrix-client-r0-profile-userid-displayname +// SetDisplayName sets the user's profile display name. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3profileuseriddisplayname func (cli *Client) SetDisplayName(displayName string) (err error) { - urlPath := cli.BuildURL("profile", cli.UserID, "displayname") + urlPath := cli.BuildClientURL("v3", "profile", cli.UserID, "displayname") s := struct { DisplayName string `json:"displayname"` }{displayName} @@ -745,9 +745,9 @@ func (cli *Client) SetDisplayName(displayName string) (err error) { return } -// GetAvatarURL gets the avatar URL of the user with the specified MXID. See http://matrix.org/docs/spec/client_server/r0.6.1.html#get-matrix-client-r0-profile-userid-avatar-url +// GetAvatarURL gets the avatar URL of the user with the specified MXID. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3profileuseridavatar_url func (cli *Client) GetAvatarURL(mxid id.UserID) (url id.ContentURI, err error) { - urlPath := cli.BuildURL("profile", cli.UserID, "avatar_url") + urlPath := cli.BuildClientURL("v3", "profile", cli.UserID, "avatar_url") s := struct { AvatarURL id.ContentURI `json:"avatar_url"` }{} @@ -760,14 +760,14 @@ func (cli *Client) GetAvatarURL(mxid id.UserID) (url id.ContentURI, err error) { return } -// GetOwnAvatarURL gets the user's avatar URL. See http://matrix.org/docs/spec/client_server/r0.6.1.html#get-matrix-client-r0-profile-userid-avatar-url +// GetOwnAvatarURL gets the user's avatar URL. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3profileuseridavatar_url func (cli *Client) GetOwnAvatarURL() (url id.ContentURI, err error) { return cli.GetAvatarURL(cli.UserID) } -// SetAvatarURL sets the user's avatar URL. See http://matrix.org/docs/spec/client_server/r0.6.1.html#put-matrix-client-r0-profile-userid-avatar-url +// SetAvatarURL sets the user's avatar URL. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3profileuseridavatar_url func (cli *Client) SetAvatarURL(url id.ContentURI) (err error) { - urlPath := cli.BuildURL("profile", cli.UserID, "avatar_url") + urlPath := cli.BuildClientURL("v3", "profile", cli.UserID, "avatar_url") s := struct { AvatarURL string `json:"avatar_url"` }{url.String()} @@ -779,16 +779,16 @@ func (cli *Client) SetAvatarURL(url id.ContentURI) (err error) { return nil } -// GetAccountData gets the user's account data of this type. See https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-user-userid-account-data-type +// GetAccountData gets the user's account data of this type. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3useruseridaccount_datatype func (cli *Client) GetAccountData(name string, output interface{}) (err error) { - urlPath := cli.BuildURL("user", cli.UserID, "account_data", name) + urlPath := cli.BuildClientURL("v3", "user", cli.UserID, "account_data", name) _, err = cli.MakeRequest("GET", urlPath, nil, output) return } -// SetAccountData sets the user's account data of this type. See https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-user-userid-account-data-type +// SetAccountData sets the user's account data of this type. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridaccount_datatype func (cli *Client) SetAccountData(name string, data interface{}) (err error) { - urlPath := cli.BuildURL("user", cli.UserID, "account_data", name) + urlPath := cli.BuildClientURL("v3", "user", cli.UserID, "account_data", name) _, err = cli.MakeRequest("PUT", urlPath, &data, nil) if err != nil { return err @@ -797,14 +797,16 @@ func (cli *Client) SetAccountData(name string, data interface{}) (err error) { return nil } +// GetRoomAccountData gets the user's account data of this type in a specific room. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridaccount_datatype func (cli *Client) GetRoomAccountData(roomID id.RoomID, name string, output interface{}) (err error) { - urlPath := cli.BuildURL("user", cli.UserID, "rooms", roomID, "account_data", name) + urlPath := cli.BuildClientURL("v3", "user", cli.UserID, "rooms", roomID, "account_data", name) _, err = cli.MakeRequest("GET", urlPath, nil, output) return } +// SetRoomAccountData sets the user's account data of this type in a specific room. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridroomsroomidaccount_datatype func (cli *Client) SetRoomAccountData(roomID id.RoomID, name string, data interface{}) (err error) { - urlPath := cli.BuildURL("user", cli.UserID, "rooms", roomID, "account_data", name) + urlPath := cli.BuildClientURL("v3", "user", cli.UserID, "rooms", roomID, "account_data", name) _, err = cli.MakeRequest("PUT", urlPath, &data, nil) if err != nil { return err @@ -816,12 +818,9 @@ func (cli *Client) SetRoomAccountData(roomID id.RoomID, name string, data interf type ReqSendEvent struct { Timestamp int64 TransactionID string - - ParentID string - RelType event.RelationType } -// SendMessageEvent sends a message event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid +// SendMessageEvent sends a message event into a room. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid // contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal. func (cli *Client) SendMessageEvent(roomID id.RoomID, eventType event.Type, contentJSON interface{}, extra ...ReqSendEvent) (resp *RespSendEvent, err error) { var req ReqSendEvent @@ -841,28 +840,25 @@ func (cli *Client) SendMessageEvent(roomID id.RoomID, eventType event.Type, cont queryParams["ts"] = strconv.FormatInt(req.Timestamp, 10) } - urlData := URLPath{"rooms", roomID, "send", eventType.String(), txnID} - if len(req.ParentID) > 0 { - urlData = URLPath{"rooms", roomID, "send_relation", req.ParentID, req.RelType, eventType.String(), txnID} - } + urlData := ClientURLPath{"v3", "rooms", roomID, "send", eventType.String(), txnID} urlPath := cli.BuildURLWithQuery(urlData, queryParams) _, err = cli.MakeRequest("PUT", urlPath, contentJSON, &resp) return } -// SendStateEvent sends a state event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey +// SendStateEvent sends a state event into a room. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidstateeventtypestatekey // contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal. func (cli *Client) SendStateEvent(roomID id.RoomID, eventType event.Type, stateKey string, contentJSON interface{}) (resp *RespSendEvent, err error) { - urlPath := cli.BuildURL("rooms", roomID, "state", eventType.String(), stateKey) + urlPath := cli.BuildClientURL("v3", "rooms", roomID, "state", eventType.String(), stateKey) _, err = cli.MakeRequest("PUT", urlPath, contentJSON, &resp) return } -// SendStateEvent sends a state event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey +// SendMassagedStateEvent sends a state event into a room with a custom timestamp. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidstateeventtypestatekey // contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal. func (cli *Client) SendMassagedStateEvent(roomID id.RoomID, eventType event.Type, stateKey string, contentJSON interface{}, ts int64) (resp *RespSendEvent, err error) { - urlPath := cli.BuildURLWithQuery(URLPath{"rooms", roomID, "state", eventType.String(), stateKey}, map[string]string{ + urlPath := cli.BuildURLWithQuery(ClientURLPath{"v3", "rooms", roomID, "state", eventType.String(), stateKey}, map[string]string{ "ts": strconv.FormatInt(ts, 10), }) _, err = cli.MakeRequest("PUT", urlPath, contentJSON, &resp) @@ -870,7 +866,7 @@ func (cli *Client) SendMassagedStateEvent(roomID id.RoomID, eventType event.Type } // SendText sends an m.room.message event into the given room with a msgtype of m.text -// See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-text +// See https://spec.matrix.org/v1.2/client-server-api/#mtext func (cli *Client) SendText(roomID id.RoomID, text string) (*RespSendEvent, error) { return cli.SendMessageEvent(roomID, event.EventMessage, &event.MessageEventContent{ MsgType: event.MsgText, @@ -879,7 +875,9 @@ func (cli *Client) SendText(roomID id.RoomID, text string) (*RespSendEvent, erro } // SendImage sends an m.room.message event into the given room with a msgtype of m.image -// See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-image +// See https://spec.matrix.org/v1.2/client-server-api/#mimage +// +// Deprecated: This does not allow setting image metadata, you should prefer SendMessageEvent with a properly filled &event.MessageEventContent func (cli *Client) SendImage(roomID id.RoomID, body string, url id.ContentURI) (*RespSendEvent, error) { return cli.SendMessageEvent(roomID, event.EventMessage, &event.MessageEventContent{ MsgType: event.MsgImage, @@ -889,7 +887,9 @@ func (cli *Client) SendImage(roomID id.RoomID, body string, url id.ContentURI) ( } // SendVideo sends an m.room.message event into the given room with a msgtype of m.video -// See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-video +// See https://spec.matrix.org/v1.2/client-server-api/#mvideo +// +// Deprecated: This does not allow setting video metadata, you should prefer SendMessageEvent with a properly filled &event.MessageEventContent func (cli *Client) SendVideo(roomID id.RoomID, body string, url id.ContentURI) (*RespSendEvent, error) { return cli.SendMessageEvent(roomID, event.EventMessage, &event.MessageEventContent{ MsgType: event.MsgVideo, @@ -899,7 +899,7 @@ func (cli *Client) SendVideo(roomID id.RoomID, body string, url id.ContentURI) ( } // SendNotice sends an m.room.message event into the given room with a msgtype of m.notice -// See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-notice +// See https://spec.matrix.org/v1.2/client-server-api/#mnotice func (cli *Client) SendNotice(roomID id.RoomID, text string) (*RespSendEvent, error) { return cli.SendMessageEvent(roomID, event.EventMessage, &event.MessageEventContent{ MsgType: event.MsgNotice, @@ -917,7 +917,7 @@ func (cli *Client) SendReaction(roomID id.RoomID, eventID id.EventID, reaction s }) } -// RedactEvent redacts the given event. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid +// RedactEvent redacts the given event. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidredacteventidtxnid func (cli *Client) RedactEvent(roomID id.RoomID, eventID id.EventID, extra ...ReqRedact) (resp *RespSendEvent, err error) { req := ReqRedact{} if len(extra) > 0 { @@ -935,23 +935,23 @@ func (cli *Client) RedactEvent(roomID id.RoomID, eventID id.EventID, extra ...Re } else { txnID = cli.TxnID() } - urlPath := cli.BuildURL("rooms", roomID, "redact", eventID, txnID) + urlPath := cli.BuildClientURL("v3", "rooms", roomID, "redact", eventID, txnID) _, err = cli.MakeRequest("PUT", urlPath, req.Extra, &resp) return } -// CreateRoom creates a new Matrix room. See https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom +// CreateRoom creates a new Matrix room. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3createroom // resp, err := cli.CreateRoom(&mautrix.ReqCreateRoom{ // Preset: "public_chat", // }) // fmt.Println("Room:", resp.RoomID) func (cli *Client) CreateRoom(req *ReqCreateRoom) (resp *RespCreateRoom, err error) { - urlPath := cli.BuildURL("createRoom") + urlPath := cli.BuildClientURL("v3", "createRoom") _, err = cli.MakeRequest("POST", urlPath, req, &resp) return } -// LeaveRoom leaves the given room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave +// LeaveRoom leaves the given room. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidleave func (cli *Client) LeaveRoom(roomID id.RoomID, optionalReq ...*ReqLeave) (resp *RespLeaveRoom, err error) { req := &ReqLeave{} if len(optionalReq) == 1 { @@ -959,86 +959,86 @@ func (cli *Client) LeaveRoom(roomID id.RoomID, optionalReq ...*ReqLeave) (resp * } else if len(optionalReq) > 1 { panic("invalid number of arguments to LeaveRoom") } - u := cli.BuildURL("rooms", roomID, "leave") + u := cli.BuildClientURL("v3", "rooms", roomID, "leave") _, err = cli.MakeRequest("POST", u, req, &resp) return } -// ForgetRoom forgets a room entirely. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget +// ForgetRoom forgets a room entirely. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidforget func (cli *Client) ForgetRoom(roomID id.RoomID) (resp *RespForgetRoom, err error) { - u := cli.BuildURL("rooms", roomID, "forget") + u := cli.BuildClientURL("v3", "rooms", roomID, "forget") _, err = cli.MakeRequest("POST", u, struct{}{}, &resp) return } -// InviteUser invites a user to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite +// InviteUser invites a user to a room. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite func (cli *Client) InviteUser(roomID id.RoomID, req *ReqInviteUser) (resp *RespInviteUser, err error) { - u := cli.BuildURL("rooms", roomID, "invite") + u := cli.BuildClientURL("v3", "rooms", roomID, "invite") _, err = cli.MakeRequest("POST", u, req, &resp) return } -// InviteUserByThirdParty invites a third-party identifier to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#invite-by-third-party-id-endpoint +// InviteUserByThirdParty invites a third-party identifier to a room. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite-1 func (cli *Client) InviteUserByThirdParty(roomID id.RoomID, req *ReqInvite3PID) (resp *RespInviteUser, err error) { - u := cli.BuildURL("rooms", roomID, "invite") + u := cli.BuildClientURL("v3", "rooms", roomID, "invite") _, err = cli.MakeRequest("POST", u, req, &resp) return } -// KickUser kicks a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick +// KickUser kicks a user from a room. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidkick func (cli *Client) KickUser(roomID id.RoomID, req *ReqKickUser) (resp *RespKickUser, err error) { - u := cli.BuildURL("rooms", roomID, "kick") + u := cli.BuildClientURL("v3", "rooms", roomID, "kick") _, err = cli.MakeRequest("POST", u, req, &resp) return } -// BanUser bans a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban +// BanUser bans a user from a room. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidban func (cli *Client) BanUser(roomID id.RoomID, req *ReqBanUser) (resp *RespBanUser, err error) { - u := cli.BuildURL("rooms", roomID, "ban") + u := cli.BuildClientURL("v3", "rooms", roomID, "ban") _, err = cli.MakeRequest("POST", u, req, &resp) return } -// UnbanUser unbans a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban +// UnbanUser unbans a user from a room. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidunban func (cli *Client) UnbanUser(roomID id.RoomID, req *ReqUnbanUser) (resp *RespUnbanUser, err error) { - u := cli.BuildURL("rooms", roomID, "unban") + u := cli.BuildClientURL("v3", "rooms", roomID, "unban") _, err = cli.MakeRequest("POST", u, req, &resp) return } -// UserTyping sets the typing status of the user. See https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid +// UserTyping sets the typing status of the user. See https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidtypinguserid func (cli *Client) UserTyping(roomID id.RoomID, typing bool, timeout int64) (resp *RespTyping, err error) { req := ReqTyping{Typing: typing, Timeout: timeout} - u := cli.BuildURL("rooms", roomID, "typing", cli.UserID) + u := cli.BuildClientURL("v3", "rooms", roomID, "typing", cli.UserID) _, err = cli.MakeRequest("PUT", u, req, &resp) return } -// GetPresence gets the presence of the user with the specified MXID. See https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-presence-userid-status +// GetPresence gets the presence of the user with the specified MXID. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3presenceuseridstatus func (cli *Client) GetPresence(userID id.UserID) (resp *RespPresence, err error) { resp = new(RespPresence) - u := cli.BuildURL("presence", userID, "status") + u := cli.BuildClientURL("v3", "presence", userID, "status") _, err = cli.MakeRequest("GET", u, nil, resp) return } -// GetOwnPresence gets the user's presence. See https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-presence-userid-status +// GetOwnPresence gets the user's presence. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3presenceuseridstatus func (cli *Client) GetOwnPresence() (resp *RespPresence, err error) { return cli.GetPresence(cli.UserID) } func (cli *Client) SetPresence(status event.Presence) (err error) { req := ReqPresence{Presence: status} - u := cli.BuildURL("presence", cli.UserID, "status") + u := cli.BuildClientURL("v3", "presence", cli.UserID, "status") _, err = cli.MakeRequest("PUT", u, req, nil) return } // StateEvent gets a single state event in a room. It will attempt to JSON unmarshal into the given "outContent" struct with // the HTTP response body, or return an error. -// See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-statekey +// See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidstateeventtypestatekey func (cli *Client) StateEvent(roomID id.RoomID, eventType event.Type, stateKey string, outContent interface{}) (err error) { - u := cli.BuildURL("rooms", roomID, "state", eventType.String(), stateKey) + u := cli.BuildClientURL("v3", "rooms", roomID, "state", eventType.String(), stateKey) _, err = cli.MakeRequest("GET", u, nil, outContent) return } @@ -1082,11 +1082,11 @@ func parseRoomStateArray(_ *http.Request, res *http.Response, responseJSON inter } // State gets all state in a room. -// See https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-state +// See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidstate func (cli *Client) State(roomID id.RoomID) (stateMap RoomStateMap, err error) { _, err = cli.MakeFullRequest(FullRequest{ Method: http.MethodGet, - URL: cli.BuildURL("rooms", roomID, "state"), + URL: cli.BuildClientURL("v3", "rooms", roomID, "state"), ResponseJSON: &stateMap, Handler: parseRoomStateArray, }) @@ -1106,7 +1106,7 @@ func (cli *Client) UploadLink(link string) (*RespMediaUpload, error) { } func (cli *Client) GetDownloadURL(mxcURL id.ContentURI) string { - return cli.BuildBaseURL("_matrix", "media", "r0", "download", mxcURL.Homeserver, mxcURL.FileID) + return cli.BuildURL(MediaURLPath{"v3", "download", mxcURL.Homeserver, mxcURL.FileID}) } func (cli *Client) Download(mxcURL id.ContentURI) (io.ReadCloser, error) { @@ -1129,7 +1129,7 @@ func (cli *Client) DownloadBytes(mxcURL id.ContentURI) ([]byte, error) { // UnstableCreateMXC creates a blank Matrix content URI to allow uploading the content asynchronously later. // See https://github.com/matrix-org/matrix-spec-proposals/pull/2246 func (cli *Client) UnstableCreateMXC() (*RespCreateMXC, error) { - u, _ := url.Parse(cli.BuildBaseURL("_matrix", "media", "unstable", "fi.mau.msc2246", "create")) + u, _ := url.Parse(cli.BuildURL(MediaURLPath{"unstable", "fi.mau.msc2246", "create"})) var m RespCreateMXC _, err := cli.MakeFullRequest(FullRequest{ Method: http.MethodPost, @@ -1194,10 +1194,10 @@ type ReqUploadMedia struct { // UploadMedia uploads the given data to the content repository and returns an MXC URI. // See https://spec.matrix.org/v1.2/client-server-api/#post_matrixmediav3upload func (cli *Client) UploadMedia(data ReqUploadMedia) (*RespMediaUpload, error) { - u, _ := url.Parse(cli.BuildBaseURL("_matrix", "media", "r0", "upload")) + u, _ := url.Parse(cli.BuildURL(MediaURLPath{"v3", "upload"})) method := http.MethodPost if !data.UnstableMXC.IsEmpty() { - u, _ = url.Parse(cli.BuildBaseURL("_matrix", "media", "unstable", "fi.mau.msc2246", "upload", data.UnstableMXC.Homeserver, data.UnstableMXC.FileID)) + u, _ = url.Parse(cli.BuildURL(MediaURLPath{"unstable", "fi.mau.msc2246", "upload", data.UnstableMXC.Homeserver, data.UnstableMXC.FileID})) method = http.MethodPut } if len(data.FileName) > 0 { @@ -1228,7 +1228,7 @@ func (cli *Client) UploadMedia(data ReqUploadMedia) (*RespMediaUpload, error) { // // See https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3preview_url func (cli *Client) GetURLPreview(url string) (*RespPreviewURL, error) { - reqURL := cli.BuildBaseURLWithQuery(URLPath{"_matrix", "media", "r0", "preview_url"}, map[string]string{ + reqURL := cli.BuildURLWithQuery(MediaURLPath{"v3", "preview_url"}, map[string]string{ "url": url, }) var output RespPreviewURL @@ -1236,12 +1236,12 @@ func (cli *Client) GetURLPreview(url string) (*RespPreviewURL, error) { return &output, err } -// JoinedMembers returns a map of joined room members. See https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms +// JoinedMembers returns a map of joined room members. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidjoined_members // // In general, usage of this API is discouraged in favour of /sync, as calling this API can race with incoming membership changes. // This API is primarily designed for application services which may want to efficiently look up joined members in a room. func (cli *Client) JoinedMembers(roomID id.RoomID) (resp *RespJoinedMembers, err error) { - u := cli.BuildURL("rooms", roomID, "joined_members") + u := cli.BuildClientURL("v3", "rooms", roomID, "joined_members") _, err = cli.MakeRequest("GET", u, nil, &resp) return } @@ -1261,24 +1261,24 @@ func (cli *Client) Members(roomID id.RoomID, req ...ReqMembers) (resp *RespMembe if len(extra.NotMembership) > 0 { query["not_membership"] = string(extra.NotMembership) } - u := cli.BuildURLWithQuery(URLPath{"rooms", roomID, "members"}, query) + u := cli.BuildURLWithQuery(ClientURLPath{"v3", "rooms", roomID, "members"}, query) _, err = cli.MakeRequest("GET", u, nil, &resp) return } -// JoinedRooms returns a list of rooms which the client is joined to. See https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms +// JoinedRooms returns a list of rooms which the client is joined to. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3joined_rooms // // In general, usage of this API is discouraged in favour of /sync, as calling this API can race with incoming membership changes. // This API is primarily designed for application services which may want to efficiently look up joined rooms. func (cli *Client) JoinedRooms() (resp *RespJoinedRooms, err error) { - u := cli.BuildURL("joined_rooms") + u := cli.BuildClientURL("v3", "joined_rooms") _, err = cli.MakeRequest("GET", u, nil, &resp) return } // Messages returns a list of message and state events for a room. It uses // pagination query parameters to paginate history in the room. -// See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages +// See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidmessages func (cli *Client) Messages(roomID id.RoomID, from, to string, dir rune, filter *FilterPart, limit int) (resp *RespMessages, err error) { query := map[string]string{ "from": from, @@ -1298,7 +1298,7 @@ func (cli *Client) Messages(roomID id.RoomID, from, to string, dir rune, filter query["limit"] = strconv.Itoa(limit) } - urlPath := cli.BuildURLWithQuery(URLPath{"rooms", roomID, "messages"}, query) + urlPath := cli.BuildURLWithQuery(ClientURLPath{"v3", "rooms", roomID, "messages"}, query) _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } @@ -1306,7 +1306,7 @@ func (cli *Client) Messages(roomID id.RoomID, from, to string, dir rune, filter // Context returns a number of events that happened just before and after the // specified event. It use pagination query parameters to paginate history in // the room. -// See https://spec.matrix.org/v1.1/client-server-api/#get_matrixclientv3roomsroomidcontexteventid +// See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidcontexteventid func (cli *Client) Context(roomID id.RoomID, eventID id.EventID, filter *FilterPart, limit int) (resp *RespContext, err error) { query := map[string]string{} if filter != nil { @@ -1320,13 +1320,13 @@ func (cli *Client) Context(roomID id.RoomID, eventID id.EventID, filter *FilterP query["limit"] = strconv.Itoa(limit) } - urlPath := cli.BuildURLWithQuery(URLPath{"rooms", roomID, "context", eventID}, query) + urlPath := cli.BuildURLWithQuery(ClientURLPath{"v3", "rooms", roomID, "context", eventID}, query) _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } func (cli *Client) GetEvent(roomID id.RoomID, eventID id.EventID) (resp *event.Event, err error) { - urlPath := cli.BuildURL("rooms", roomID, "event", eventID) + urlPath := cli.BuildClientURL("v3", "rooms", roomID, "event", eventID) _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } @@ -1338,13 +1338,13 @@ func (cli *Client) MarkRead(roomID id.RoomID, eventID id.EventID) (err error) { // MarkReadWithContent sends a read receipt including custom data. // N.B. This is not (yet) a part of the spec, normal servers will drop any extra content. func (cli *Client) MarkReadWithContent(roomID id.RoomID, eventID id.EventID, content interface{}) (err error) { - urlPath := cli.BuildURL("rooms", roomID, "receipt", "m.read", eventID) + urlPath := cli.BuildClientURL("v3", "rooms", roomID, "receipt", "m.read", eventID) _, err = cli.MakeRequest("POST", urlPath, &content, nil) return } func (cli *Client) SetReadMarkers(roomID id.RoomID, content interface{}) (err error) { - urlPath := cli.BuildURL("rooms", roomID, "read_markers") + urlPath := cli.BuildClientURL("v3", "rooms", roomID, "read_markers") _, err = cli.MakeRequest("POST", urlPath, &content, nil) return } @@ -1358,7 +1358,7 @@ func (cli *Client) AddTag(roomID id.RoomID, tag string, order float64) error { } func (cli *Client) AddTagWithCustomData(roomID id.RoomID, tag string, data interface{}) (err error) { - urlPath := cli.BuildURL("user", cli.UserID, "rooms", roomID, "tags", tag) + urlPath := cli.BuildClientURL("v3", "user", cli.UserID, "rooms", roomID, "tags", tag) _, err = cli.MakeRequest("PUT", urlPath, data, nil) return } @@ -1369,13 +1369,13 @@ func (cli *Client) GetTags(roomID id.RoomID) (tags event.TagEventContent, err er } func (cli *Client) GetTagsWithCustomData(roomID id.RoomID, resp interface{}) (err error) { - urlPath := cli.BuildURL("user", cli.UserID, "rooms", roomID, "tags") + urlPath := cli.BuildClientURL("v3", "user", cli.UserID, "rooms", roomID, "tags") _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } func (cli *Client) RemoveTag(roomID id.RoomID, tag string) (err error) { - urlPath := cli.BuildURL("user", cli.UserID, "rooms", roomID, "tags", tag) + urlPath := cli.BuildClientURL("v3", "user", cli.UserID, "rooms", roomID, "tags", tag) _, err = cli.MakeRequest("DELETE", urlPath, nil, nil) return } @@ -1388,57 +1388,57 @@ func (cli *Client) SetTags(roomID id.RoomID, tags event.Tags) (err error) { } // TurnServer returns turn server details and credentials for the client to use when initiating calls. -// See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver +// See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3voipturnserver func (cli *Client) TurnServer() (resp *RespTurnServer, err error) { - urlPath := cli.BuildURL("voip", "turnServer") + urlPath := cli.BuildClientURL("v3", "voip", "turnServer") _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } func (cli *Client) CreateAlias(alias id.RoomAlias, roomID id.RoomID) (resp *RespAliasCreate, err error) { - urlPath := cli.BuildURL("directory", "room", alias) + urlPath := cli.BuildClientURL("v3", "directory", "room", alias) _, err = cli.MakeRequest("PUT", urlPath, &ReqAliasCreate{RoomID: roomID}, &resp) return } func (cli *Client) ResolveAlias(alias id.RoomAlias) (resp *RespAliasResolve, err error) { - urlPath := cli.BuildURL("directory", "room", alias) + urlPath := cli.BuildClientURL("v3", "directory", "room", alias) _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } func (cli *Client) DeleteAlias(alias id.RoomAlias) (resp *RespAliasDelete, err error) { - urlPath := cli.BuildURL("directory", "room", alias) + urlPath := cli.BuildClientURL("v3", "directory", "room", alias) _, err = cli.MakeRequest("DELETE", urlPath, nil, &resp) return } func (cli *Client) GetAliases(roomID id.RoomID) (resp *RespAliasList, err error) { - urlPath := cli.BuildURL("rooms", roomID, "aliases") + urlPath := cli.BuildClientURL("v3", "rooms", roomID, "aliases") _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } func (cli *Client) UploadKeys(req *ReqUploadKeys) (resp *RespUploadKeys, err error) { - urlPath := cli.BuildURL("keys", "upload") + urlPath := cli.BuildClientURL("v3", "keys", "upload") _, err = cli.MakeRequest("POST", urlPath, req, &resp) return } func (cli *Client) QueryKeys(req *ReqQueryKeys) (resp *RespQueryKeys, err error) { - urlPath := cli.BuildURL("keys", "query") + urlPath := cli.BuildClientURL("v3", "keys", "query") _, err = cli.MakeRequest("POST", urlPath, req, &resp) return } func (cli *Client) ClaimKeys(req *ReqClaimKeys) (resp *RespClaimKeys, err error) { - urlPath := cli.BuildURL("keys", "claim") + urlPath := cli.BuildClientURL("v3", "keys", "claim") _, err = cli.MakeRequest("POST", urlPath, req, &resp) return } func (cli *Client) GetKeyChanges(from, to string) (resp *RespKeyChanges, err error) { - urlPath := cli.BuildURLWithQuery(URLPath{"keys", "changes"}, map[string]string{ + urlPath := cli.BuildURLWithQuery(ClientURLPath{"v3", "keys", "changes"}, map[string]string{ "from": from, "to": to, }) @@ -1447,37 +1447,37 @@ func (cli *Client) GetKeyChanges(from, to string) (resp *RespKeyChanges, err err } func (cli *Client) SendToDevice(eventType event.Type, req *ReqSendToDevice) (resp *RespSendToDevice, err error) { - urlPath := cli.BuildURL("sendToDevice", eventType.String(), cli.TxnID()) + urlPath := cli.BuildClientURL("v3", "sendToDevice", eventType.String(), cli.TxnID()) _, err = cli.MakeRequest("PUT", urlPath, req, &resp) return } func (cli *Client) GetDevicesInfo() (resp *RespDevicesInfo, err error) { - urlPath := cli.BuildURL("devices") + urlPath := cli.BuildClientURL("v3", "devices") _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } func (cli *Client) GetDeviceInfo(deviceID id.DeviceID) (resp *RespDeviceInfo, err error) { - urlPath := cli.BuildURL("devices", deviceID) + urlPath := cli.BuildClientURL("v3", "devices", deviceID) _, err = cli.MakeRequest("GET", urlPath, nil, &resp) return } func (cli *Client) SetDeviceInfo(deviceID id.DeviceID, req *ReqDeviceInfo) error { - urlPath := cli.BuildURL("devices", deviceID) + urlPath := cli.BuildClientURL("v3", "devices", deviceID) _, err := cli.MakeRequest("PUT", urlPath, req, nil) return err } func (cli *Client) DeleteDevice(deviceID id.DeviceID, req *ReqDeleteDevice) error { - urlPath := cli.BuildURL("devices", deviceID) + urlPath := cli.BuildClientURL("v3", "devices", deviceID) _, err := cli.MakeRequest("DELETE", urlPath, req, nil) return err } func (cli *Client) DeleteDevices(req *ReqDeleteDevices) error { - urlPath := cli.BuildURL("delete_devices") + urlPath := cli.BuildClientURL("v3", "delete_devices") _, err := cli.MakeRequest("DELETE", urlPath, req, nil) return err } @@ -1490,7 +1490,7 @@ type UIACallback = func(*RespUserInteractive) interface{} func (cli *Client) UploadCrossSigningKeys(keys *UploadCrossSigningKeysReq, uiaCallback UIACallback) error { content, err := cli.MakeFullRequest(FullRequest{ Method: http.MethodPost, - URL: cli.BuildBaseURL("_matrix", "client", "unstable", "keys", "device_signing", "upload"), + URL: cli.BuildClientURL("v3", "keys", "device_signing", "upload"), RequestJSON: keys, SensitiveContent: keys.Auth != nil, }) @@ -1510,7 +1510,7 @@ func (cli *Client) UploadCrossSigningKeys(keys *UploadCrossSigningKeysReq, uiaCa } func (cli *Client) UploadSignatures(req *ReqUploadSignatures) (resp *RespUploadSignatures, err error) { - urlPath := cli.BuildBaseURL("_matrix", "client", "unstable", "keys", "signatures", "upload") + urlPath := cli.BuildClientURL("v3", "keys", "signatures", "upload") _, err = cli.MakeRequest("POST", urlPath, req, &resp) return } @@ -1522,7 +1522,7 @@ func (cli *Client) GetPushRules() (*pushrules.PushRuleset, error) { // GetScopedPushRules returns the push notification rules for the given scope. func (cli *Client) GetScopedPushRules(scope string) (resp *pushrules.PushRuleset, err error) { - u, _ := url.Parse(cli.BuildURL("pushrules", scope)) + u, _ := url.Parse(cli.BuildClientURL("v3", "pushrules", scope)) // client.BuildURL returns the URL without a trailing slash, but the pushrules endpoint requires the slash. u.Path += "/" _, err = cli.MakeRequest("GET", u.String(), nil, &resp) @@ -1530,7 +1530,7 @@ func (cli *Client) GetScopedPushRules(scope string) (resp *pushrules.PushRuleset } func (cli *Client) GetPushRule(scope string, kind pushrules.PushRuleType, ruleID string) (resp *pushrules.PushRule, err error) { - urlPath := cli.BuildURL("pushrules", scope, kind, ruleID) + urlPath := cli.BuildClientURL("v3", "pushrules", scope, kind, ruleID) _, err = cli.MakeRequest("GET", urlPath, nil, &resp) if resp != nil { resp.Type = kind @@ -1539,7 +1539,7 @@ func (cli *Client) GetPushRule(scope string, kind pushrules.PushRuleType, ruleID } func (cli *Client) DeletePushRule(scope string, kind pushrules.PushRuleType, ruleID string) error { - urlPath := cli.BuildURL("pushrules", scope, kind, ruleID) + urlPath := cli.BuildClientURL("v3", "pushrules", scope, kind, ruleID) _, err := cli.MakeRequest("DELETE", urlPath, nil, nil) return err } @@ -1552,7 +1552,7 @@ func (cli *Client) PutPushRule(scope string, kind pushrules.PushRuleType, ruleID if len(req.Before) > 0 { query["before"] = req.Before } - urlPath := cli.BuildURLWithQuery(URLPath{"pushrules", scope, kind, ruleID}, query) + urlPath := cli.BuildURLWithQuery(ClientURLPath{"v3", "pushrules", scope, kind, ruleID}, query) _, err := cli.MakeRequest("PUT", urlPath, req, nil) return err } @@ -1561,14 +1561,14 @@ func (cli *Client) PutPushRule(scope string, kind pushrules.PushRuleType, ruleID // // See https://github.com/matrix-org/matrix-doc/pull/2716 for more info. func (cli *Client) BatchSend(roomID id.RoomID, req *ReqBatchSend) (resp *RespBatchSend, err error) { - path := URLPath{"_matrix", "client", "unstable", "org.matrix.msc2716", "rooms", roomID, "batch_send"} + path := ClientURLPath{"unstable", "org.matrix.msc2716", "rooms", roomID, "batch_send"} query := map[string]string{ "prev_event_id": req.PrevEventID.String(), } if len(req.BatchID) > 0 { query["batch_id"] = req.BatchID.String() } - _, err = cli.MakeRequest("POST", cli.BuildBaseURLWithQuery(path, query), req, &resp) + _, err = cli.MakeRequest("POST", cli.BuildURLWithQuery(path, query), req, &resp) return } @@ -1590,7 +1590,6 @@ func NewClient(homeserverURL string, userID id.UserID, accessToken string) (*Cli HomeserverURL: hsURL, UserID: userID, Client: &http.Client{Timeout: 180 * time.Second}, - Prefix: URLPath{"_matrix", "client", "r0"}, Syncer: NewDefaultSyncer(), Logger: stubLogger, // By default, use an in-memory store which will never save filter ids / next batch tokens to disk. diff --git a/crypto/keyexport.go b/crypto/keyexport.go index c1a2f02..a94d223 100644 --- a/crypto/keyexport.go +++ b/crypto/keyexport.go @@ -148,7 +148,7 @@ func formatKeyExportData(data []byte) []byte { } // ExportKeys exports the given Megolm sessions with the format specified in the Matrix spec. -// See https://matrix.org/docs/spec/client_server/r0.6.1#key-exports +// See https://spec.matrix.org/v1.2/client-server-api/#key-exports func ExportKeys(passphrase string, sessions []*InboundGroupSession) ([]byte, error) { // Make all the keys necessary for exporting encryptionKey, hashKey, salt, iv := makeExportKeys(passphrase) diff --git a/crypto/keyimport.go b/crypto/keyimport.go index 4144f07..6069897 100644 --- a/crypto/keyimport.go +++ b/crypto/keyimport.go @@ -34,7 +34,7 @@ var ( var exportPrefixBytes, exportSuffixBytes = []byte(exportPrefix), []byte(exportSuffix) func decodeKeyExport(data []byte) ([]byte, error) { - // If there valid prefix and suffix aren't there, it's probably not a Matrix key export + // If the valid prefix and suffix aren't there, it's probably not a Matrix key export if !bytes.HasPrefix(data, exportPrefixBytes) { return nil, ErrMissingExportPrefix } else if !bytes.HasSuffix(data, exportSuffixBytes) { @@ -123,7 +123,7 @@ func (mach *OlmMachine) importExportedRoomKey(session ExportedSession) (bool, er } // ImportKeys imports data that was exported with the format specified in the Matrix spec. -// See See https://matrix.org/docs/spec/client_server/r0.6.1#key-exports +// See https://spec.matrix.org/v1.2/client-server-api/#key-exports func (mach *OlmMachine) ImportKeys(passphrase string, data []byte) (int, int, error) { exportData, err := decodeKeyExport(data) if err != nil { diff --git a/error.go b/error.go index 52234d0..a68c5ca 100644 --- a/error.go +++ b/error.go @@ -101,7 +101,7 @@ func (e HTTPError) Unwrap() error { } // RespError is the standard JSON error response from Homeservers. It also implements the Golang "error" interface. -// See http://matrix.org/docs/spec/client_server/r0.6.1.html#api-standards +// See https://spec.matrix.org/v1.2/client-server-api/#api-standards type RespError struct { ErrCode string Err string diff --git a/event/accountdata.go b/event/accountdata.go index 7883e67..6637fcf 100644 --- a/event/accountdata.go +++ b/event/accountdata.go @@ -13,7 +13,7 @@ import ( ) // TagEventContent represents the content of a m.tag room account data event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-tag +// https://spec.matrix.org/v1.2/client-server-api/#mtag type TagEventContent struct { Tags Tags `json:"tags"` } @@ -25,17 +25,17 @@ type Tag struct { } // DirectChatsEventContent represents the content of a m.direct account data event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-direct +// https://spec.matrix.org/v1.2/client-server-api/#mdirect type DirectChatsEventContent map[id.UserID][]id.RoomID // FullyReadEventContent represents the content of a m.fully_read account data event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-fully-read +// https://spec.matrix.org/v1.2/client-server-api/#mfully_read type FullyReadEventContent struct { EventID id.EventID `json:"event_id"` } // IgnoredUserListEventContent represents the content of a m.ignored_user_list account data event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-ignored-user-list +// https://spec.matrix.org/v1.2/client-server-api/#mignored_user_list type IgnoredUserListEventContent struct { IgnoredUsers map[id.UserID]IgnoredUser `json:"ignored_users"` } diff --git a/event/encryption.go b/event/encryption.go index 197f973..43aa7ea 100644 --- a/event/encryption.go +++ b/event/encryption.go @@ -13,7 +13,7 @@ import ( ) // EncryptionEventContent represents the content of a m.room.encryption state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-encryption +// https://spec.matrix.org/v1.2/client-server-api/#mroomencryption type EncryptionEventContent struct { // The encryption algorithm to be used to encrypt messages sent in this room. Must be 'm.megolm.v1.aes-sha2'. Algorithm id.Algorithm `json:"algorithm"` @@ -24,10 +24,12 @@ type EncryptionEventContent struct { } // EncryptedEventContent represents the content of a m.room.encrypted message event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-encrypted +// https://spec.matrix.org/v1.2/client-server-api/#mroomencrypted +// +// Note that sender_key and device_id are deprecated in Megolm events as of https://github.com/matrix-org/matrix-spec-proposals/pull/3700 type EncryptedEventContent struct { Algorithm id.Algorithm `json:"algorithm"` - SenderKey id.SenderKey `json:"sender_key"` + SenderKey id.SenderKey `json:"sender_key,omitempty"` DeviceID id.DeviceID `json:"device_id,omitempty"` // Only present for Megolm events SessionID id.SessionID `json:"session_id,omitempty"` // Only present for Megolm events Ciphertext json.RawMessage `json:"ciphertext"` @@ -81,7 +83,7 @@ func (content *EncryptedEventContent) MarshalJSON() ([]byte, error) { } // RoomKeyEventContent represents the content of a m.room_key to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-key +// https://spec.matrix.org/v1.2/client-server-api/#mroom_key type RoomKeyEventContent struct { Algorithm id.Algorithm `json:"algorithm"` RoomID id.RoomID `json:"room_id"` @@ -90,7 +92,7 @@ type RoomKeyEventContent struct { } // ForwardedRoomKeyEventContent represents the content of a m.forwarded_room_key to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-forwarded-room-key +// https://spec.matrix.org/v1.2/client-server-api/#mforwarded_room_key type ForwardedRoomKeyEventContent struct { RoomKeyEventContent SenderKey id.SenderKey `json:"sender_key"` @@ -106,7 +108,7 @@ const ( ) // RoomKeyRequestEventContent represents the content of a m.room_key_request to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-key-request +// https://spec.matrix.org/v1.2/client-server-api/#mroom_key_request type RoomKeyRequestEventContent struct { Body RequestedKeyInfo `json:"body"` Action KeyRequestAction `json:"action"` diff --git a/event/ephemeral.go b/event/ephemeral.go index 186cb16..7f1007b 100644 --- a/event/ephemeral.go +++ b/event/ephemeral.go @@ -12,14 +12,14 @@ import ( "maunium.net/go/mautrix/id" ) -// TagEventContent represents the content of a m.typing ephemeral event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-typing +// TypingEventContent represents the content of a m.typing ephemeral event. +// https://spec.matrix.org/v1.2/client-server-api/#mtyping type TypingEventContent struct { UserIDs []id.UserID `json:"user_ids"` } // ReceiptEventContent represents the content of a m.receipt ephemeral event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-receipt +// https://spec.matrix.org/v1.2/client-server-api/#mreceipt type ReceiptEventContent map[id.EventID]Receipts type Receipts struct { @@ -69,7 +69,7 @@ const ( ) // PresenceEventContent represents the content of a m.presence ephemeral event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-presence +// https://spec.matrix.org/v1.2/client-server-api/#mpresence type PresenceEventContent struct { Presence Presence `json:"presence"` Displayname string `json:"displayname,omitempty"` diff --git a/event/member.go b/event/member.go index 9e4e525..ebafdcb 100644 --- a/event/member.go +++ b/event/member.go @@ -33,7 +33,7 @@ const ( ) // MemberEventContent represents the content of a m.room.member state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-member +// https://spec.matrix.org/v1.2/client-server-api/#mroommember type MemberEventContent struct { Membership Membership `json:"membership"` AvatarURL id.ContentURIString `json:"avatar_url,omitempty"` diff --git a/event/message.go b/event/message.go index 14de96f..5d75a84 100644 --- a/event/message.go +++ b/event/message.go @@ -18,7 +18,7 @@ import ( ) // MessageType is the sub-type of a m.room.message event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-message-msgtypes +// https://spec.matrix.org/v1.2/client-server-api/#mroommessage-msgtypes type MessageType string // Msgtypes @@ -36,7 +36,7 @@ const ( ) // Format specifies the format of the formatted_body in m.room.message events. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-message-msgtypes +// https://spec.matrix.org/v1.2/client-server-api/#mroommessage-msgtypes type Format string // Message formats @@ -49,7 +49,7 @@ const ( // The redacted event ID is still at the top level, but will move in a future room version. // See https://github.com/matrix-org/matrix-doc/pull/2244 and https://github.com/matrix-org/matrix-doc/pull/2174 // -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-redaction +// https://spec.matrix.org/v1.2/client-server-api/#mroomredaction type RedactionEventContent struct { Reason string `json:"reason,omitempty"` } @@ -72,12 +72,12 @@ func (content *ReactionEventContent) SetRelatesTo(rel *RelatesTo) { content.RelatesTo = *rel } -// MssageEventContent represents the content of a m.room.message event. +// MessageEventContent represents the content of a m.room.message event. // // It is also used to represent m.sticker events, as they are equivalent to m.room.message // with the exception of the msgtype field. // -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-message +// https://spec.matrix.org/v1.2/client-server-api/#mroommessage type MessageEventContent struct { // Base m.room.message fields MsgType MessageType `json:"msgtype,omitempty"` diff --git a/event/powerlevels.go b/event/powerlevels.go index 3c4576c..85197a5 100644 --- a/event/powerlevels.go +++ b/event/powerlevels.go @@ -13,13 +13,13 @@ import ( ) // PowerLevelsEventContent represents the content of a m.room.power_levels state event content. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-power-levels +// https://spec.matrix.org/v1.2/client-server-api/#mroompower_levels type PowerLevelsEventContent struct { - usersLock sync.RWMutex `json:"-"` + usersLock sync.RWMutex Users map[id.UserID]int `json:"users,omitempty"` UsersDefault int `json:"users_default,omitempty"` - eventsLock sync.RWMutex `json:"-"` + eventsLock sync.RWMutex Events map[string]int `json:"events,omitempty"` EventsDefault int `json:"events_default,omitempty"` diff --git a/event/state.go b/event/state.go index e62b592..c726364 100644 --- a/event/state.go +++ b/event/state.go @@ -11,26 +11,27 @@ import ( ) // CanonicalAliasEventContent represents the content of a m.room.canonical_alias state event. -// https://matrix.org/docs/spec/client_server/r0.6.1#m-room-canonical-alias +// https://spec.matrix.org/v1.2/client-server-api/#mroomcanonical_alias type CanonicalAliasEventContent struct { Alias id.RoomAlias `json:"alias"` AltAliases []id.RoomAlias `json:"alt_aliases,omitempty"` } // RoomNameEventContent represents the content of a m.room.name state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-name +// https://spec.matrix.org/v1.2/client-server-api/#mroomname type RoomNameEventContent struct { Name string `json:"name"` } // RoomAvatarEventContent represents the content of a m.room.avatar state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-avatar +// https://spec.matrix.org/v1.2/client-server-api/#mroomavatar type RoomAvatarEventContent struct { - URL id.ContentURI `json:"url"` + URL id.ContentURI `json:"url"` + Info *FileInfo `json:"info,omitempty"` } // ServerACLEventContent represents the content of a m.room.server_acl state event. -// https://spec.matrix.org/v1.1/client-server-api/#server-access-control-lists-acls-for-rooms +// https://spec.matrix.org/v1.2/client-server-api/#server-access-control-lists-acls-for-rooms type ServerACLEventContent struct { Allow []string `json:"allow,omitempty"` AllowIPLiterals bool `json:"allow_ip_literals"` @@ -38,20 +39,20 @@ type ServerACLEventContent struct { } // TopicEventContent represents the content of a m.room.topic state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-topic +// https://spec.matrix.org/v1.2/client-server-api/#mroomtopic type TopicEventContent struct { Topic string `json:"topic"` } // TombstoneEventContent represents the content of a m.room.tombstone state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-tombstone +// https://spec.matrix.org/v1.2/client-server-api/#mroomtombstone type TombstoneEventContent struct { Body string `json:"body"` ReplacementRoom id.RoomID `json:"replacement_room"` } // CreateEventContent represents the content of a m.room.create state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-create +// https://spec.matrix.org/v1.2/client-server-api/#mroomcreate type CreateEventContent struct { Type RoomType `json:"type,omitempty"` Creator id.UserID `json:"creator,omitempty"` @@ -64,30 +65,43 @@ type CreateEventContent struct { } // JoinRule specifies how open a room is to new members. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-join-rules +// https://spec.matrix.org/v1.2/client-server-api/#mroomjoin_rules type JoinRule string const ( - JoinRulePublic JoinRule = "public" - JoinRuleKnock JoinRule = "knock" - JoinRuleInvite JoinRule = "invite" - JoinRulePrivate JoinRule = "private" + JoinRulePublic JoinRule = "public" + JoinRuleKnock JoinRule = "knock" + JoinRuleInvite JoinRule = "invite" + JoinRuleRestricted JoinRule = "restricted" + JoinRulePrivate JoinRule = "private" ) // JoinRulesEventContent represents the content of a m.room.join_rules state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-join-rules +// https://spec.matrix.org/v1.2/client-server-api/#mroomjoin_rules type JoinRulesEventContent struct { - JoinRule JoinRule `json:"join_rule"` + JoinRule JoinRule `json:"join_rule"` + Allow []JoinRuleAllow `json:"allow,omitempty"` +} + +type JoinRuleAllowType string + +const ( + JoinRuleAllowRoomMembership JoinRuleAllowType = "m.room_membership" +) + +type JoinRuleAllow struct { + RoomID id.RoomID `json:"room_id"` + Type JoinRuleAllowType `json:"type"` } // PinnedEventsEventContent represents the content of a m.room.pinned_events state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-pinned-events +// https://spec.matrix.org/v1.2/client-server-api/#mroompinned_events type PinnedEventsEventContent struct { Pinned []id.EventID `json:"pinned"` } // HistoryVisibility specifies who can see new messages. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-history-visibility +// https://spec.matrix.org/v1.2/client-server-api/#mroomhistory_visibility type HistoryVisibility string const ( @@ -98,13 +112,13 @@ const ( ) // HistoryVisibilityEventContent represents the content of a m.room.history_visibility state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-history-visibility +// https://spec.matrix.org/v1.2/client-server-api/#mroomhistory_visibility type HistoryVisibilityEventContent struct { HistoryVisibility HistoryVisibility `json:"history_visibility"` } // GuestAccess specifies whether or not guest accounts can join. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-guest-access +// https://spec.matrix.org/v1.2/client-server-api/#mroomguest_access type GuestAccess string const ( @@ -113,7 +127,7 @@ const ( ) // GuestAccessEventContent represents the content of a m.room.guest_access state event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-guest-access +// https://spec.matrix.org/v1.2/client-server-api/#mroomguest_access type GuestAccessEventContent struct { GuestAccess GuestAccess `json:"guest_access"` } @@ -146,7 +160,7 @@ type SpaceParentEventContent struct { } // ModPolicyContent represents the content of a m.room.rule.user, m.room.rule.room, and m.room.rule.server state event. -// https://spec.matrix.org/v1.1/client-server-api/#moderation-policy-lists +// https://spec.matrix.org/v1.2/client-server-api/#moderation-policy-lists type ModPolicyContent struct { Entity string `json:"entity"` Reason string `json:"reason"` diff --git a/event/verification.go b/event/verification.go index 800e7b1..8410904 100644 --- a/event/verification.go +++ b/event/verification.go @@ -15,7 +15,7 @@ type VerificationMethod string const VerificationMethodSAS VerificationMethod = "m.sas.v1" // VerificationRequestEventContent represents the content of a m.key.verification.request to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-key-verification-request +// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationrequest type VerificationRequestEventContent struct { // The device ID which is initiating the request. FromDevice id.DeviceID `json:"from_device"` @@ -63,7 +63,7 @@ const ( ) // VerificationStartEventContent represents the content of a m.key.verification.start to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-key-verification-start +// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationstartmsasv1 type VerificationStartEventContent struct { // The device ID which is initiating the process. FromDevice id.DeviceID `json:"from_device"` @@ -137,6 +137,7 @@ func (vsec *VerificationStartEventContent) SetRelatesTo(rel *RelatesTo) { } // VerificationReadyEventContent represents the content of a m.key.verification.ready event. +// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationready type VerificationReadyEventContent struct { // The device ID which accepted the process. FromDevice id.DeviceID `json:"from_device"` @@ -164,7 +165,7 @@ func (vrec *VerificationReadyEventContent) SetRelatesTo(rel *RelatesTo) { } // VerificationAcceptEventContent represents the content of a m.key.verification.accept to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-key-verification-accept +// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationaccept type VerificationAcceptEventContent struct { // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message. TransactionID string `json:"transaction_id,omitempty"` @@ -202,7 +203,7 @@ func (vaec *VerificationAcceptEventContent) SetRelatesTo(rel *RelatesTo) { } // VerificationKeyEventContent represents the content of a m.key.verification.key to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-key-verification-key +// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationkey type VerificationKeyEventContent struct { // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message. TransactionID string `json:"transaction_id,omitempty"` @@ -230,7 +231,7 @@ func (vkec *VerificationKeyEventContent) SetRelatesTo(rel *RelatesTo) { } // VerificationMacEventContent represents the content of a m.key.verification.mac to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-key-verification-mac +// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationmac type VerificationMacEventContent struct { // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message. TransactionID string `json:"transaction_id,omitempty"` @@ -276,7 +277,7 @@ const ( ) // VerificationCancelEventContent represents the content of a m.key.verification.cancel to_device event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-key-verification-cancel +// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationcancel type VerificationCancelEventContent struct { // The opaque identifier for the verification process/request. TransactionID string `json:"transaction_id,omitempty"` diff --git a/filter.go b/filter.go index 71235f2..fd6de7a 100644 --- a/filter.go +++ b/filter.go @@ -16,8 +16,8 @@ const ( EventFormatFederation EventFormat = "federation" ) -//Filter is used by clients to specify how the server should filter responses to e.g. sync requests -//Specified by: https://matrix.org/docs/spec/client_server/r0.6.0.html#filtering +// Filter is used by clients to specify how the server should filter responses to e.g. sync requests +// Specified by: https://spec.matrix.org/v1.2/client-server-api/#filtering type Filter struct { AccountData FilterPart `json:"account_data,omitempty"` EventFields []string `json:"event_fields,omitempty"` diff --git a/format/doc.go b/format/doc.go index 03a72d1..84a10b6 100644 --- a/format/doc.go +++ b/format/doc.go @@ -1,5 +1,5 @@ // Package format contains utilities for working with Matrix HTML, specifically // methods to parse Markdown into HTML and to parse Matrix HTML into text or markdown. // -// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-message-msgtypes +// https://spec.matrix.org/v1.2/client-server-api/#mroommessage-msgtypes package format diff --git a/id/contenturi.go b/id/contenturi.go index 0a6c155..b5934c9 100644 --- a/id/contenturi.go +++ b/id/contenturi.go @@ -34,7 +34,7 @@ func (uriString ContentURIString) ParseOrIgnore() ContentURI { } // ContentURI represents a Matrix content URI. -// https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris +// https://spec.matrix.org/v1.2/client-server-api/#matrix-content-mxc-uris type ContentURI struct { Homeserver string FileID string diff --git a/id/crypto.go b/id/crypto.go index 5683cc4..6adb573 100644 --- a/id/crypto.go +++ b/id/crypto.go @@ -20,7 +20,7 @@ const ( ) // Algorithm is a Matrix message encryption algorithm. -// https://matrix.org/docs/spec/client_server/r0.6.0#messaging-algorithm-names +// https://spec.matrix.org/v1.2/client-server-api/#messaging-algorithm-names type Algorithm string const ( diff --git a/pushrules/condition.go b/pushrules/condition.go index f11d2b8..49f88f4 100644 --- a/pushrules/condition.go +++ b/pushrules/condition.go @@ -25,7 +25,7 @@ type Room interface { // PushCondKind is the type of a push condition. type PushCondKind string -// The allowed push condition kinds as specified in section 11.12.1.4.3 of r0.3.0 of the Client-Server API. +// The allowed push condition kinds as specified in https://spec.matrix.org/v1.2/client-server-api/#conditions-1 const ( KindEventMatch PushCondKind = "event_match" KindContainsDisplayName PushCondKind = "contains_display_name" diff --git a/pushrules/pushrules.go b/pushrules/pushrules.go index cb7d2f6..7944299 100644 --- a/pushrules/pushrules.go +++ b/pushrules/pushrules.go @@ -15,7 +15,7 @@ import ( ) // EventContent represents the content of a m.push_rules account data event. -// https://matrix.org/docs/spec/client_server/r0.6.0#m-push-rules +// https://spec.matrix.org/v1.2/client-server-api/#mpush_rules type EventContent struct { Ruleset *PushRuleset `json:"global"` } diff --git a/requests.go b/requests.go index b630642..a8df8e0 100644 --- a/requests.go +++ b/requests.go @@ -32,7 +32,7 @@ const ( IdentifierTypePhone = "m.id.phone" ) -// ReqRegister is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-register +// ReqRegister is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3register type ReqRegister struct { Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` @@ -42,7 +42,7 @@ type ReqRegister struct { Auth interface{} `json:"auth,omitempty"` // Type for registration, only used for appservice user registrations - // https://matrix.org/docs/spec/application_service/r0.1.2#server-admin-style-permissions + // https://spec.matrix.org/v1.2/application-service-api/#server-admin-style-permissions Type AuthType `json:"type,omitempty"` } @@ -63,7 +63,7 @@ type UserIdentifier struct { Phone string `json:"phone,omitempty"` } -// ReqLogin is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login +// ReqLogin is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3login type ReqLogin struct { Type AuthType `json:"type"` Identifier UserIdentifier `json:"identifier"` @@ -89,7 +89,7 @@ type ReqUIAuthLogin struct { Password string `json:"password"` } -// ReqCreateRoom is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom +// ReqCreateRoom is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3createroom type ReqCreateRoom struct { Visibility string `json:"visibility,omitempty"` RoomAliasName string `json:"room_alias_name,omitempty"` @@ -105,7 +105,7 @@ type ReqCreateRoom struct { PowerLevelOverride *event.PowerLevelsEventContent `json:"power_level_content_override,omitempty"` } -// ReqRedact is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid +// ReqRedact is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidredacteventidtxnid type ReqRedact struct { Reason string TxnID string @@ -118,8 +118,8 @@ type ReqMembers struct { NotMembership event.Membership `json:"not_membership,omitempty"` } -// ReqInvite3PID is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#id57 -// It is also a JSON object used in https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom +// ReqInvite3PID is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite-1 +// It is also a JSON object used in https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3createroom type ReqInvite3PID struct { IDServer string `json:"id_server"` Medium string `json:"medium"` @@ -130,31 +130,31 @@ type ReqLeave struct { Reason string `json:"reason,omitempty"` } -// ReqInviteUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite +// ReqInviteUser is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite type ReqInviteUser struct { Reason string `json:"reason,omitempty"` UserID id.UserID `json:"user_id"` } -// ReqKickUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick +// ReqKickUser is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidkick type ReqKickUser struct { Reason string `json:"reason,omitempty"` UserID id.UserID `json:"user_id"` } -// ReqBanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban +// ReqBanUser is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidban type ReqBanUser struct { Reason string `json:"reason,omitempty"` UserID id.UserID `json:"user_id"` } -// ReqUnbanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban +// ReqUnbanUser is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidunban type ReqUnbanUser struct { Reason string `json:"reason,omitempty"` UserID id.UserID `json:"user_id"` } -// ReqTyping is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid +// ReqTyping is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidtypinguserid type ReqTyping struct { Typing bool `json:"typing"` Timeout int64 `json:"timeout,omitempty"` @@ -287,17 +287,17 @@ type ReqSendToDevice struct { Messages map[id.UserID]map[id.DeviceID]*event.Content `json:"messages"` } -// ReqDeviceInfo is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-devices-deviceid +// ReqDeviceInfo is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3devicesdeviceid type ReqDeviceInfo struct { DisplayName string `json:"display_name,omitempty"` } -// ReqDeleteDevice is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#delete-matrix-client-r0-devices-deviceid +// ReqDeleteDevice is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#delete_matrixclientv3devicesdeviceid type ReqDeleteDevice struct { Auth interface{} `json:"auth,omitempty"` } -// ReqDeleteDevices is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-delete-devices +// ReqDeleteDevices is the JSON request for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3delete_devices type ReqDeleteDevices struct { Devices []id.DeviceID `json:"devices"` Auth interface{} `json:"auth,omitempty"` diff --git a/responses.go b/responses.go index 05a4480..ea812d5 100644 --- a/responses.go +++ b/responses.go @@ -5,51 +5,50 @@ import ( "maunium.net/go/mautrix/id" ) -// RespWhoami is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-account-whoami +// RespWhoami is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3accountwhoami type RespWhoami struct { - UserID id.UserID `json:"user_id"` - // N.B. This field is not in the spec yet, it's expected to land in r0.6.2 or r0.7.0 + UserID id.UserID `json:"user_id"` DeviceID id.DeviceID `json:"device_id"` } -// RespCreateFilter is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter +// RespCreateFilter is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3useruseridfilter type RespCreateFilter struct { FilterID string `json:"filter_id"` } -// RespVersions is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.1.html#get-matrix-client-versions +// RespVersions is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientversions type RespVersions struct { Versions []string `json:"versions"` UnstableFeatures map[string]bool `json:"unstable_features"` } -// RespJoinRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join +// RespJoinRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidjoin type RespJoinRoom struct { RoomID id.RoomID `json:"room_id"` } -// RespLeaveRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave +// RespLeaveRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidleave type RespLeaveRoom struct{} -// RespForgetRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget +// RespForgetRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidforget type RespForgetRoom struct{} -// RespInviteUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite +// RespInviteUser is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite type RespInviteUser struct{} -// RespKickUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick +// RespKickUser is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidkick type RespKickUser struct{} -// RespBanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban +// RespBanUser is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidban type RespBanUser struct{} -// RespUnbanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban +// RespUnbanUser is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidunban type RespUnbanUser struct{} -// RespTyping is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid +// RespTyping is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidtypinguserid type RespTyping struct{} -// RespPresence is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-presence-userid-status +// RespPresence is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3presenceuseridstatus type RespPresence struct { Presence event.Presence `json:"presence"` LastActiveAgo int `json:"last_active_ago"` @@ -57,12 +56,12 @@ type RespPresence struct { CurrentlyActive bool `json:"currently_active"` } -// RespJoinedRooms is the JSON response for https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms +// RespJoinedRooms is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3joined_rooms type RespJoinedRooms struct { JoinedRooms []id.RoomID `json:"joined_rooms"` } -// RespJoinedMembers is the JSON response for https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms +// RespJoinedMembers is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidjoined_members type RespJoinedMembers struct { Joined map[id.UserID]struct { DisplayName *string `json:"display_name"` @@ -70,7 +69,7 @@ type RespJoinedMembers struct { } `json:"joined"` } -// RespMessages is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages +// RespMessages is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidmessages type RespMessages struct { Start string `json:"start"` Chunk []*event.Event `json:"chunk"` @@ -78,7 +77,7 @@ type RespMessages struct { End string `json:"end"` } -// RespContext is the JSON response for https://spec.matrix.org/v1.1/client-server-api/#get_matrixclientv3roomsroomidcontexteventid +// RespContext is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidcontexteventid type RespContext struct { End string `json:"end"` Event *event.Event `json:"event"` @@ -88,12 +87,12 @@ type RespContext struct { State []*event.Event `json:"state"` } -// RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid +// RespSendEvent is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid type RespSendEvent struct { EventID id.EventID `json:"event_id"` } -// RespMediaUpload is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload +// RespMediaUpload is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixmediav3upload type RespMediaUpload struct { ContentURI id.ContentURI `json:"content_uri"` } @@ -119,7 +118,7 @@ type RespPreviewURL struct { ImageType string `json:"og:image:type,omitempty"` } -// RespUserInteractive is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#user-interactive-authentication-api +// RespUserInteractive is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#user-interactive-authentication-api type RespUserInteractive struct { Flows []struct { Stages []AuthType `json:"stages"` @@ -142,12 +141,12 @@ func (r RespUserInteractive) HasSingleStageFlow(stageName AuthType) bool { return false } -// RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname +// RespUserDisplayName is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3profileuseriddisplayname type RespUserDisplayName struct { DisplayName string `json:"displayname"` } -// RespRegister is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register +// RespRegister is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3register type RespRegister struct { AccessToken string `json:"access_token"` DeviceID id.DeviceID `json:"device_id"` @@ -160,6 +159,7 @@ type LoginFlow struct { Type AuthType `json:"type"` } +// RespLoginFlows is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3login type RespLoginFlows struct { Flows []LoginFlow `json:"flows"` } @@ -179,7 +179,7 @@ func (rlf *RespLoginFlows) HasFlow(flowType ...AuthType) bool { return rlf.FirstFlowOfType(flowType...) != nil } -// RespLogin is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-login +// RespLogin is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3login type RespLogin struct { AccessToken string `json:"access_token"` DeviceID id.DeviceID `json:"device_id"` @@ -187,10 +187,10 @@ type RespLogin struct { WellKnown *ClientWellKnown `json:"well_known"` } -// RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout +// RespLogout is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3logout type RespLogout struct{} -// RespCreateRoom is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-createroom +// RespCreateRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3createroom type RespCreateRoom struct { RoomID id.RoomID `json:"room_id"` } @@ -205,7 +205,7 @@ type LazyLoadSummary struct { InvitedMemberCount *int `json:"m.invited_member_count,omitempty"` } -// RespSync is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-r0-sync +// RespSync is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3sync type RespSync struct { NextBatch string `json:"next_batch"` @@ -325,12 +325,12 @@ type RespKeyChanges struct { type RespSendToDevice struct{} -// RespDevicesInfo is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-devices +// RespDevicesInfo is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3devices type RespDevicesInfo struct { Devices []RespDeviceInfo `json:"devices"` } -// RespDeviceInfo is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-devices-deviceid +// RespDeviceInfo is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3devicesdeviceid type RespDeviceInfo struct { DeviceID id.DeviceID `json:"device_id"` DisplayName string `json:"display_name"` diff --git a/url.go b/url.go index 3de60c1..8d3678e 100644 --- a/url.go +++ b/url.go @@ -56,28 +56,42 @@ func BuildURL(baseURL *url.URL, path ...interface{}) *url.URL { } // BuildURL builds a URL with the Client's homeserver and appservice user ID set already. -func (cli *Client) BuildURL(urlPath ...interface{}) string { - return cli.BuildBaseURL(append(cli.Prefix, urlPath...)...) +func (cli *Client) BuildURL(urlPath PrefixableURLPath) string { + return cli.BuildURLWithQuery(urlPath, nil) } -// BuildBaseURL builds a URL with the Client's homeserver and appservice user ID set already. -// You must supply the prefix in the path. -func (cli *Client) BuildBaseURL(urlPath ...interface{}) string { - return cli.BuildBaseURLWithQuery(urlPath, nil) +// BuildClientURL builds a URL with the Client's homeserver and appservice user ID set already. +// This method also automatically prepends the client API prefix (/_matrix/client). +func (cli *Client) BuildClientURL(urlPath ...interface{}) string { + return cli.BuildURLWithQuery(ClientURLPath(urlPath), nil) } -type URLPath = []interface{} - -// BuildURLWithQuery builds a URL with query parameters in addition to the Client's -// homeserver and appservice user ID set already. -func (cli *Client) BuildURLWithQuery(urlPath URLPath, urlQuery map[string]string) string { - return cli.BuildBaseURLWithQuery(append(cli.Prefix, urlPath...), urlQuery) +type PrefixableURLPath interface { + FullPath() []interface{} } -// BuildBaseURLWithQuery builds a URL with query parameters in addition to the Client's homeserver -// and appservice user ID set already. You must supply the prefix in the path. -func (cli *Client) BuildBaseURLWithQuery(urlPath URLPath, urlQuery map[string]string) string { - hsURL := *BuildURL(cli.HomeserverURL, urlPath...) +type BaseURLPath []interface{} + +func (bup BaseURLPath) FullPath() []interface{} { + return bup +} + +type ClientURLPath []interface{} + +func (cup ClientURLPath) FullPath() []interface{} { + return append([]interface{}{"_matrix", "client"}, []interface{}(cup)...) +} + +type MediaURLPath []interface{} + +func (mup MediaURLPath) FullPath() []interface{} { + return append([]interface{}{"_matrix", "media"}, []interface{}(mup)...) +} + +// BuildURLWithQuery builds a URL with query parameters in addition to the Client's homeserver +// and appservice user ID set already. +func (cli *Client) BuildURLWithQuery(urlPath PrefixableURLPath, urlQuery map[string]string) string { + hsURL := *BuildURL(cli.HomeserverURL, urlPath.FullPath()...) query := hsURL.Query() if cli.AppServiceUserID != "" { query.Set("user_id", string(cli.AppServiceUserID)) diff --git a/url_test.go b/url_test.go index 029204a..5ce3548 100644 --- a/url_test.go +++ b/url_test.go @@ -20,8 +20,8 @@ func TestClient_BuildURL(t *testing.T) { assert.Equal(t, cli.HomeserverURL.Scheme, "https") assert.Equal(t, cli.HomeserverURL.Host, "example.com") assert.Equal(t, cli.HomeserverURL.Path, "") - built := cli.BuildURL("foo/bar%2F🐈 1", "hello", "world") - assert.Equal(t, "https://example.com/_matrix/client/r0/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) + built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world") + assert.Equal(t, "https://example.com/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) } func TestClient_BuildURL_HTTP(t *testing.T) { @@ -30,8 +30,8 @@ func TestClient_BuildURL_HTTP(t *testing.T) { assert.Equal(t, cli.HomeserverURL.Scheme, "http") assert.Equal(t, cli.HomeserverURL.Host, "example.com") assert.Equal(t, cli.HomeserverURL.Path, "") - built := cli.BuildURL("foo/bar%2F🐈 1", "hello", "world") - assert.Equal(t, "http://example.com/_matrix/client/r0/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) + built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world") + assert.Equal(t, "http://example.com/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) } func TestClient_BuildURL_MissingScheme(t *testing.T) { @@ -40,8 +40,8 @@ func TestClient_BuildURL_MissingScheme(t *testing.T) { assert.Equal(t, cli.HomeserverURL.Scheme, "https") assert.Equal(t, cli.HomeserverURL.Host, "example.com") assert.Equal(t, cli.HomeserverURL.Path, "") - built := cli.BuildURL("foo/bar%2F🐈 1", "hello", "world") - assert.Equal(t, "https://example.com/_matrix/client/r0/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) + built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world") + assert.Equal(t, "https://example.com/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) } func TestClient_BuildURL_WithPath(t *testing.T) { @@ -50,8 +50,8 @@ func TestClient_BuildURL_WithPath(t *testing.T) { assert.Equal(t, cli.HomeserverURL.Scheme, "https") assert.Equal(t, cli.HomeserverURL.Host, "example.com") assert.Equal(t, cli.HomeserverURL.Path, "/base") - built := cli.BuildURL("foo/bar%2F🐈 1", "hello", "world") - assert.Equal(t, "https://example.com/base/_matrix/client/r0/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) + built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world") + assert.Equal(t, "https://example.com/base/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) } func TestClient_BuildURL_MissingSchemeWithPath(t *testing.T) { @@ -60,6 +60,6 @@ func TestClient_BuildURL_MissingSchemeWithPath(t *testing.T) { assert.Equal(t, cli.HomeserverURL.Scheme, "https") assert.Equal(t, cli.HomeserverURL.Host, "example.com") assert.Equal(t, cli.HomeserverURL.Path, "/base") - built := cli.BuildURL("foo/bar%2F🐈 1", "hello", "world") - assert.Equal(t, "https://example.com/base/_matrix/client/r0/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) + built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world") + assert.Equal(t, "https://example.com/base/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built) }