NcApi.java 23 KB

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