From 71cb9b2d1dd96b309134187cd38155c22f086060 Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 21 Nov 2017 23:48:39 +0100 Subject: [PATCH] Update vendor github.com/matrix-org/gomatrix --- .../github.com/matrix-org/gomatrix/client.go | 90 ++++++++++++++++++- .../github.com/matrix-org/gomatrix/events.go | 43 ++++++--- .../github.com/matrix-org/gomatrix/filter.go | 43 +++++++++ .../matrix-org/gomatrix/requests.go | 6 ++ .../matrix-org/gomatrix/responses.go | 32 +++++++ vendor/github.com/matrix-org/gomatrix/room.go | 2 +- vendor/github.com/matrix-org/gomatrix/sync.go | 12 ++- vendor/manifest | 2 +- 8 files changed, 213 insertions(+), 17 deletions(-) create mode 100644 vendor/github.com/matrix-org/gomatrix/filter.go diff --git a/vendor/github.com/matrix-org/gomatrix/client.go b/vendor/github.com/matrix-org/gomatrix/client.go index 29784ebf..90a07c68 100644 --- a/vendor/github.com/matrix-org/gomatrix/client.go +++ b/vendor/github.com/matrix-org/gomatrix/client.go @@ -79,7 +79,7 @@ func (cli *Client) BuildBaseURL(urlPath ...string) string { return hsURL.String() } -// BuildURLWithQuery builds a URL with query paramters in addition to the Client's homeserver/prefix/access_token set already. +// BuildURLWithQuery builds a URL with query parameters in addition to the Client's homeserver/prefix/access_token set already. func (cli *Client) BuildURLWithQuery(urlPath []string, urlQuery map[string]string) string { u, _ := url.Parse(cli.BuildURL(urlPath...)) q := u.Query() @@ -387,6 +387,20 @@ func (cli *Client) JoinRoom(roomIDorAlias, serverName string, content interface{ return } +// GetDisplayName returns the display name of the user from the specified MXID. See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname +func (cli *Client) GetDisplayName(mxid string) (resp *RespUserDisplayName, err error) { + urlPath := cli.BuildURL("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.2.0.html#get-matrix-client-r0-profile-userid-displayname +func (cli *Client) GetOwnDisplayName() (resp *RespUserDisplayName, err error) { + urlPath := cli.BuildURL("profile", cli.UserID, "displayname") + _, err = cli.MakeRequest("GET", urlPath, nil, &resp) + return +} + // SetDisplayName sets the user's profile display name. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname func (cli *Client) SetDisplayName(displayName string) (err error) { urlPath := cli.BuildURL("profile", cli.UserID, "displayname") @@ -450,6 +464,35 @@ func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) { TextMessage{"m.text", text}) } +// 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 +func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) { + return cli.SendMessageEvent(roomID, "m.room.message", + ImageMessage{ + MsgType: "m.image", + Body: body, + URL: url, + }) +} + +// 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 +func (cli *Client) SendVideo(roomID, body, url string) (*RespSendEvent, error) { + return cli.SendMessageEvent(roomID, "m.room.message", + VideoMessage{ + MsgType: "m.video", + Body: body, + URL: url, + }) +} + +// 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 +func (cli *Client) SendNotice(roomID, text string) (*RespSendEvent, error) { + return cli.SendMessageEvent(roomID, "m.room.message", + TextMessage{"m.notice", text}) +} + // 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 func (cli *Client) RedactEvent(roomID, eventID string, req *ReqRedact) (resp *RespSendEvent, err error) { txnID := txnID() @@ -518,6 +561,14 @@ func (cli *Client) UnbanUser(roomID string, req *ReqUnbanUser) (resp *RespUnbanU 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 +func (cli *Client) UserTyping(roomID string, typing bool, timeout int64) (resp *RespTyping, err error) { + req := ReqTyping{Typing: typing, Timeout: timeout} + u := cli.BuildURL("rooms", roomID, "typing", cli.UserID) + _, err = cli.MakeRequest("PUT", u, req, &resp) + 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 @@ -556,8 +607,15 @@ func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, co return nil, err } if res.StatusCode != 200 { + contents, err := ioutil.ReadAll(res.Body) + if err != nil { + return nil, HTTPError{ + Message: "Upload request failed - Failed to read response body: " + err.Error(), + Code: res.StatusCode, + } + } return nil, HTTPError{ - Message: "Upload request failed", + Message: "Upload request failed: " + string(contents), Code: res.StatusCode, } } @@ -588,6 +646,34 @@ func (cli *Client) JoinedRooms() (resp *RespJoinedRooms, err error) { 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 +func (cli *Client) Messages(roomID, from, to string, dir rune, limit int) (resp *RespMessages, err error) { + query := map[string]string{ + "from": from, + "dir": string(dir), + } + if to != "" { + query["to"] = to + } + if limit != 0 { + query["limit"] = strconv.Itoa(limit) + } + + urlPath := cli.BuildURLWithQuery([]string{"rooms", roomID, "messages"}, query) + _, err = cli.MakeRequest("GET", urlPath, nil, &resp) + return +} + +// 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 +func (cli *Client) TurnServer() (resp *RespTurnServer, err error) { + urlPath := cli.BuildURL("voip", "turnServer") + _, err = cli.MakeRequest("GET", urlPath, nil, &resp) + return +} + func txnID() string { return "go" + strconv.FormatInt(time.Now().UnixNano(), 10) } diff --git a/vendor/github.com/matrix-org/gomatrix/events.go b/vendor/github.com/matrix-org/gomatrix/events.go index 6ea259e3..7427740e 100644 --- a/vendor/github.com/matrix-org/gomatrix/events.go +++ b/vendor/github.com/matrix-org/gomatrix/events.go @@ -7,13 +7,13 @@ import ( // Event represents a single Matrix event. type Event struct { - StateKey string `json:"state_key"` // The state key for the event. Only present on State Events. - Sender string `json:"sender"` // The user ID of the sender of the event - Type string `json:"type"` // The event type - Timestamp int `json:"origin_server_ts"` // The unix timestamp when this message was sent by the origin server - ID string `json:"event_id"` // The unique ID of this event - RoomID string `json:"room_id"` // The room the event was sent to. May be nil (e.g. for presence) - Content map[string]interface{} `json:"content"` // The JSON content of the event. + StateKey *string `json:"state_key,omitempty"` // The state key for the event. Only present on State Events. + Sender string `json:"sender"` // The user ID of the sender of the event + Type string `json:"type"` // The event type + Timestamp int64 `json:"origin_server_ts"` // The unix timestamp when this message was sent by the origin server + ID string `json:"event_id"` // The unique ID of this event + RoomID string `json:"room_id"` // The room the event was sent to. May be nil (e.g. for presence) + Content map[string]interface{} `json:"content"` // The JSON content of the event. } // Body returns the value of the "body" key in the event content if it is @@ -44,12 +44,31 @@ type TextMessage struct { Body string `json:"body"` } -// ImageInfo contains info about an image +// ImageInfo contains info about an image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-image type ImageInfo struct { - Height uint `json:"h"` - Width uint `json:"w"` - Mimetype string `json:"mimetype"` - Size uint `json:"size"` + Height uint `json:"h,omitempty"` + Width uint `json:"w,omitempty"` + Mimetype string `json:"mimetype,omitempty"` + Size uint `json:"size,omitempty"` +} + +// VideoInfo contains info about a video - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-video +type VideoInfo struct { + Mimetype string `json:"mimetype,omitempty"` + ThumbnailInfo ImageInfo `json:"thumbnail_info"` + ThumbnailURL string `json:"thumbnail_url,omitempty"` + Height uint `json:"h,omitempty"` + Width uint `json:"w,omitempty"` + Duration uint `json:"duration,omitempty"` + Size uint `json:"size,omitempty"` +} + +// VideoMessage is an m.video - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-video +type VideoMessage struct { + MsgType string `json:"msgtype"` + Body string `json:"body"` + URL string `json:"url"` + Info VideoInfo `json:"info"` } // ImageMessage is an m.image event diff --git a/vendor/github.com/matrix-org/gomatrix/filter.go b/vendor/github.com/matrix-org/gomatrix/filter.go new file mode 100644 index 00000000..e4e76287 --- /dev/null +++ b/vendor/github.com/matrix-org/gomatrix/filter.go @@ -0,0 +1,43 @@ +// Copyright 2017 Jan Christian Grünhage +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gomatrix + +//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.2.0.html#filtering +type Filter struct { + AccountData FilterPart `json:"account_data,omitempty"` + EventFields []string `json:"event_fields,omitempty"` + EventFormat string `json:"event_format,omitempty"` + Presence FilterPart `json:"presence,omitempty"` + Room struct { + AccountData FilterPart `json:"account_data,omitempty"` + Ephemeral FilterPart `json:"ephemeral,omitempty"` + IncludeLeave bool `json:"include_leave,omitempty"` + NotRooms []string `json:"not_rooms,omitempty"` + Rooms []string `json:"rooms,omitempty"` + State FilterPart `json:"state,omitempty"` + Timeline FilterPart `json:"timeline,omitempty"` + } `json:"room,omitempty"` +} + +type FilterPart struct { + NotRooms []string `json:"not_rooms,omitempty"` + Rooms []string `json:"rooms,omitempty"` + Limit *int `json:"limit,omitempty"` + NotSenders []string `json:"not_senders,omitempty"` + NotTypes []string `json:"not_types,omitempty"` + Senders []string `json:"senders,omitempty"` + Types []string `json:"types,omitempty"` +} diff --git a/vendor/github.com/matrix-org/gomatrix/requests.go b/vendor/github.com/matrix-org/gomatrix/requests.go index c1ba27b9..af99a226 100644 --- a/vendor/github.com/matrix-org/gomatrix/requests.go +++ b/vendor/github.com/matrix-org/gomatrix/requests.go @@ -70,3 +70,9 @@ type ReqBanUser struct { type ReqUnbanUser struct { UserID string `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 +type ReqTyping struct { + Typing bool `json:"typing"` + Timeout int64 `json:"timeout"` +} diff --git a/vendor/github.com/matrix-org/gomatrix/responses.go b/vendor/github.com/matrix-org/gomatrix/responses.go index de7a8ae9..fe0eeb32 100644 --- a/vendor/github.com/matrix-org/gomatrix/responses.go +++ b/vendor/github.com/matrix-org/gomatrix/responses.go @@ -45,6 +45,9 @@ 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 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 +type RespTyping struct{} + // RespJoinedRooms is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680 type RespJoinedRooms struct { JoinedRooms []string `json:"joined_rooms"` @@ -58,6 +61,13 @@ 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 +type RespMessages struct { + Start string `json:"start"` + Chunk []Event `json:"chunk"` + End string `json:"end"` +} + // 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 type RespSendEvent struct { EventID string `json:"event_id"` @@ -90,6 +100,11 @@ func (r RespUserInteractive) HasSingleStageFlow(stageName string) 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 +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 type RespRegister struct { AccessToken string `json:"access_token"` @@ -125,6 +140,16 @@ type RespSync struct { Events []Event `json:"events"` } `json:"presence"` Rooms struct { + Leave map[string]struct { + State struct { + Events []Event `json:"events"` + } `json:"state"` + Timeline struct { + Events []Event `json:"events"` + Limited bool `json:"limited"` + PrevBatch string `json:"prev_batch"` + } `json:"timeline"` + } `json:"leave"` Join map[string]struct { State struct { Events []Event `json:"events"` @@ -142,3 +167,10 @@ type RespSync struct { } `json:"invite"` } `json:"rooms"` } + +type RespTurnServer struct { + Username string `json:"username"` + Password string `json:"password"` + TTL int `json:"ttl"` + URIs []string `json:"uris"` +} diff --git a/vendor/github.com/matrix-org/gomatrix/room.go b/vendor/github.com/matrix-org/gomatrix/room.go index 0533b3e7..c9b2351f 100644 --- a/vendor/github.com/matrix-org/gomatrix/room.go +++ b/vendor/github.com/matrix-org/gomatrix/room.go @@ -13,7 +13,7 @@ func (room Room) UpdateState(event *Event) { if !exists { room.State[event.Type] = make(map[string]*Event) } - room.State[event.Type][event.StateKey] = event + room.State[event.Type][*event.StateKey] = event } // GetStateEvent returns the state event for the given type/state_key combo, or nil. diff --git a/vendor/github.com/matrix-org/gomatrix/sync.go b/vendor/github.com/matrix-org/gomatrix/sync.go index 347e5dcf..c4bea48c 100644 --- a/vendor/github.com/matrix-org/gomatrix/sync.go +++ b/vendor/github.com/matrix-org/gomatrix/sync.go @@ -73,6 +73,16 @@ func (s *DefaultSyncer) ProcessResponse(res *RespSync, since string) (err error) s.notifyListeners(&event) } } + for roomID, roomData := range res.Rooms.Leave { + room := s.getOrCreateRoom(roomID) + for _, event := range roomData.Timeline.Events { + if event.StateKey != nil { + event.RoomID = roomID + room.UpdateState(&event) + s.notifyListeners(&event) + } + } + } return } @@ -102,7 +112,7 @@ func (s *DefaultSyncer) shouldProcessResponse(resp *RespSync, since string) bool for roomID, roomData := range resp.Rooms.Join { for i := len(roomData.Timeline.Events) - 1; i >= 0; i-- { e := roomData.Timeline.Events[i] - if e.Type == "m.room.member" && e.StateKey == s.UserID { + if e.Type == "m.room.member" && e.StateKey != nil && *e.StateKey == s.UserID { m := e.Content["membership"] mship, ok := m.(string) if !ok { diff --git a/vendor/manifest b/vendor/manifest index dd4a7707..0a97122b 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -290,7 +290,7 @@ "importpath": "github.com/matrix-org/gomatrix", "repository": "https://github.com/matrix-org/gomatrix", "vcs": "git", - "revision": "812dcb5515581023371efaa6a82750d997f50d57", + "revision": "a7fc80c8060c2544fe5d4dae465b584f8e9b4e27", "branch": "master", "notests": true },