NcApi.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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.participants.AddParticipantOverall;
  38. import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
  39. import com.nextcloud.talk.models.json.push.PushRegistrationOverall;
  40. import com.nextcloud.talk.models.json.reactions.ReactionsOverall;
  41. import com.nextcloud.talk.models.json.search.ContactsByNumberOverall;
  42. import com.nextcloud.talk.models.json.signaling.SignalingOverall;
  43. import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
  44. import com.nextcloud.talk.models.json.status.StatusOverall;
  45. import com.nextcloud.talk.models.json.statuses.StatusesOverall;
  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. /*
  94. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
  95. */
  96. @GET
  97. Observable<RoomOverall> getRoom(@Header("Authorization") String authorization, @Url String url);
  98. /*
  99. QueryMap items are as follows:
  100. - "roomType" : ""
  101. - "invite" : ""
  102. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room
  103. */
  104. @POST
  105. Observable<RoomOverall> createRoom(@Header("Authorization") String authorization, @Url String url,
  106. @QueryMap Map<String, String> options);
  107. /*
  108. QueryMap items are as follows:
  109. - "roomName" : "newName"
  110. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
  111. */
  112. @FormUrlEncoded
  113. @PUT
  114. Observable<GenericOverall> renameRoom(@Header("Authorization") String authorization, @Url String url,
  115. @Field("roomName") String roomName);
  116. /*
  117. QueryMap items are as follows:
  118. - "newParticipant" : "user"
  119. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants
  120. */
  121. @POST
  122. Observable<AddParticipantOverall> addParticipant(@Header("Authorization") String authorization, @Url String url,
  123. @QueryMap Map<String, String> options);
  124. @POST
  125. Observable<GenericOverall> resendParticipantInvitations(@Header("Authorization") String authorization,
  126. @Url String url);
  127. // also used for removing a guest from a conversation
  128. @Deprecated
  129. @DELETE
  130. Observable<GenericOverall> removeParticipantFromConversation(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  131. @DELETE
  132. Observable<GenericOverall> removeAttendeeFromConversation(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  133. @Deprecated
  134. @POST
  135. Observable<GenericOverall> promoteUserToModerator(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  136. @Deprecated
  137. @DELETE
  138. Observable<GenericOverall> demoteModeratorToUser(@Header("Authorization") String authorization, @Url String url, @Query("participant") String participantId);
  139. @POST
  140. Observable<GenericOverall> promoteAttendeeToModerator(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  141. @DELETE
  142. Observable<GenericOverall> demoteAttendeeFromModerator(@Header("Authorization") String authorization, @Url String url, @Query("attendeeId") Long attendeeId);
  143. /*
  144. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants/self
  145. */
  146. @DELETE
  147. Observable<GenericOverall> removeSelfFromRoom(@Header("Authorization") String authorization, @Url String url);
  148. /*
  149. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public
  150. */
  151. @POST
  152. Observable<GenericOverall> makeRoomPublic(@Header("Authorization") String authorization, @Url String url);
  153. /*
  154. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public
  155. */
  156. @DELETE
  157. Observable<GenericOverall> makeRoomPrivate(@Header("Authorization") String authorization, @Url String url);
  158. @DELETE
  159. Observable<GenericOverall> deleteRoom(@Header("Authorization") String authorization, @Url String url);
  160. /*
  161. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  162. */
  163. @GET
  164. Observable<ParticipantsOverall> getPeersForCall(@Header("Authorization") String authorization, @Url String url);
  165. @GET
  166. Observable<ParticipantsOverall> getPeersForCall(@Header("Authorization") String authorization, @Url String url,
  167. @QueryMap Map<String, Boolean> fields);
  168. @FormUrlEncoded
  169. @POST
  170. Observable<RoomOverall> joinRoom(@Nullable @Header("Authorization") String authorization, @Url String url, @Nullable @Field("password") String password);
  171. @DELETE
  172. Observable<GenericOverall> leaveRoom(@Nullable @Header("Authorization") String authorization, @Url String url);
  173. /*
  174. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  175. */
  176. @FormUrlEncoded
  177. @POST
  178. Observable<GenericOverall> joinCall(@Nullable @Header("Authorization") String authorization, @Url String url,
  179. @Field("flags") Integer inCall,
  180. @Field("silent") Boolean callWithoutNotification);
  181. /*
  182. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
  183. */
  184. @DELETE
  185. Observable<GenericOverall> leaveCall(@Nullable @Header("Authorization") String authorization, @Url String url);
  186. @GET
  187. Observable<SignalingSettingsOverall> getSignalingSettings(@Nullable @Header("Authorization") String authorization,
  188. @Url String url);
  189. /*
  190. QueryMap items are as follows:
  191. - "messages" : "message"
  192. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling
  193. */
  194. @FormUrlEncoded
  195. @POST
  196. Observable<SignalingOverall> sendSignalingMessages(@Nullable @Header("Authorization") String authorization, @Url String url,
  197. @Field("messages") String messages);
  198. /*
  199. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling
  200. */
  201. @GET
  202. Observable<SignalingOverall> pullSignalingMessages(@Nullable @Header("Authorization") String authorization, @Url
  203. String
  204. url);
  205. /*
  206. QueryMap items are as follows:
  207. - "format" : "json"
  208. Server URL is: baseUrl + ocsApiVersion + "/cloud/user"
  209. */
  210. @GET
  211. Observable<UserProfileOverall> getUserProfile(@Header("Authorization") String authorization, @Url String url);
  212. @GET
  213. Observable<UserProfileOverall> getUserData(@Header("Authorization") String authorization, @Url String url);
  214. @FormUrlEncoded
  215. @PUT
  216. Observable<GenericOverall> setUserData(@Header("Authorization") String authorization, @Url String url,
  217. @Field("key") String key, @Field("value") String value);
  218. /*
  219. Server URL is: baseUrl + /status.php
  220. */
  221. @GET
  222. Observable<Status> getServerStatus(@Url String url);
  223. /*
  224. QueryMap items are as follows:
  225. - "format" : "json"
  226. - "pushTokenHash" : ""
  227. - "devicePublicKey" : ""
  228. - "proxyServer" : ""
  229. Server URL is: baseUrl + ocsApiVersion + "/apps/notifications/api/v2/push
  230. */
  231. @POST
  232. Observable<PushRegistrationOverall> registerDeviceForNotificationsWithNextcloud(@Header("Authorization")
  233. String authorization,
  234. @Url String url,
  235. @QueryMap Map<String,
  236. String> options);
  237. @DELETE
  238. Observable<GenericOverall> unregisterDeviceForNotificationsWithNextcloud(@Header("Authorization")
  239. String authorization,
  240. @Url String url);
  241. @FormUrlEncoded
  242. @POST
  243. Observable<Void> registerDeviceForNotificationsWithPushProxy(@Url String url,
  244. @FieldMap Map<String, String> fields);
  245. /*
  246. QueryMap items are as follows:
  247. - "deviceIdentifier": "{{deviceIdentifier}}",
  248. - "deviceIdentifierSignature": "{{signature}}",
  249. - "userPublicKey": "{{userPublicKey}}"
  250. */
  251. @DELETE
  252. Observable<Void> unregisterDeviceForNotificationsWithProxy(@Url String url,
  253. @QueryMap Map<String, String> fields);
  254. @FormUrlEncoded
  255. @PUT
  256. Observable<GenericOverall> setPassword(@Header("Authorization") String authorization, @Url String url,
  257. @Field("password") String password);
  258. @FormUrlEncoded
  259. @PUT
  260. Observable<Response<GenericOverall>> setPassword2(@Header("Authorization") String authorization,
  261. @Url String url,
  262. @Field("password") String password);
  263. @GET
  264. Observable<CapabilitiesOverall> getCapabilities(@Header("Authorization") String authorization, @Url String url);
  265. /*
  266. QueryMap items are as follows:
  267. - "lookIntoFuture": int (0 or 1),
  268. - "limit" : int, range 100-200,
  269. - "timeout": used with look into future, 30 default, 60 at most
  270. - "lastKnownMessageId", int, use one from X-Chat-Last-Given
  271. */
  272. @GET
  273. Observable<Response<ChatOverall>> pullChatMessages(@Header("Authorization") String authorization, @Url String url,
  274. @QueryMap Map<String, Integer> fields);
  275. /*
  276. Fieldmap items are as follows:
  277. - "message": ,
  278. - "actorDisplayName"
  279. */
  280. @FormUrlEncoded
  281. @POST
  282. Observable<GenericOverall> sendChatMessage(@Header("Authorization") String authorization,
  283. @Url String url,
  284. @Field("message") CharSequence message,
  285. @Field("actorDisplayName") String actorDisplayName,
  286. @Field("replyTo") Integer replyTo,
  287. @Field("silent") Boolean sendWithoutNotification);
  288. @GET
  289. Observable<Response<ChatShareOverall>> getSharedItems(@Header("Authorization") String authorization, @Url String url,
  290. @Query("objectType") String objectType,
  291. @Nullable @Query("lastKnownMessageId") Integer lastKnownMessageId,
  292. @Nullable @Query("limit") Integer limit);
  293. @GET
  294. Observable<Response<ChatShareOverviewOverall>> getSharedItemsOverview(@Header("Authorization") String authorization,
  295. @Url String url,
  296. @Nullable @Query("limit") Integer limit);
  297. @GET
  298. Observable<MentionOverall> getMentionAutocompleteSuggestions(@Header("Authorization") String authorization,
  299. @Url String url, @Query("search") String query,
  300. @Nullable @Query("limit") Integer limit,
  301. @QueryMap Map<String, String> fields);
  302. // Url is: /api/{apiVersion}/room/{token}/pin
  303. @POST
  304. Observable<GenericOverall> addConversationToFavorites(@Header("Authorization") String authorization,
  305. @Url String url);
  306. // Url is: /api/{apiVersion}/room/{token}/favorites
  307. @DELETE
  308. Observable<GenericOverall> removeConversationFromFavorites(@Header("Authorization") String authorization,
  309. @Url String url);
  310. @GET
  311. Observable<NotificationOverall> getNotification(@Header("Authorization") String authorization,
  312. @Url String url);
  313. @FormUrlEncoded
  314. @POST
  315. Observable<GenericOverall> setNotificationLevel(@Header("Authorization") String authorization, @Url String url, @Field("level") int level);
  316. @FormUrlEncoded
  317. @PUT
  318. Observable<GenericOverall> setReadOnlyState(@Header("Authorization") String authorization, @Url String url, @Field("state") int state);
  319. @FormUrlEncoded
  320. @POST
  321. Observable<GenericOverall> createRemoteShare(@Nullable @Header("Authorization") String authorization, @Url String url,
  322. @Field("path") String remotePath,
  323. @Field("shareWith") String roomToken,
  324. @Field("shareType") String shareType,
  325. @Field("talkMetaData") String talkMetaData);
  326. @FormUrlEncoded
  327. @PUT
  328. Observable<GenericOverall> setLobbyForConversation(@Header("Authorization") String authorization,
  329. @Url String url, @Field("state") Integer state,
  330. @Field("timer") Long timer);
  331. @POST
  332. Observable<GenericOverall> setReadStatusPrivacy(@Header("Authorization") String authorization,
  333. @Url String url,
  334. @Body RequestBody body);
  335. @POST
  336. Observable<ContactsByNumberOverall> searchContactsByPhoneNumber(@Header("Authorization") String authorization,
  337. @Url String url,
  338. @Body RequestBody search);
  339. @PUT
  340. Observable<Response<GenericOverall>> uploadFile(@Header("Authorization") String authorization,
  341. @Url String url,
  342. @Body RequestBody body);
  343. @HEAD
  344. Observable<Response<Void>> checkIfFileExists(@Header("Authorization") String authorization,
  345. @Url String url);
  346. @GET
  347. Call<ResponseBody> downloadFile(@Header("Authorization") String authorization,
  348. @Url String url);
  349. @DELETE
  350. Observable<ChatOverallSingleMessage> deleteChatMessage(@Header("Authorization") String authorization,
  351. @Url String url);
  352. @DELETE
  353. Observable<GenericOverall> deleteAvatar(@Header("Authorization") String authorization, @Url String url);
  354. @Multipart
  355. @POST
  356. Observable<GenericOverall> uploadAvatar(@Header("Authorization") String authorization,
  357. @Url String url,
  358. @Part MultipartBody.Part attachment);
  359. @GET
  360. Observable<UserProfileFieldsOverall> getEditableUserProfileFields(@Header("Authorization") String authorization,
  361. @Url String url);
  362. @GET
  363. Call<ResponseBody> downloadResizedImage(@Header("Authorization") String authorization,
  364. @Url String url);
  365. @FormUrlEncoded
  366. @POST
  367. Observable<GenericOverall> sendLocation(@Header("Authorization") String authorization,
  368. @Url String url,
  369. @Field("objectType") String objectType,
  370. @Field("objectId") String objectId,
  371. @Field("metaData") String metaData);
  372. @DELETE
  373. Observable<GenericOverall> clearChatHistory(@Header("Authorization") String authorization, @Url String url);
  374. @FormUrlEncoded
  375. @POST
  376. Observable<GenericOverall> notificationCalls(@Header("Authorization") String authorization, @Url String url,
  377. @Field("level") Integer level);
  378. @GET
  379. Observable<HoverCardOverall> hoverCard(@Header("Authorization") String authorization, @Url String url);
  380. // Url is: /api/{apiVersion}/chat/{token}/read
  381. @FormUrlEncoded
  382. @POST
  383. Observable<GenericOverall> setChatReadMarker(@Header("Authorization") String authorization,
  384. @Url String url,
  385. @Field("lastReadMessage") int lastReadMessage);
  386. /*
  387. Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /listed-room
  388. */
  389. @GET
  390. Observable<RoomsOverall> getOpenConversations(@Header("Authorization") String authorization, @Url String url);
  391. /*
  392. * OCS Status API
  393. */
  394. @GET
  395. Observable<StatusOverall> status(@Header("Authorization") String authorization, @Url String url);
  396. @GET
  397. Observable<ResponseBody> getPredefinedStatuses(@Header("Authorization") String authorization, @Url String url);
  398. @DELETE
  399. Observable<GenericOverall> statusDeleteMessage(@Header("Authorization") String authorization, @Url String url);
  400. @FormUrlEncoded
  401. @PUT
  402. Observable<GenericOverall> setPredefinedStatusMessage(@Header("Authorization") String authorization,
  403. @Url String url,
  404. @Field("messageId") String selectedPredefinedMessageId,
  405. @Field("clearAt") Long clearAt);
  406. @FormUrlEncoded
  407. @PUT
  408. Observable<GenericOverall> setCustomStatusMessage(@Header("Authorization") String authorization,
  409. @Url String url,
  410. @Field("statusIcon") String statusIcon,
  411. @Field("message") String message,
  412. @Field("clearAt") Long clearAt);
  413. @FormUrlEncoded
  414. @PUT
  415. Observable<GenericOverall> setStatusType(@Header("Authorization") String authorization,
  416. @Url String url,
  417. @Field("statusType") String statusType);
  418. @GET
  419. Observable<StatusesOverall> getUserStatuses(@Header("Authorization") String authorization, @Url String url);
  420. @POST
  421. Observable<GenericOverall> sendReaction(@Header("Authorization") String authorization, @Url String url,
  422. @Query("reaction") String reaction);
  423. @DELETE
  424. Observable<GenericOverall> deleteReaction(@Header("Authorization") String authorization, @Url String url,
  425. @Query("reaction") String reaction);
  426. @GET
  427. Observable<ReactionsOverall> getReactions(@Header("Authorization") String authorization,
  428. @Url String url,
  429. @Query("reaction") String reaction);
  430. @GET
  431. Observable<UnifiedSearchOverall> performUnifiedSearch(@Header("Authorization") String authorization,
  432. @Url String url,
  433. @Query("term") String term,
  434. @Query("from") String fromUrl,
  435. @Query("limit") Integer limit,
  436. @Query("cursor") Integer cursor);
  437. @GET
  438. Observable<PollOverall> getPoll(@Header("Authorization") String authorization,
  439. @Url String url);
  440. @FormUrlEncoded
  441. @POST
  442. Observable<PollOverall> createPoll(@Header("Authorization") String authorization,
  443. @Url String url,
  444. @Query("question") String question,
  445. @Field("options[]") List<String> options,
  446. @Query("resultMode") Integer resultMode,
  447. @Query("maxVotes") Integer maxVotes);
  448. @FormUrlEncoded
  449. @POST
  450. Observable<PollOverall> votePoll(@Header("Authorization") String authorization,
  451. @Url String url,
  452. @Field("optionIds[]") List<Integer> optionIds);
  453. @DELETE
  454. Observable<PollOverall> closePoll(@Header("Authorization") String authorization,
  455. @Url String url);
  456. @FormUrlEncoded
  457. @POST
  458. Observable<GenericOverall> setMessageExpiration(@Header("Authorization") String authorization,
  459. @Url String url,
  460. @Field("seconds") Integer seconds);
  461. }