NcApi.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. *
  3. * Nextcloud Talk application
  4. *
  5. * @author Mario Danic
  6. * @author Marcel Hibbe
  7. * @author Tim Krüger
  8. * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
  9. * Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
  10. * Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. package com.nextcloud.talk.api;
  26. import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall;
  27. import com.nextcloud.talk.models.json.chat.ChatOverall;
  28. import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage;
  29. import com.nextcloud.talk.models.json.conversations.RoomOverall;
  30. import com.nextcloud.talk.models.json.conversations.RoomsOverall;
  31. import com.nextcloud.talk.models.json.generic.GenericOverall;
  32. import com.nextcloud.talk.models.json.generic.Status;
  33. import com.nextcloud.talk.models.json.hovercard.HoverCardOverall;
  34. import com.nextcloud.talk.models.json.mention.MentionOverall;
  35. import com.nextcloud.talk.models.json.notifications.NotificationOverall;
  36. import com.nextcloud.talk.models.json.participants.AddParticipantOverall;
  37. import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
  38. import com.nextcloud.talk.models.json.push.PushRegistrationOverall;
  39. import com.nextcloud.talk.models.json.search.ContactsByNumberOverall;
  40. import com.nextcloud.talk.models.json.signaling.SignalingOverall;
  41. import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
  42. import com.nextcloud.talk.models.json.userprofile.UserProfileFieldsOverall;
  43. import com.nextcloud.talk.models.json.userprofile.UserProfileOverall;
  44. import java.util.List;
  45. import java.util.Map;
  46. import androidx.annotation.Nullable;
  47. import io.reactivex.Observable;
  48. import okhttp3.MultipartBody;
  49. import okhttp3.RequestBody;
  50. import okhttp3.ResponseBody;
  51. import retrofit2.Call;
  52. import retrofit2.Response;
  53. import retrofit2.http.Body;
  54. import retrofit2.http.DELETE;
  55. import retrofit2.http.Field;
  56. import retrofit2.http.FieldMap;
  57. import retrofit2.http.FormUrlEncoded;
  58. import retrofit2.http.GET;
  59. import retrofit2.http.Header;
  60. import retrofit2.http.Multipart;
  61. import retrofit2.http.POST;
  62. import retrofit2.http.PUT;
  63. import retrofit2.http.Part;
  64. import retrofit2.http.Query;
  65. import retrofit2.http.QueryMap;
  66. import retrofit2.http.Url;
  67. public interface NcApi {
  68. /*
  69. QueryMap items are as follows:
  70. - "format" : "json"
  71. - "search" : ""
  72. - "perPage" : "200"
  73. - "itemType" : "call"
  74. Server URL is: baseUrl + ocsApiVersion + /apps/files_sharing/api/v1/sharees
  75. or if we're on 14 and up:
  76. baseUrl + ocsApiVersion + "/core/autocomplete/get");
  77. */
  78. @GET
  79. Observable<ResponseBody> getContactsWithSearchParam(@Header("Authorization") String authorization, @Url String url,
  80. @Nullable @Query("shareTypes[]") List<String> listOfShareTypes, @QueryMap Map<String, Object> options);
  81. /*
  82. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room
  83. */
  84. @GET
  85. Observable<RoomsOverall> getRooms(@Header("Authorization") String authorization, @Url String url);
  86. /*
  87. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
  88. */
  89. @GET
  90. Observable<RoomOverall> getRoom(@Header("Authorization") String authorization, @Url String url);
  91. /*
  92. QueryMap items are as follows:
  93. - "roomType" : ""
  94. - "invite" : ""
  95. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room
  96. */
  97. @POST
  98. Observable<RoomOverall> createRoom(@Header("Authorization") String authorization, @Url String url,
  99. @QueryMap Map<String, String> options);
  100. /*
  101. QueryMap items are as follows:
  102. - "roomName" : "newName"
  103. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
  104. */
  105. @FormUrlEncoded
  106. @PUT
  107. Observable<GenericOverall> renameRoom(@Header("Authorization") String authorization, @Url String url,
  108. @Field("roomName") String roomName);
  109. /*
  110. QueryMap items are as follows:
  111. - "newParticipant" : "user"
  112. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants
  113. */
  114. @POST
  115. Observable<AddParticipantOverall> addParticipant(@Header("Authorization") String authorization, @Url String url,
  116. @QueryMap Map<String, String> options);
  117. // also used for removing a guest from a conversation
  118. @Deprecated
  119. @DELETE
  120. Observable<GenericOverall> removeParticipantFromConversation(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  121. @DELETE
  122. Observable<GenericOverall> removeAttendeeFromConversation(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  123. @Deprecated
  124. @POST
  125. Observable<GenericOverall> promoteUserToModerator(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  126. @Deprecated
  127. @DELETE
  128. Observable<GenericOverall> demoteModeratorToUser(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  129. @POST
  130. Observable<GenericOverall> promoteAttendeeToModerator(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  131. @DELETE
  132. Observable<GenericOverall> demoteAttendeeFromModerator(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  133. /*
  134. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants/self
  135. */
  136. @DELETE
  137. Observable<GenericOverall> removeSelfFromRoom(@Header("Authorization") String authorization, @Url String url);
  138. /*
  139. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public
  140. */
  141. @POST
  142. Observable<GenericOverall> makeRoomPublic(@Header("Authorization") String authorization, @Url String url);
  143. /*
  144. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public
  145. */
  146. @DELETE
  147. Observable<GenericOverall> makeRoomPrivate(@Header("Authorization") String authorization, @Url String url);
  148. @DELETE
  149. Observable<GenericOverall> deleteRoom(@Header("Authorization") String authorization, @Url String url);
  150. /*
  151. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  152. */
  153. @GET
  154. Observable<ParticipantsOverall> getPeersForCall(@Header("Authorization") String authorization, @Url String url);
  155. @FormUrlEncoded
  156. @POST
  157. Observable<RoomOverall> joinRoom(@Nullable @Header("Authorization") String authorization, @Url String url, @Nullable @Field("password") String password);
  158. @DELETE
  159. Observable<GenericOverall> leaveRoom(@Nullable @Header("Authorization") String authorization, @Url String url);
  160. /*
  161. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  162. */
  163. @FormUrlEncoded
  164. @POST
  165. Observable<GenericOverall> joinCall(@Nullable @Header("Authorization") String authorization, @Url String url,
  166. @Field("flags") Integer inCall);
  167. /*
  168. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  169. */
  170. @DELETE
  171. Observable<GenericOverall> leaveCall(@Nullable @Header("Authorization") String authorization, @Url String url);
  172. @GET
  173. Observable<SignalingSettingsOverall> getSignalingSettings(@Nullable @Header("Authorization") String authorization,
  174. @Url String url);
  175. /*
  176. QueryMap items are as follows:
  177. - "messages" : "message"
  178. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling
  179. */
  180. @FormUrlEncoded
  181. @POST
  182. Observable<SignalingOverall> sendSignalingMessages(@Nullable @Header("Authorization") String authorization, @Url String url,
  183. @Field("messages") String messages);
  184. /*
  185. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling
  186. */
  187. @GET
  188. Observable<SignalingOverall> pullSignalingMessages(@Nullable @Header("Authorization") String authorization, @Url
  189. String
  190. url);
  191. /*
  192. QueryMap items are as follows:
  193. - "format" : "json"
  194. Server URL is: baseUrl + ocsApiVersion + "/cloud/user"
  195. */
  196. @GET
  197. Observable<UserProfileOverall> getUserProfile(@Header("Authorization") String authorization, @Url String url);
  198. @GET
  199. Observable<UserProfileOverall> getUserData(@Header("Authorization") String authorization, @Url String url);
  200. @FormUrlEncoded
  201. @PUT
  202. Observable<GenericOverall> setUserData(@Header("Authorization") String authorization, @Url String url,
  203. @Field("key") String key, @Field("value") String value);
  204. /*
  205. Server URL is: baseUrl + /status.php
  206. */
  207. @GET
  208. Observable<Status> getServerStatus(@Url String url);
  209. /*
  210. QueryMap items are as follows:
  211. - "format" : "json"
  212. - "pushTokenHash" : ""
  213. - "devicePublicKey" : ""
  214. - "proxyServer" : ""
  215. Server URL is: baseUrl + ocsApiVersion + "/apps/notifications/api/v2/push
  216. */
  217. @POST
  218. Observable<PushRegistrationOverall> registerDeviceForNotificationsWithNextcloud(@Header("Authorization")
  219. String authorization,
  220. @Url String url,
  221. @QueryMap Map<String,
  222. String> options);
  223. @DELETE
  224. Observable<GenericOverall> unregisterDeviceForNotificationsWithNextcloud(@Header("Authorization")
  225. String authorization,
  226. @Url String url);
  227. @FormUrlEncoded
  228. @POST
  229. Observable<Void> registerDeviceForNotificationsWithProxy(@Url String url,
  230. @FieldMap Map<String, String> fields);
  231. /*
  232. QueryMap items are as follows:
  233. - "deviceIdentifier": "{{deviceIdentifier}}",
  234. - "deviceIdentifierSignature": "{{signature}}",
  235. - "userPublicKey": "{{userPublicKey}}"
  236. */
  237. @DELETE
  238. Observable<Void> unregisterDeviceForNotificationsWithProxy(@Url String url,
  239. @QueryMap Map<String, String> fields);
  240. @FormUrlEncoded
  241. @PUT
  242. Observable<GenericOverall> setPassword(@Header("Authorization") String authorization, @Url String url,
  243. @Field("password") String password);
  244. @GET
  245. Observable<CapabilitiesOverall> getCapabilities(@Header("Authorization") String authorization, @Url String url);
  246. /*
  247. QueryMap items are as follows:
  248. - "lookIntoFuture": int (0 or 1),
  249. - "limit" : int, range 100-200,
  250. - "timeout": used with look into future, 30 default, 60 at most
  251. - "lastKnownMessageId", int, use one from X-Chat-Last-Given
  252. */
  253. @GET
  254. Observable<Response<ChatOverall>> pullChatMessages(@Header("Authorization") String authorization, @Url String url,
  255. @QueryMap Map<String, Integer> fields);
  256. /*
  257. Fieldmap items are as follows:
  258. - "message": ,
  259. - "actorDisplayName"
  260. */
  261. @FormUrlEncoded
  262. @POST
  263. Observable<GenericOverall> sendChatMessage(@Header("Authorization") String authorization,
  264. @Url String url,
  265. @Field("message") CharSequence message,
  266. @Field("actorDisplayName") String actorDisplayName,
  267. @Field("replyTo") Integer replyTo);
  268. @GET
  269. Observable<MentionOverall> getMentionAutocompleteSuggestions(@Header("Authorization") String authorization,
  270. @Url String url, @Query("search") String query,
  271. @Nullable @Query("limit") Integer limit);
  272. // Url is: /api/{apiVersion}/room/{token}/pin
  273. @POST
  274. Observable<GenericOverall> addConversationToFavorites(@Header("Authorization") String authorization,
  275. @Url String url);
  276. // Url is: /api/{apiVersion}/room/{token}/favorites
  277. @DELETE
  278. Observable<GenericOverall> removeConversationFromFavorites(@Header("Authorization") String authorization,
  279. @Url String url);
  280. @GET
  281. Observable<NotificationOverall> getNotification(@Header("Authorization") String authorization,
  282. @Url String url);
  283. @FormUrlEncoded
  284. @POST
  285. Observable<GenericOverall> setNotificationLevel(@Header("Authorization") String authorization, @Url String url, @Field("level") int level);
  286. @FormUrlEncoded
  287. @PUT
  288. Observable<GenericOverall> setReadOnlyState(@Header("Authorization") String authorization, @Url String url, @Field("state") int state);
  289. @FormUrlEncoded
  290. @POST
  291. Observable<Void> createRemoteShare(@Nullable @Header("Authorization") String authorization, @Url String url,
  292. @Field("path") String remotePath,
  293. @Field("shareWith") String roomToken,
  294. @Field("shareType") String shareType,
  295. @Field("talkMetaData") String talkMetaData);
  296. @FormUrlEncoded
  297. @PUT
  298. Observable<GenericOverall> setLobbyForConversation(@Header("Authorization") String authorization,
  299. @Url String url, @Field("state") Integer state,
  300. @Field("timer") Long timer);
  301. @POST
  302. Observable<GenericOverall> setReadStatusPrivacy(@Header("Authorization") String authorization,
  303. @Url String url,
  304. @Body RequestBody body);
  305. @POST
  306. Observable<ContactsByNumberOverall> searchContactsByPhoneNumber(@Header("Authorization") String authorization,
  307. @Url String url,
  308. @Body RequestBody search);
  309. @PUT
  310. Observable<Response<GenericOverall>> uploadFile(@Header("Authorization") String authorization,
  311. @Url String url,
  312. @Body RequestBody body);
  313. @GET
  314. Call<ResponseBody> downloadFile(@Header("Authorization") String authorization,
  315. @Url String url);
  316. @DELETE
  317. Observable<ChatOverallSingleMessage> deleteChatMessage(@Header("Authorization") String authorization,
  318. @Url String url);
  319. @DELETE
  320. Observable<GenericOverall> deleteAvatar(@Header("Authorization") String authorization, @Url String url);
  321. @Multipart
  322. @POST
  323. Observable<GenericOverall> uploadAvatar(@Header("Authorization") String authorization,
  324. @Url String url,
  325. @Part MultipartBody.Part attachment);
  326. @GET
  327. Observable<UserProfileFieldsOverall> getEditableUserProfileFields(@Header("Authorization") String authorization,
  328. @Url String url);
  329. @GET
  330. Call<ResponseBody> downloadResizedImage(@Header("Authorization") String authorization,
  331. @Url String url);
  332. @FormUrlEncoded
  333. @POST
  334. Observable<GenericOverall> sendLocation(@Header("Authorization") String authorization,
  335. @Url String url,
  336. @Field("objectType") String objectType,
  337. @Field("objectId") String objectId,
  338. @Field("metaData") String metaData);
  339. @DELETE
  340. Observable<GenericOverall> clearChatHistory(@Header("Authorization") String authorization, @Url String url);
  341. @FormUrlEncoded
  342. @POST
  343. Observable<GenericOverall> notificationCalls(@Header("Authorization") String authorization, @Url String url,
  344. @Field("level") Integer level);
  345. @GET
  346. Observable<HoverCardOverall> hoverCard(@Header("Authorization") String authorization, @Url String url);
  347. // Url is: /api/{apiVersion}/chat/{token}/read
  348. @FormUrlEncoded
  349. @POST
  350. Observable<GenericOverall> setChatReadMarker(@Header("Authorization") String authorization,
  351. @Url String url,
  352. @Field("lastReadMessage") int lastReadMessage);
  353. }