mirror of
				https://github.com/matrix-org/gomatrix
				synced 2025-11-03 22:08:04 +00:00 
			
		
		
		
	Merge d43f7960c7 into 4da59c5538
				
					
				
			This commit is contained in:
		
						commit
						2d969b91f3
					
				
					 3 changed files with 76 additions and 1 deletions
				
			
		
							
								
								
									
										49
									
								
								client.go
									
										
									
									
									
								
							
							
						
						
									
										49
									
								
								client.go
									
										
									
									
									
								
							| 
						 | 
					@ -450,6 +450,35 @@ func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) {
 | 
				
			||||||
		TextMessage{"m.text", text})
 | 
							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
 | 
					// 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) {
 | 
					func (cli *Client) RedactEvent(roomID, eventID string, req *ReqRedact) (resp *RespSendEvent, err error) {
 | 
				
			||||||
	txnID := txnID()
 | 
						txnID := txnID()
 | 
				
			||||||
| 
						 | 
					@ -603,6 +632,26 @@ func (cli *Client) JoinedRooms() (resp *RespJoinedRooms, err error) {
 | 
				
			||||||
	return
 | 
						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"] = string(limit)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						urlPath := cli.BuildURLWithQuery([]string{"rooms", roomID, "messages"}, query)
 | 
				
			||||||
 | 
						_, err = cli.MakeRequest("GET", urlPath, nil, &resp)
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func txnID() string {
 | 
					func txnID() string {
 | 
				
			||||||
	return "go" + strconv.FormatInt(time.Now().UnixNano(), 10)
 | 
						return "go" + strconv.FormatInt(time.Now().UnixNano(), 10)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										21
									
								
								events.go
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								events.go
									
										
									
									
									
								
							| 
						 | 
					@ -44,7 +44,7 @@ type TextMessage struct {
 | 
				
			||||||
	Body    string `json:"body"`
 | 
						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 {
 | 
					type ImageInfo struct {
 | 
				
			||||||
	Height   uint   `json:"h"`
 | 
						Height   uint   `json:"h"`
 | 
				
			||||||
	Width    uint   `json:"w"`
 | 
						Width    uint   `json:"w"`
 | 
				
			||||||
| 
						 | 
					@ -52,6 +52,25 @@ type ImageInfo struct {
 | 
				
			||||||
	Size     uint   `json:"size"`
 | 
						Size     uint   `json:"size"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 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"`
 | 
				
			||||||
 | 
						ThumbnailInfo ImageInfo `json:"thumbnail_info"`
 | 
				
			||||||
 | 
						ThumbnailURL  string    `json:"thumbnail_url"`
 | 
				
			||||||
 | 
						Height        uint      `json:"h"`
 | 
				
			||||||
 | 
						Width         uint      `json:"w"`
 | 
				
			||||||
 | 
						Duration      uint      `json:"duration"`
 | 
				
			||||||
 | 
						Size          uint      `json:"size"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 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
 | 
					// ImageMessage is an m.image event
 | 
				
			||||||
type ImageMessage struct {
 | 
					type ImageMessage struct {
 | 
				
			||||||
	MsgType string    `json:"msgtype"`
 | 
						MsgType string    `json:"msgtype"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -61,6 +61,13 @@ type RespJoinedMembers struct {
 | 
				
			||||||
	} `json:"joined"`
 | 
						} `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
 | 
					// 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 {
 | 
					type RespSendEvent struct {
 | 
				
			||||||
	EventID string `json:"event_id"`
 | 
						EventID string `json:"event_id"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue