NcApi.java 21 KB

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