Status code 200: The lookup was successful.
42 | * 43 | * @param userId Required. The user to look up. 44 | * @return {@link AdminResponse} 45 | */ 46 | @GET 47 | @Path("/whois/{userId}") 48 | AdminResponse whois( 49 | @PathParam("userId") String userId 50 | ); 51 | } 52 | -------------------------------------------------------------------------------- /bot-impl/src/main/java/io/github/ma1uta/matrix/bot/command/Leave.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.bot.command; 18 | 19 | import io.github.ma1uta.matrix.bot.BotConfig; 20 | import io.github.ma1uta.matrix.bot.BotDao; 21 | import io.github.ma1uta.matrix.bot.Context; 22 | import io.github.ma1uta.matrix.bot.PersistentService; 23 | import io.github.ma1uta.matrix.event.RoomEvent; 24 | 25 | /** 26 | * Leave current room. 27 | * 28 | * @paramStatus code 200: The lookup was successful.
43 | * 44 | * @param userId Required. The user to look up. 45 | * @return {@link AdminResponse} 46 | */ 47 | @GET 48 | @Path("/whois/{userId}") 49 | CompletionStageStatus code 200: The capabilities of the server.
44 | *Status code 429: This request was rate-limited.
45 | * 46 | * @return {@link CapabilitiesResponse}. 47 | */ 48 | @GET 49 | @Path("/capabilities") 50 | CapabilitiesResponse capabilities(); 51 | } 52 | -------------------------------------------------------------------------------- /client-impl/src/main/java/io/github/ma1uta/matrix/client/methods/blocked/UserDirectoryMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.client.methods.blocked; 18 | 19 | import io.github.ma1uta.matrix.client.model.userdirectory.SearchRequest; 20 | import io.github.ma1uta.matrix.client.model.userdirectory.SearchResponse; 21 | import io.github.ma1uta.matrix.client.rest.blocked.UserDirectoryApi; 22 | import org.eclipse.microprofile.rest.client.RestClientBuilder; 23 | 24 | import java.util.Objects; 25 | 26 | /** 27 | * User directory methods. 28 | */ 29 | public class UserDirectoryMethods { 30 | 31 | private final UserDirectoryApi userDirectoryApi; 32 | 33 | public UserDirectoryMethods(RestClientBuilder restClientBuilder) { 34 | this.userDirectoryApi = restClientBuilder.build(UserDirectoryApi.class); 35 | } 36 | 37 | /** 38 | * This API performs a server-side search over all users registered on the server. It searches user ID and displayname 39 | * case-insensitively for users that you share a room with or that are in public rooms. 40 | * 41 | * @param request The search request. 42 | * @return The result of the search. 43 | */ 44 | public SearchResponse search(SearchRequest request) { 45 | Objects.requireNonNull(request.getSearchTerm(), "SearchTerm cannot be empty."); 46 | 47 | return userDirectoryApi.searchUsers(request); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /common-impl/src/main/java/io/github/ma1uta/matrix/impl/exception/MatrixException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.impl.exception; 18 | 19 | import io.github.ma1uta.matrix.common.ExceptionResponse; 20 | 21 | import java.net.HttpURLConnection; 22 | 23 | /** 24 | * Common matrix implementation exception. 25 | */ 26 | public class MatrixException extends RuntimeException { 27 | 28 | /** 29 | * Error code for all other unknown exceptions. 30 | */ 31 | public static final String M_INTERNAL = "M_INTERNAL"; 32 | 33 | /** 34 | * Response status. 35 | */ 36 | private Integer status = HttpURLConnection.HTTP_INTERNAL_ERROR; 37 | 38 | private ExceptionResponse response; 39 | 40 | public MatrixException(String error, ExceptionResponse response) { 41 | super(error); 42 | this.response = response; 43 | } 44 | 45 | public MatrixException(String error, ExceptionResponse response, Integer status) { 46 | this(error, response); 47 | this.status = status; 48 | } 49 | 50 | public ExceptionResponse getResponse() { 51 | return response; 52 | } 53 | 54 | public void setResponse(ExceptionResponse response) { 55 | this.response = response; 56 | } 57 | 58 | public Integer getStatus() { 59 | return status; 60 | } 61 | 62 | public void setStatus(Integer status) { 63 | this.status = status; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /client-impl/src/main/java/io/github/ma1uta/matrix/client/rest/async/CapabilitiesApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.client.rest.async; 18 | 19 | import io.github.ma1uta.matrix.client.model.capability.CapabilitiesResponse; 20 | 21 | import java.util.concurrent.CompletionStage; 22 | import javax.ws.rs.GET; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.Produces; 25 | import javax.ws.rs.core.MediaType; 26 | 27 | /** 28 | * A homeserver may not support certain operations and clients must be able to query for what the homeserver can and can't offer. 29 | * For example, a homeserver may not support users changing their password as it is configured to perform authentication against 30 | * an external system. 31 | */ 32 | @Path("/_matrix/client/r0") 33 | @Produces(MediaType.APPLICATION_JSON) 34 | public interface CapabilitiesApi { 35 | 36 | /** 37 | * Gets information about the server's supported feature set and other relevant capabilities. 38 | *Status code 200: The capabilities of the server.
45 | *Status code 429: This request was rate-limited.
46 | * 47 | * @return {@link CapabilitiesResponse}. 48 | */ 49 | @GET 50 | @Path("/capabilities") 51 | CompletionStageStatus code 200: The events and state surrounding the requested event.
44 | * 45 | * @param roomId Required. The room to get events from. 46 | * @param eventId Required. The event to get context around. 47 | * @param limit The maximum number of events to return. Default: 10. 48 | * @return {@link EventContextResponse}. 49 | */ 50 | @GET 51 | @Path("/{roomId}/context/{eventId}") 52 | EventContextResponse context( 53 | @PathParam("roomId") String roomId, 54 | @PathParam("eventId") String eventId, 55 | @QueryParam("limit") Integer limit 56 | ); 57 | } 58 | -------------------------------------------------------------------------------- /client-impl/src/main/java/io/github/ma1uta/matrix/client/rest/blocked/ServerDiscoveryApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.client.rest.blocked; 18 | 19 | import io.github.ma1uta.matrix.client.model.serverdiscovery.ServerDiscoveryResponse; 20 | 21 | import javax.ws.rs.GET; 22 | import javax.ws.rs.Path; 23 | import javax.ws.rs.Produces; 24 | import javax.ws.rs.core.MediaType; 25 | 26 | /** 27 | * In order to allow users to connect to a Matrix server without needing to explicitly specify the homeserver's URL or other parameters, 28 | * clients SHOULD use an auto-discovery mechanism to determine the server's URL based on a user's Matrix ID. Auto-discovery should only 29 | * be done at login time. 30 | */ 31 | @Path("/.well-known/matrix/client") 32 | @Produces(MediaType.APPLICATION_JSON) 33 | public interface ServerDiscoveryApi { 34 | 35 | /** 36 | * Gets discovery information about the domain. The file may include additional keys, which MUST follow the Java package naming 37 | * convention, e.g. com.example.myapp.property. This ensures property names are suitably namespaced for each application and 38 | * reduces the risk of clashes. 39 | *Status code 200: Server discovery information.
45 | *Status code 404: No server discovery information available.
46 | * 47 | * @return {@link ServerDiscoveryResponse}. 48 | */ 49 | @GET 50 | @Path("/") 51 | ServerDiscoveryResponse serverDiscovery(); 52 | } 53 | -------------------------------------------------------------------------------- /bot-impl/src/main/java/io/github/ma1uta/matrix/bot/command/SetAccessPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.bot.command; 18 | 19 | import io.github.ma1uta.matrix.bot.AccessPolicy; 20 | import io.github.ma1uta.matrix.bot.BotConfig; 21 | import io.github.ma1uta.matrix.bot.BotDao; 22 | import io.github.ma1uta.matrix.bot.Context; 23 | import io.github.ma1uta.matrix.bot.PersistentService; 24 | import io.github.ma1uta.matrix.event.RoomEvent; 25 | 26 | /** 27 | * Set new access policy. 28 | * 29 | * @paramStatus code 200: The events and state surrounding the requested event.
45 | * 46 | * @param roomId Required. The room to get events from. 47 | * @param eventId Required. The event to get context around. 48 | * @param limit The maximum number of events to return. Default: 10. 49 | * @return {@link EventContextResponse}. 50 | */ 51 | @GET 52 | @Path("/{roomId}/context/{eventId}") 53 | CompletionStageStatus code 200: Server discovery information.
46 | *Status code 404: No server discovery information available.
47 | * 48 | * @return {@link ServerDiscoveryResponse}. 49 | */ 50 | @GET 51 | @Path("/") 52 | CompletionStageStatus code 200: The event has been reported successfully.
46 | * 47 | * @param roomId Required. The room in which the event being reported is located. 48 | * @param eventId Required. The event to report. 49 | * @param reportRequest JSON body request. 50 | * @return {@link EmptyResponse}. 51 | */ 52 | @POST 53 | @Path("/rooms/{roomId}/report/{eventId}") 54 | EmptyResponse report( 55 | @PathParam("roomId") String roomId, 56 | @PathParam("eventId") String eventId, 57 | ReportRequest reportRequest 58 | ); 59 | } 60 | -------------------------------------------------------------------------------- /client-impl/src/test/java/io/github/ma1uta/matrix/client/ContentAsyncMethodsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.client; 18 | 19 | import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; 20 | import static com.github.tomakehurst.wiremock.client.WireMock.okJson; 21 | import static com.github.tomakehurst.wiremock.client.WireMock.post; 22 | import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching; 23 | import static org.junit.jupiter.api.Assertions.assertEquals; 24 | 25 | import io.github.ma1uta.matrix.client.model.content.ContentUri; 26 | import org.junit.jupiter.api.Test; 27 | 28 | import java.io.InputStream; 29 | import java.util.concurrent.TimeUnit; 30 | import javax.ws.rs.core.MediaType; 31 | 32 | class ContentAsyncMethodsTest extends MockServer { 33 | 34 | @Test 35 | void upload() throws Exception { 36 | wireMockServer.stubFor(post(urlPathMatching("/_matrix/media/r0/upload")) 37 | .withHeader("Content-Type", equalTo(MediaType.TEXT_PLAIN)) 38 | .withHeader("Authorization", equalTo("Bearer " + ACCESS_TOKEN)) 39 | .withQueryParam("filename", equalTo("content.txt")) 40 | .willReturn(okJson("{\"content_uri\":\"mxc://example.com/AQwafuaFswefuhsfAFAgsw\"}") 41 | ) 42 | ); 43 | 44 | try (InputStream inputStream = getClass().getResourceAsStream("/content.txt")) { 45 | getMatrixClient().getConnectionInfo().setAccessToken(ACCESS_TOKEN); 46 | String uri = getMatrixClient().contentAsync().upload(inputStream, "content.txt", "text/plain").thenApply(ContentUri::getContentUri) 47 | .get(1000, TimeUnit.MILLISECONDS); 48 | assertEquals("mxc://example.com/AQwafuaFswefuhsfAFAgsw", uri); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /client-impl/src/main/java/io/github/ma1uta/matrix/client/AbstractClientBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.client; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | * A Client builder. 23 | * 24 | * @paramStatus code 200: The event has been reported successfully.
47 | * 48 | * @param roomId Required. The room in which the event being reported is located. 49 | * @param eventId Required. The event to report. 50 | * @param reportRequest JSON body request. 51 | * @return {@link EmptyResponse}. 52 | */ 53 | @POST 54 | @Path("/rooms/{roomId}/report/{eventId}") 55 | CompletionStageStatus code 200: Results of the search.
47 | *Status code 400: Part of the request was invalid.
48 | *Status code 429: This request was rate-limited.
49 | * 50 | * @param nextBatch The point to return events from. If given, this should be a next_batch result from a previous call 51 | * to this endpoint. 52 | * @param searchRequest JSON body request. 53 | * @return {@link SearchResponse}. 54 | */ 55 | @POST 56 | @Path("/search") 57 | SearchResponse search( 58 | @QueryParam("next_batch") String nextBatch, 59 | SearchRequest searchRequest 60 | ); 61 | } 62 | -------------------------------------------------------------------------------- /client-impl/src/main/java/io/github/ma1uta/matrix/client/rest/async/SearchApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.client.rest.async; 18 | 19 | import io.github.ma1uta.matrix.client.model.search.SearchRequest; 20 | import io.github.ma1uta.matrix.client.model.search.SearchResponse; 21 | 22 | import java.util.concurrent.CompletionStage; 23 | import javax.ws.rs.Consumes; 24 | import javax.ws.rs.POST; 25 | import javax.ws.rs.Path; 26 | import javax.ws.rs.Produces; 27 | import javax.ws.rs.QueryParam; 28 | import javax.ws.rs.core.MediaType; 29 | 30 | /** 31 | * The search API allows clients to perform full text search across events in all rooms that the user has been in, including those 32 | * that they have left. Only events that the user is allowed to see will be searched, e.g. it won't include events in rooms that 33 | * happened after you left. 34 | */ 35 | @Path("/_matrix/client/r0") 36 | @Consumes(MediaType.APPLICATION_JSON) 37 | @Produces(MediaType.APPLICATION_JSON) 38 | public interface SearchApi { 39 | 40 | /** 41 | * Performs a full text search across different categories. 42 | *Status code 200: Results of the search.
48 | *Status code 400: Part of the request was invalid.
49 | *Status code 429: This request was rate-limited.
50 | * 51 | * @param nextBatch The point to return events from. If given, this should be a next_batch result from a previous call 52 | * to this endpoint. 53 | * @param searchRequest JSON body request. 54 | * @return {@link SearchResponse}. 55 | */ 56 | @POST 57 | @Path("/search") 58 | CompletionStageStatus code 200: The results of the search.
52 | *Status code 429: This request was rate-limited.
53 | * 54 | * @param request JSON body request. 55 | * @return {@link SearchResponse}. 56 | */ 57 | @POST 58 | @Path("/search") 59 | SearchResponse searchUsers( 60 | SearchRequest request 61 | ); 62 | } 63 | -------------------------------------------------------------------------------- /bot-impl/src/main/java/io/github/ma1uta/matrix/bot/AbstractStandaloneBotPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Anatoliy Sablin tolya@sablin.xyz 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.ma1uta.matrix.bot; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import java.util.List; 23 | import java.util.concurrent.ExecutorService; 24 | import java.util.concurrent.Executors; 25 | import java.util.concurrent.TimeUnit; 26 | 27 | /** 28 | * Bot service. 29 | * 30 | * @paramStatus code 200: The results of the search.
53 | *Status code 429: This request was rate-limited.
54 | * 55 | * @param request JSON body request. 56 | * @return {@link SearchResponse}. 57 | */ 58 | @POST 59 | @Path("/search") 60 | CompletionStageStatus code 200: OpenID token information. This response is nearly compatible with the response documented 48 | * in the OpenID 1.0 Specification with the only difference being the lack of an id_token. Instead, the Matrix homeserver's name 49 | * is provided.
50 | *Status code 429: This request was rate-limited.
51 | * 52 | * @param userId Required. The user to request and OpenID token for. Should be the user who is authenticated for the request. 53 | * @return {@link OpenIdResponse}. 54 | */ 55 | @POST 56 | @Path("/user/{userId}/openid/request_token") 57 | OpenIdResponse requestToken( 58 | @PathParam("userId") String userId 59 | ); 60 | } 61 | --------------------------------------------------------------------------------