mirror of
				https://github.com/matrix-org/gomatrix
				synced 2025-11-03 22:08:04 +00:00 
			
		
		
		
	Add methods to query /publicRooms API
This commit is contained in:
		
							parent
							
								
									7df988a63f
								
							
						
					
					
						commit
						9c5753065f
					
				
					 2 changed files with 66 additions and 0 deletions
				
			
		
							
								
								
									
										46
									
								
								client.go
									
										
									
									
									
								
							
							
						
						
									
										46
									
								
								client.go
									
										
									
									
									
								
							| 
						 | 
					@ -372,6 +372,52 @@ func (cli *Client) Versions() (resp *RespVersions, err error) {
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PublicRooms returns the list of public rooms on target server. Does not require Auth. See http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#get-matrix-client-unstable-publicrooms
 | 
				
			||||||
 | 
					func (cli *Client) PublicRooms(limit int, since string, server string) (resp *RespPublicRooms, err error) {
 | 
				
			||||||
 | 
						args := map[string]string{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if limit != 0 {
 | 
				
			||||||
 | 
							args["limit"] = strconv.Itoa(limit)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if since != "" {
 | 
				
			||||||
 | 
							args["since"] = since
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if server != "" {
 | 
				
			||||||
 | 
							args["server"] = server
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						urlPath := cli.BuildURLWithQuery([]string{"publicRooms"}, args)
 | 
				
			||||||
 | 
						err = cli.MakeRequest("GET", urlPath, nil, &resp)
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PublicRoomsFiltered returns a subset of PublicRooms filtered server side. See http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#post-matrix-client-unstable-publicrooms
 | 
				
			||||||
 | 
					func (cli *Client) PublicRoomsFiltered(limit int, since string, server string, filter string) (resp *RespPublicRooms, err error) {
 | 
				
			||||||
 | 
						content := map[string]string{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if limit != 0 {
 | 
				
			||||||
 | 
							content["limit"] = strconv.Itoa(limit)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if since != "" {
 | 
				
			||||||
 | 
							content["since"] = since
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if filter != "" {
 | 
				
			||||||
 | 
							content["filter"] = filter
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var urlPath string
 | 
				
			||||||
 | 
						if server == "" {
 | 
				
			||||||
 | 
							urlPath = cli.BuildURL("publicRooms")
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							urlPath = cli.BuildURLWithQuery([]string{"publicRooms"}, map[string]string{
 | 
				
			||||||
 | 
								"server": server,
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = cli.MakeRequest("POST", urlPath, content, &resp)
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// JoinRoom joins the client to a room ID or alias. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias
 | 
					// JoinRoom joins the client to a room ID or alias. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// 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
 | 
					// 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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										20
									
								
								responses.go
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								responses.go
									
										
									
									
									
								
							| 
						 | 
					@ -22,6 +22,26 @@ type RespVersions struct {
 | 
				
			||||||
	Versions []string `json:"versions"`
 | 
						Versions []string `json:"versions"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// RespPublicRooms is the JSON response for http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#get-matrix-client-unstable-publicrooms
 | 
				
			||||||
 | 
					type RespPublicRooms struct {
 | 
				
			||||||
 | 
						TotalRoomCountEstimate int                `json:"total_room_count_estimate"`
 | 
				
			||||||
 | 
						PrevBatch              string             `json:"prev_batch"`
 | 
				
			||||||
 | 
						NextBatch              string             `json:"next_batch"`
 | 
				
			||||||
 | 
						Chunk                  []PublicRoomsChunk `json:"chunk"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PublicRoomsChunk struct {
 | 
				
			||||||
 | 
						CanonicalAlias   string   `json:"canonical_alias"`
 | 
				
			||||||
 | 
						Name             string   `json:"name"`
 | 
				
			||||||
 | 
						WorldReadable    bool     `json:"world_readable"`
 | 
				
			||||||
 | 
						Topic            string   `json:"topic"`
 | 
				
			||||||
 | 
						NumJoinedMembers int      `json:"num_joined_members"`
 | 
				
			||||||
 | 
						AvatarUrl        string   `json:"avatar_url"`
 | 
				
			||||||
 | 
						RoomID           string   `json:"room_id"`
 | 
				
			||||||
 | 
						GuestCanJoin     bool     `json:"guest_can_join"`
 | 
				
			||||||
 | 
						Aliases          []string `json:"aliases"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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 http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join
 | 
				
			||||||
type RespJoinRoom struct {
 | 
					type RespJoinRoom struct {
 | 
				
			||||||
	RoomID string `json:"room_id"`
 | 
						RoomID string `json:"room_id"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue