NcApi.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * Nextcloud Talk application
  3. *
  4. * @author Mario Danic
  5. * @author Marcel Hibbe
  6. * @author Tim Krüger
  7. * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
  8. * Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
  9. * Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. package com.nextcloud.talk.api;
  25. import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall;
  26. import com.nextcloud.talk.models.json.chat.ChatOverall;
  27. import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage;
  28. import com.nextcloud.talk.models.json.chat.ChatShareOverall;
  29. import com.nextcloud.talk.models.json.chat.ChatShareOverviewOverall;
  30. import com.nextcloud.talk.models.json.conversations.RoomOverall;
  31. import com.nextcloud.talk.models.json.conversations.RoomsOverall;
  32. import com.nextcloud.talk.models.json.generic.GenericOverall;
  33. import com.nextcloud.talk.models.json.generic.Status;
  34. import com.nextcloud.talk.models.json.hovercard.HoverCardOverall;
  35. import com.nextcloud.talk.models.json.mention.MentionOverall;
  36. import com.nextcloud.talk.models.json.notifications.NotificationOverall;
  37. import com.nextcloud.talk.models.json.opengraph.OpenGraphOverall;
  38. import com.nextcloud.talk.models.json.participants.AddParticipantOverall;
  39. import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
  40. import com.nextcloud.talk.models.json.push.PushRegistrationOverall;
  41. import com.nextcloud.talk.models.json.reactions.ReactionsOverall;
  42. import com.nextcloud.talk.models.json.search.ContactsByNumberOverall;
  43. import com.nextcloud.talk.models.json.signaling.SignalingOverall;
  44. import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
  45. import com.nextcloud.talk.models.json.status.StatusOverall;
  46. import com.nextcloud.talk.models.json.unifiedsearch.UnifiedSearchOverall;
  47. import com.nextcloud.talk.models.json.userprofile.UserProfileFieldsOverall;
  48. import com.nextcloud.talk.models.json.userprofile.UserProfileOverall;
  49. import com.nextcloud.talk.polls.repositories.model.PollOverall;
  50. import java.util.List;
  51. import java.util.Map;
  52. import androidx.annotation.Nullable;
  53. import io.reactivex.Observable;
  54. import okhttp3.MultipartBody;
  55. import okhttp3.RequestBody;
  56. import okhttp3.ResponseBody;
  57. import retrofit2.Call;
  58. import retrofit2.Response;
  59. import retrofit2.http.Body;
  60. import retrofit2.http.DELETE;
  61. import retrofit2.http.Field;
  62. import retrofit2.http.FieldMap;
  63. import retrofit2.http.FormUrlEncoded;
  64. import retrofit2.http.GET;
  65. import retrofit2.http.HEAD;
  66. import retrofit2.http.Header;
  67. import retrofit2.http.Multipart;
  68. import retrofit2.http.POST;
  69. import retrofit2.http.PUT;
  70. import retrofit2.http.Part;
  71. import retrofit2.http.Query;
  72. import retrofit2.http.QueryMap;
  73. import retrofit2.http.Url;
  74. public interface NcApi {
  75. /*
  76. QueryMap items are as follows:
  77. - "format" : "json"
  78. - "search" : ""
  79. - "perPage" : "200"
  80. - "itemType" : "call"
  81. Server URL is: baseUrl + ocsApiVersion + /apps/files_sharing/api/v1/sharees
  82. or if we're on 14 and up:
  83. baseUrl + ocsApiVersion + "/core/autocomplete/get");
  84. */
  85. @GET
  86. Observable<ResponseBody> getContactsWithSearchParam(@Header("Authorization") String authorization, @Url String url,
  87. @Nullable @Query("shareTypes[]") List<String> listOfShareTypes, @QueryMap Map<String, Object> options);
  88. /*
  89. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room
  90. */
  91. @GET
  92. Observable<RoomsOverall> getRooms(@Header("Authorization") String authorization, @Url String url,
  93. @Nullable @Query("includeStatus") Boolean includeStatus);
  94. /*
  95. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
  96. */
  97. @GET
  98. Observable<RoomOverall> getRoom(@Header("Authorization") String authorization, @Url String url);
  99. /*
  100. QueryMap items are as follows:
  101. - "roomType" : ""
  102. - "invite" : ""
  103. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room
  104. */
  105. @POST
  106. Observable<RoomOverall> createRoom(@Header("Authorization") String authorization, @Url String url,
  107. @QueryMap Map<String, String> options);
  108. /*
  109. QueryMap items are as follows:
  110. - "roomName" : "newName"
  111. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
  112. */
  113. @FormUrlEncoded
  114. @PUT
  115. Observable<GenericOverall> renameRoom(@Header("Authorization") String authorization, @Url String url,
  116. @Field("roomName") String roomName);
  117. /*
  118. QueryMap items are as follows:
  119. - "newParticipant" : "user"
  120. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants
  121. */
  122. @POST
  123. Observable<AddParticipantOverall> addParticipant(@Header("Authorization") String authorization, @Url String url,
  124. @QueryMap Map<String, String> options);
  125. @POST
  126. Observable<GenericOverall> resendParticipantInvitations(@Header("Authorization") String authorization,
  127. @Url String url);
  128. // also used for removing a guest from a conversation
  129. @Deprecated
  130. @DELETE
  131. Observable<GenericOverall> removeParticipantFromConversation(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  132. @DELETE
  133. Observable<GenericOverall> removeAttendeeFromConversation(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  134. @Deprecated
  135. @POST
  136. Observable<GenericOverall> promoteUserToModerator(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  137. @Deprecated
  138. @DELETE
  139. Observable<GenericOverall> demoteModeratorToUser(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  140. @POST
  141. Observable<GenericOverall> promoteAttendeeToModerator(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  142. @DELETE
  143. Observable<GenericOverall> demoteAttendeeFromModerator(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  144. /*
  145. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants/self
  146. */
  147. @DELETE
  148. Observable<GenericOverall> removeSelfFromRoom(@Header("Authorization") String authorization, @Url String url);
  149. /*
  150. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public
  151. */
  152. @POST
  153. Observable<GenericOverall> makeRoomPublic(@Header("Authorization") String authorization, @Url String url);
  154. /*
  155. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public
  156. */
  157. @DELETE
  158. Observable<GenericOverall> makeRoomPrivate(@Header("Authorization") String authorization, @Url String url);
  159. @DELETE
  160. Observable<GenericOverall> deleteRoom(@Header("Authorization") String authorization, @Url String url);
  161. /*
  162. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  163. */
  164. @GET
  165. Observable<ParticipantsOverall> getPeersForCall(@Header("Authorization") String authorization, @Url String url);
  166. @GET
  167. Observable<ParticipantsOverall> getPeersForCall(@Header("Authorization") String authorization, @Url String url,
  168. @QueryMap Map<String, Boolean> fields);
  169. @FormUrlEncoded
  170. @POST
  171. Observable<RoomOverall> joinRoom(@Nullable @Header("Authorization") String authorization, @Url String url, @Nullable @Field("password") String password);
  172. @DELETE
  173. Observable<GenericOverall> leaveRoom(@Nullable @Header("Authorization") String authorization, @Url String url);
  174. /*
  175. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  176. */
  177. @FormUrlEncoded
  178. @POST
  179. Observable<GenericOverall> joinCall(@Nullable @Header("Authorization") String authorization, @Url String url,
  180. @Field("flags") Integer inCall,
  181. @Field("silent") Boolean callWithoutNotification);
  182. /*
  183. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  184. */
  185. @DELETE
  186. Observable<GenericOverall> leaveCall(@Nullable @Header("Authorization") String authorization, @Url String url);
  187. @GET
  188. Observable<SignalingSettingsOverall> getSignalingSettings(@Nullable @Header("Authorization") String authorization,
  189. @Url String url);
  190. /*
  191. QueryMap items are as follows:
  192. - "messages" : "message"
  193. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling
  194. */
  195. @FormUrlEncoded
  196. @POST
  197. Observable<SignalingOverall> sendSignalingMessages(@Nullable @Header("Authorization") String authorization, @Url String url,
  198. @Field("messages") String messages);
  199. /*
  200. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling
  201. */
  202. @GET
  203. Observable<SignalingOverall> pullSignalingMessages(@Nullable @Header("Authorization") String authorization, @Url
  204. String
  205. url);
  206. /*
  207. QueryMap items are as follows:
  208. - "format" : "json"
  209. Server URL is: baseUrl + ocsApiVersion + "/cloud/user"
  210. */
  211. @GET
  212. Observable<UserProfileOverall> getUserProfile(@Header("Authorization") String authorization, @Url String url);
  213. @GET
  214. Observable<UserProfileOverall> getUserData(@Header("Authorization") String authorization, @Url String url);
  215. @FormUrlEncoded
  216. @PUT
  217. Observable<GenericOverall> setUserData(@Header("Authorization") String authorization, @Url String url,
  218. @Field("key") String key, @Field("value") String value);
  219. /*
  220. Server URL is: baseUrl + /status.php
  221. */
  222. @GET
  223. Observable<Status> getServerStatus(@Url String url);
  224. /*
  225. QueryMap items are as follows:
  226. - "format" : "json"
  227. - "pushTokenHash" : ""
  228. - "devicePublicKey" : ""
  229. - "proxyServer" : ""
  230. Server URL is: baseUrl + ocsApiVersion + "/apps/notifications/api/v2/push
  231. */
  232. @POST
  233. Observable<PushRegistrationOverall> registerDeviceForNotificationsWithNextcloud(@Header("Authorization")
  234. String authorization,
  235. @Url String url,
  236. @QueryMap Map<String,
  237. String> options);
  238. @DELETE
  239. Observable<GenericOverall> unregisterDeviceForNotificationsWithNextcloud(@Header("Authorization")
  240. String authorization,
  241. @Url String url);
  242. @FormUrlEncoded
  243. @POST
  244. Observable<Void> registerDeviceForNotificationsWithPushProxy(@Url String url,
  245. @FieldMap Map<String, String> fields);
  246. /*
  247. QueryMap items are as follows:
  248. - "deviceIdentifier": "{{deviceIdentifier}}",
  249. - "deviceIdentifierSignature": "{{signature}}",
  250. - "userPublicKey": "{{userPublicKey}}"
  251. */
  252. @DELETE
  253. Observable<Void> unregisterDeviceForNotificationsWithProxy(@Url String url,
  254. @QueryMap Map<String, String> fields);
  255. @FormUrlEncoded
  256. @PUT
  257. Observable<GenericOverall> setPassword(@Header("Authorization") String authorization, @Url String url,
  258. @Field("password") String password);
  259. @FormUrlEncoded
  260. @PUT
  261. Observable<Response<GenericOverall>> setPassword2(@Header("Authorization") String authorization,
  262. @Url String url,
  263. @Field("password") String password);
  264. @GET
  265. Observable<CapabilitiesOverall> getCapabilities(@Header("Authorization") String authorization, @Url String url);
  266. /*
  267. QueryMap items are as follows:
  268. - "lookIntoFuture": int (0 or 1),
  269. - "limit" : int, range 100-200,
  270. - "timeout": used with look into future, 30 default, 60 at most
  271. - "lastKnownMessageId", int, use one from X-Chat-Last-Given
  272. */
  273. @GET
  274. Observable<Response<ChatOverall>> pullChatMessages(@Header("Authorization") String authorization, @Url String url,
  275. @QueryMap Map<String, Integer> fields);
  276. /*
  277. Fieldmap items are as follows:
  278. - "message": ,
  279. - "actorDisplayName"
  280. */
  281. @FormUrlEncoded
  282. @POST
  283. Observable<GenericOverall> sendChatMessage(@Header("Authorization") String authorization,
  284. @Url String url,
  285. @Field("message") CharSequence message,
  286. @Field("actorDisplayName") String actorDisplayName,
  287. @Field("replyTo") Integer replyTo,
  288. @Field("silent") Boolean sendWithoutNotification);
  289. @GET
  290. Observable<Response<ChatShareOverall>> getSharedItems(@Header("Authorization") String authorization, @Url String url,
  291. @Query("objectType") String objectType,
  292. @Nullable @Query("lastKnownMessageId") Integer lastKnownMessageId,
  293. @Nullable @Query("limit") Integer limit);
  294. @GET
  295. Observable<Response<ChatShareOverviewOverall>> getSharedItemsOverview(@Header("Authorization") String authorization,
  296. @Url String url,
  297. @Nullable @Query("limit") Integer limit);
  298. @GET
  299. Observable<MentionOverall> getMentionAutocompleteSuggestions(@Header("Authorization") String authorization,
  300. @Url String url, @Query("search") String query,
  301. @Nullable @Query("limit") Integer limit,
  302. @QueryMap Map<String, String> fields);
  303. // Url is: /api/{apiVersion}/room/{token}/pin
  304. @POST
  305. Observable<GenericOverall> addConversationToFavorites(@Header("Authorization") String authorization,
  306. @Url String url);
  307. // Url is: /api/{apiVersion}/room/{token}/favorites
  308. @DELETE
  309. Observable<GenericOverall> removeConversationFromFavorites(@Header("Authorization") String authorization,
  310. @Url String url);
  311. @GET
  312. Observable<NotificationOverall> getNotification(@Header("Authorization") String authorization,
  313. @Url String url);
  314. @FormUrlEncoded
  315. @POST
  316. Observable<GenericOverall> setNotificationLevel(@Header("Authorization") String authorization, @Url String url, @Field("level") int level);
  317. @FormUrlEncoded
  318. @PUT
  319. Observable<GenericOverall> setReadOnlyState(@Header("Authorization") String authorization, @Url String url, @Field("state") int state);
  320. @FormUrlEncoded
  321. @POST
  322. Observable<GenericOverall> createRemoteShare(@Nullable @Header("Authorization") String authorization, @Url String url,
  323. @Field("path") String remotePath,
  324. @Field("shareWith") String roomToken,
  325. @Field("shareType") String shareType,
  326. @Field("talkMetaData") String talkMetaData);
  327. @FormUrlEncoded
  328. @PUT
  329. Observable<GenericOverall> setLobbyForConversation(@Header("Authorization") String authorization,
  330. @Url String url, @Field("state") Integer state,
  331. @Field("timer") Long timer);
  332. @POST
  333. Observable<GenericOverall> setReadStatusPrivacy(@Header("Authorization") String authorization,
  334. @Url String url,
  335. @Body RequestBody body);
  336. @POST
  337. Observable<ContactsByNumberOverall> searchContactsByPhoneNumber(@Header("Authorization") String authorization,
  338. @Url String url,
  339. @Body RequestBody search);
  340. @PUT
  341. Observable<Response<GenericOverall>> uploadFile(@Header("Authorization") String authorization,
  342. @Url String url,
  343. @Body RequestBody body);
  344. @HEAD
  345. Observable<Response<Void>> checkIfFileExists(@Header("Authorization") String authorization,
  346. @Url String url);
  347. @GET
  348. Call<ResponseBody> downloadFile(@Header("Authorization") String authorization,
  349. @Url String url);
  350. @DELETE
  351. Observable<ChatOverallSingleMessage> deleteChatMessage(@Header("Authorization") String authorization,
  352. @Url String url);
  353. @DELETE
  354. Observable<GenericOverall> deleteAvatar(@Header("Authorization") String authorization, @Url String url);
  355. @Multipart
  356. @POST
  357. Observable<GenericOverall> uploadAvatar(@Header("Authorization") String authorization,
  358. @Url String url,
  359. @Part MultipartBody.Part attachment);
  360. @GET
  361. Observable<UserProfileFieldsOverall> getEditableUserProfileFields(@Header("Authorization") String authorization,
  362. @Url String url);
  363. @GET
  364. Call<ResponseBody> downloadResizedImage(@Header("Authorization") String authorization,
  365. @Url String url);
  366. @FormUrlEncoded
  367. @POST
  368. Observable<GenericOverall> sendLocation(@Header("Authorization") String authorization,
  369. @Url String url,
  370. @Field("objectType") String objectType,
  371. @Field("objectId") String objectId,
  372. @Field("metaData") String metaData);
  373. @DELETE
  374. Observable<GenericOverall> clearChatHistory(@Header("Authorization") String authorization, @Url String url);
  375. @FormUrlEncoded
  376. @POST
  377. Observable<GenericOverall> notificationCalls(@Header("Authorization") String authorization, @Url String url,
  378. @Field("level") Integer level);
  379. @GET
  380. Observable<HoverCardOverall> hoverCard(@Header("Authorization") String authorization, @Url String url);
  381. // Url is: /api/{apiVersion}/chat/{token}/read
  382. @FormUrlEncoded
  383. @POST
  384. Observable<GenericOverall> setChatReadMarker(@Header("Authorization") String authorization,
  385. @Url String url,
  386. @Field("lastReadMessage") int lastReadMessage);
  387. /*
  388. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /listed-room
  389. */
  390. @GET
  391. Observable<RoomsOverall> getOpenConversations(@Header("Authorization") String authorization, @Url String url);
  392. /*
  393. * OCS Status API
  394. */
  395. @GET
  396. Observable<StatusOverall> status(@Header("Authorization") String authorization, @Url String url);
  397. @GET
  398. Observable<ResponseBody> getPredefinedStatuses(@Header("Authorization") String authorization, @Url String url);
  399. @DELETE
  400. Observable<GenericOverall> statusDeleteMessage(@Header("Authorization") String authorization, @Url String url);
  401. @FormUrlEncoded
  402. @PUT
  403. Observable<GenericOverall> setPredefinedStatusMessage(@Header("Authorization") String authorization,
  404. @Url String url,
  405. @Field("messageId") String selectedPredefinedMessageId,
  406. @Field("clearAt") Long clearAt);
  407. @FormUrlEncoded
  408. @PUT
  409. Observable<GenericOverall> setCustomStatusMessage(@Header("Authorization") String authorization,
  410. @Url String url,
  411. @Field("statusIcon") String statusIcon,
  412. @Field("message") String message,
  413. @Field("clearAt") Long clearAt);
  414. @FormUrlEncoded
  415. @PUT
  416. Observable<GenericOverall> setStatusType(@Header("Authorization") String authorization,
  417. @Url String url,
  418. @Field("statusType") String statusType);
  419. @POST
  420. Observable<GenericOverall> sendReaction(@Header("Authorization") String authorization, @Url String url,
  421. @Query("reaction") String reaction);
  422. @DELETE
  423. Observable<GenericOverall> deleteReaction(@Header("Authorization") String authorization, @Url String url,
  424. @Query("reaction") String reaction);
  425. @GET
  426. Observable<ReactionsOverall> getReactions(@Header("Authorization") String authorization,
  427. @Url String url,
  428. @Query("reaction") String reaction);
  429. @GET
  430. Observable<UnifiedSearchOverall> performUnifiedSearch(@Header("Authorization") String authorization,
  431. @Url String url,
  432. @Query("term") String term,
  433. @Query("from") String fromUrl,
  434. @Query("limit") Integer limit,
  435. @Query("cursor") Integer cursor);
  436. @GET
  437. Observable<PollOverall> getPoll(@Header("Authorization") String authorization,
  438. @Url String url);
  439. @FormUrlEncoded
  440. @POST
  441. Observable<PollOverall> createPoll(@Header("Authorization") String authorization,
  442. @Url String url,
  443. @Query("question") String question,
  444. @Field("options[]") List<String> options,
  445. @Query("resultMode") Integer resultMode,
  446. @Query("maxVotes") Integer maxVotes);
  447. @FormUrlEncoded
  448. @POST
  449. Observable<PollOverall> votePoll(@Header("Authorization") String authorization,
  450. @Url String url,
  451. @Field("optionIds[]") List<Integer> optionIds);
  452. @DELETE
  453. Observable<PollOverall> closePoll(@Header("Authorization") String authorization,
  454. @Url String url);
  455. @FormUrlEncoded
  456. @POST
  457. Observable<GenericOverall> setMessageExpiration(@Header("Authorization") String authorization,
  458. @Url String url,
  459. @Field("seconds") Integer seconds);
  460. @GET
  461. Observable<OpenGraphOverall> getOpenGraph(@Header("Authorization") String authorization,
  462. @Url String url,
  463. @Query("reference") String urlToFindPreviewFor);
  464. @FormUrlEncoded
  465. @POST
  466. Observable<GenericOverall> startRecording(@Header("Authorization") String authorization,
  467. @Url String url,
  468. @Field("status") Integer status);
  469. @DELETE
  470. Observable<GenericOverall> stopRecording(@Header("Authorization") String authorization,
  471. @Url String url);
  472. }