NcApi.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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.status.StatusOverall;
  43. import com.nextcloud.talk.models.json.statuses.StatusesOverall;
  44. import com.nextcloud.talk.models.json.userprofile.UserProfileFieldsOverall;
  45. import com.nextcloud.talk.models.json.userprofile.UserProfileOverall;
  46. import java.util.List;
  47. import java.util.Map;
  48. import androidx.annotation.Nullable;
  49. import io.reactivex.Observable;
  50. import okhttp3.MultipartBody;
  51. import okhttp3.RequestBody;
  52. import okhttp3.ResponseBody;
  53. import retrofit2.Call;
  54. import retrofit2.Response;
  55. import retrofit2.http.Body;
  56. import retrofit2.http.DELETE;
  57. import retrofit2.http.Field;
  58. import retrofit2.http.FieldMap;
  59. import retrofit2.http.FormUrlEncoded;
  60. import retrofit2.http.GET;
  61. import retrofit2.http.Header;
  62. import retrofit2.http.Multipart;
  63. import retrofit2.http.POST;
  64. import retrofit2.http.PUT;
  65. import retrofit2.http.Part;
  66. import retrofit2.http.Query;
  67. import retrofit2.http.QueryMap;
  68. import retrofit2.http.Url;
  69. public interface NcApi {
  70. /*
  71. QueryMap items are as follows:
  72. - "format" : "json"
  73. - "search" : ""
  74. - "perPage" : "200"
  75. - "itemType" : "call"
  76. Server URL is: baseUrl + ocsApiVersion + /apps/files_sharing/api/v1/sharees
  77. or if we're on 14 and up:
  78. baseUrl + ocsApiVersion + "/core/autocomplete/get");
  79. */
  80. @GET
  81. Observable<ResponseBody> getContactsWithSearchParam(@Header("Authorization") String authorization, @Url String url,
  82. @Nullable @Query("shareTypes[]") List<String> listOfShareTypes, @QueryMap Map<String, Object> options);
  83. /*
  84. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room
  85. */
  86. @GET
  87. Observable<RoomsOverall> getRooms(@Header("Authorization") String authorization, @Url String url);
  88. /*
  89. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
  90. */
  91. @GET
  92. Observable<RoomOverall> getRoom(@Header("Authorization") String authorization, @Url String url);
  93. /*
  94. QueryMap items are as follows:
  95. - "roomType" : ""
  96. - "invite" : ""
  97. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room
  98. */
  99. @POST
  100. Observable<RoomOverall> createRoom(@Header("Authorization") String authorization, @Url String url,
  101. @QueryMap Map<String, String> options);
  102. /*
  103. QueryMap items are as follows:
  104. - "roomName" : "newName"
  105. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
  106. */
  107. @FormUrlEncoded
  108. @PUT
  109. Observable<GenericOverall> renameRoom(@Header("Authorization") String authorization, @Url String url,
  110. @Field("roomName") String roomName);
  111. /*
  112. QueryMap items are as follows:
  113. - "newParticipant" : "user"
  114. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants
  115. */
  116. @POST
  117. Observable<AddParticipantOverall> addParticipant(@Header("Authorization") String authorization, @Url String url,
  118. @QueryMap Map<String, String> options);
  119. // also used for removing a guest from a conversation
  120. @Deprecated
  121. @DELETE
  122. Observable<GenericOverall> removeParticipantFromConversation(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  123. @DELETE
  124. Observable<GenericOverall> removeAttendeeFromConversation(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  125. @Deprecated
  126. @POST
  127. Observable<GenericOverall> promoteUserToModerator(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  128. @Deprecated
  129. @DELETE
  130. Observable<GenericOverall> demoteModeratorToUser(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  131. @POST
  132. Observable<GenericOverall> promoteAttendeeToModerator(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  133. @DELETE
  134. Observable<GenericOverall> demoteAttendeeFromModerator(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  135. /*
  136. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants/self
  137. */
  138. @DELETE
  139. Observable<GenericOverall> removeSelfFromRoom(@Header("Authorization") String authorization, @Url String url);
  140. /*
  141. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public
  142. */
  143. @POST
  144. Observable<GenericOverall> makeRoomPublic(@Header("Authorization") String authorization, @Url String url);
  145. /*
  146. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public
  147. */
  148. @DELETE
  149. Observable<GenericOverall> makeRoomPrivate(@Header("Authorization") String authorization, @Url String url);
  150. @DELETE
  151. Observable<GenericOverall> deleteRoom(@Header("Authorization") String authorization, @Url String url);
  152. /*
  153. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  154. */
  155. @GET
  156. Observable<ParticipantsOverall> getPeersForCall(@Header("Authorization") String authorization, @Url String url,
  157. @QueryMap Map<String, Boolean> fields);
  158. @FormUrlEncoded
  159. @POST
  160. Observable<RoomOverall> joinRoom(@Nullable @Header("Authorization") String authorization, @Url String url, @Nullable @Field("password") String password);
  161. @DELETE
  162. Observable<GenericOverall> leaveRoom(@Nullable @Header("Authorization") String authorization, @Url String url);
  163. /*
  164. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  165. */
  166. @FormUrlEncoded
  167. @POST
  168. Observable<GenericOverall> joinCall(@Nullable @Header("Authorization") String authorization, @Url String url,
  169. @Field("flags") Integer inCall);
  170. /*
  171. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  172. */
  173. @DELETE
  174. Observable<GenericOverall> leaveCall(@Nullable @Header("Authorization") String authorization, @Url String url);
  175. @GET
  176. Observable<SignalingSettingsOverall> getSignalingSettings(@Nullable @Header("Authorization") String authorization,
  177. @Url String url);
  178. /*
  179. QueryMap items are as follows:
  180. - "messages" : "message"
  181. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling
  182. */
  183. @FormUrlEncoded
  184. @POST
  185. Observable<SignalingOverall> sendSignalingMessages(@Nullable @Header("Authorization") String authorization, @Url String url,
  186. @Field("messages") String messages);
  187. /*
  188. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling
  189. */
  190. @GET
  191. Observable<SignalingOverall> pullSignalingMessages(@Nullable @Header("Authorization") String authorization, @Url
  192. String
  193. url);
  194. /*
  195. QueryMap items are as follows:
  196. - "format" : "json"
  197. Server URL is: baseUrl + ocsApiVersion + "/cloud/user"
  198. */
  199. @GET
  200. Observable<UserProfileOverall> getUserProfile(@Header("Authorization") String authorization, @Url String url);
  201. @GET
  202. Observable<UserProfileOverall> getUserData(@Header("Authorization") String authorization, @Url String url);
  203. @FormUrlEncoded
  204. @PUT
  205. Observable<GenericOverall> setUserData(@Header("Authorization") String authorization, @Url String url,
  206. @Field("key") String key, @Field("value") String value);
  207. /*
  208. Server URL is: baseUrl + /status.php
  209. */
  210. @GET
  211. Observable<Status> getServerStatus(@Url String url);
  212. /*
  213. QueryMap items are as follows:
  214. - "format" : "json"
  215. - "pushTokenHash" : ""
  216. - "devicePublicKey" : ""
  217. - "proxyServer" : ""
  218. Server URL is: baseUrl + ocsApiVersion + "/apps/notifications/api/v2/push
  219. */
  220. @POST
  221. Observable<PushRegistrationOverall> registerDeviceForNotificationsWithNextcloud(@Header("Authorization")
  222. String authorization,
  223. @Url String url,
  224. @QueryMap Map<String,
  225. String> options);
  226. @DELETE
  227. Observable<GenericOverall> unregisterDeviceForNotificationsWithNextcloud(@Header("Authorization")
  228. String authorization,
  229. @Url String url);
  230. @FormUrlEncoded
  231. @POST
  232. Observable<Void> registerDeviceForNotificationsWithPushProxy(@Url String url,
  233. @FieldMap Map<String, String> fields);
  234. /*
  235. QueryMap items are as follows:
  236. - "deviceIdentifier": "{{deviceIdentifier}}",
  237. - "deviceIdentifierSignature": "{{signature}}",
  238. - "userPublicKey": "{{userPublicKey}}"
  239. */
  240. @DELETE
  241. Observable<Void> unregisterDeviceForNotificationsWithProxy(@Url String url,
  242. @QueryMap Map<String, String> fields);
  243. @FormUrlEncoded
  244. @PUT
  245. Observable<GenericOverall> setPassword(@Header("Authorization") String authorization, @Url String url,
  246. @Field("password") String password);
  247. @GET
  248. Observable<CapabilitiesOverall> getCapabilities(@Header("Authorization") String authorization, @Url String url);
  249. /*
  250. QueryMap items are as follows:
  251. - "lookIntoFuture": int (0 or 1),
  252. - "limit" : int, range 100-200,
  253. - "timeout": used with look into future, 30 default, 60 at most
  254. - "lastKnownMessageId", int, use one from X-Chat-Last-Given
  255. */
  256. @GET
  257. Observable<Response<ChatOverall>> pullChatMessages(@Header("Authorization") String authorization, @Url String url,
  258. @QueryMap Map<String, Integer> fields);
  259. /*
  260. Fieldmap items are as follows:
  261. - "message": ,
  262. - "actorDisplayName"
  263. */
  264. @FormUrlEncoded
  265. @POST
  266. Observable<GenericOverall> sendChatMessage(@Header("Authorization") String authorization,
  267. @Url String url,
  268. @Field("message") CharSequence message,
  269. @Field("actorDisplayName") String actorDisplayName,
  270. @Field("replyTo") Integer replyTo);
  271. @GET
  272. Observable<MentionOverall> getMentionAutocompleteSuggestions(@Header("Authorization") String authorization,
  273. @Url String url, @Query("search") String query,
  274. @Nullable @Query("limit") Integer limit);
  275. // Url is: /api/{apiVersion}/room/{token}/pin
  276. @POST
  277. Observable<GenericOverall> addConversationToFavorites(@Header("Authorization") String authorization,
  278. @Url String url);
  279. // Url is: /api/{apiVersion}/room/{token}/favorites
  280. @DELETE
  281. Observable<GenericOverall> removeConversationFromFavorites(@Header("Authorization") String authorization,
  282. @Url String url);
  283. @GET
  284. Observable<NotificationOverall> getNotification(@Header("Authorization") String authorization,
  285. @Url String url);
  286. @FormUrlEncoded
  287. @POST
  288. Observable<GenericOverall> setNotificationLevel(@Header("Authorization") String authorization, @Url String url, @Field("level") int level);
  289. @FormUrlEncoded
  290. @PUT
  291. Observable<GenericOverall> setReadOnlyState(@Header("Authorization") String authorization, @Url String url, @Field("state") int state);
  292. @FormUrlEncoded
  293. @POST
  294. Observable<Void> createRemoteShare(@Nullable @Header("Authorization") String authorization, @Url String url,
  295. @Field("path") String remotePath,
  296. @Field("shareWith") String roomToken,
  297. @Field("shareType") String shareType,
  298. @Field("talkMetaData") String talkMetaData);
  299. @FormUrlEncoded
  300. @PUT
  301. Observable<GenericOverall> setLobbyForConversation(@Header("Authorization") String authorization,
  302. @Url String url, @Field("state") Integer state,
  303. @Field("timer") Long timer);
  304. @POST
  305. Observable<GenericOverall> setReadStatusPrivacy(@Header("Authorization") String authorization,
  306. @Url String url,
  307. @Body RequestBody body);
  308. @POST
  309. Observable<ContactsByNumberOverall> searchContactsByPhoneNumber(@Header("Authorization") String authorization,
  310. @Url String url,
  311. @Body RequestBody search);
  312. @PUT
  313. Observable<Response<GenericOverall>> uploadFile(@Header("Authorization") String authorization,
  314. @Url String url,
  315. @Body RequestBody body);
  316. @GET
  317. Call<ResponseBody> downloadFile(@Header("Authorization") String authorization,
  318. @Url String url);
  319. @DELETE
  320. Observable<ChatOverallSingleMessage> deleteChatMessage(@Header("Authorization") String authorization,
  321. @Url String url);
  322. @DELETE
  323. Observable<GenericOverall> deleteAvatar(@Header("Authorization") String authorization, @Url String url);
  324. @Multipart
  325. @POST
  326. Observable<GenericOverall> uploadAvatar(@Header("Authorization") String authorization,
  327. @Url String url,
  328. @Part MultipartBody.Part attachment);
  329. @GET
  330. Observable<UserProfileFieldsOverall> getEditableUserProfileFields(@Header("Authorization") String authorization,
  331. @Url String url);
  332. @GET
  333. Call<ResponseBody> downloadResizedImage(@Header("Authorization") String authorization,
  334. @Url String url);
  335. @FormUrlEncoded
  336. @POST
  337. Observable<GenericOverall> sendLocation(@Header("Authorization") String authorization,
  338. @Url String url,
  339. @Field("objectType") String objectType,
  340. @Field("objectId") String objectId,
  341. @Field("metaData") String metaData);
  342. @DELETE
  343. Observable<GenericOverall> clearChatHistory(@Header("Authorization") String authorization, @Url String url);
  344. @FormUrlEncoded
  345. @POST
  346. Observable<GenericOverall> notificationCalls(@Header("Authorization") String authorization, @Url String url,
  347. @Field("level") Integer level);
  348. @GET
  349. Observable<HoverCardOverall> hoverCard(@Header("Authorization") String authorization, @Url String url);
  350. // Url is: /api/{apiVersion}/chat/{token}/read
  351. @FormUrlEncoded
  352. @POST
  353. Observable<GenericOverall> setChatReadMarker(@Header("Authorization") String authorization,
  354. @Url String url,
  355. @Field("lastReadMessage") int lastReadMessage);
  356. /*
  357. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /listed-room
  358. */
  359. @GET
  360. Observable<RoomsOverall> getOpenConversations(@Header("Authorization") String authorization, @Url String url);
  361. /*
  362. * OCS Status API
  363. */
  364. @GET
  365. Observable<StatusOverall> status(@Header("Authorization") String authorization, @Url String url);
  366. @GET
  367. Observable<ResponseBody> getPredefinedStatuses(@Header("Authorization") String authorization, @Url String url);
  368. @DELETE
  369. Observable<GenericOverall> statusDeleteMessage(@Header("Authorization") String authorization, @Url String url);
  370. @FormUrlEncoded
  371. @PUT
  372. Observable<GenericOverall> setPredefinedStatusMessage(@Header("Authorization") String authorization,
  373. @Url String url,
  374. @Field("messageId") String selectedPredefinedMessageId,
  375. @Field("clearAt") Long clearAt);
  376. @FormUrlEncoded
  377. @PUT
  378. Observable<GenericOverall> setCustomStatusMessage(@Header("Authorization") String authorization,
  379. @Url String url,
  380. @Field("statusIcon") String statusIcon,
  381. @Field("message") String message,
  382. @Field("clearAt") Long clearAt);
  383. @FormUrlEncoded
  384. @PUT
  385. Observable<GenericOverall> setStatusType(@Header("Authorization") String authorization,
  386. @Url String url,
  387. @Field("statusType") String statusType);
  388. @GET
  389. Observable<StatusesOverall> getUserStatuses(@Header("Authorization") String authorization, @Url String url);
  390. }