#pragma once // Spec: shell.md section 6 (DevPlaceApi protocol). Abstract callback API the UI codes against; implemented by // ProdDevPlaceApi (network) and MockDevPlaceApi (fixtures, --mock). Every method returns a CancelPtr; a cancelled // call never calls back. Callbacks run on the UI thread. Calls without a token fail with DevPlaceError::notLoggedIn() // (delivered asynchronously). Result is the "Void" result. #include #include #include #include #include "api/ApiTypes.hpp" #include "api/MessagesSocket.hpp" #include "model/BirthDate.hpp" #include "model/Feed.hpp" #include "model/MessagesInbox.hpp" #include "model/NotificationCounts.hpp" #include "model/NotificationOpen.hpp" #include "model/Notifications.hpp" #include "model/PostDetail.hpp" #include "model/PostTopic.hpp" #include "model/Profile.hpp" #include "model/ReportReason.hpp" #include "model/TargetType.hpp" #include "model/UploadResponse.hpp" #include "model/UserSearch.hpp" #include "model/Vote.hpp" namespace dp { class DevPlaceApi { public: using Str = std::optional; virtual ~DevPlaceApi() = default; virtual CancelPtr logIn(const std::string& email, const std::string& password, Done done) = 0; virtual CancelPtr signUp(const std::string& username, const std::string& email, const std::string& password, const std::string& confirmPassword, const BirthDate& birthDate, bool acceptTerms, Done done) = 0; virtual CancelPtr deleteAccount(const std::string& password, Done done) = 0; virtual CancelPtr feed(const std::optional& before, Done done) = 0; virtual CancelPtr postDetail(const std::string& slug, Done done) = 0; virtual CancelPtr createPost(const Str& title, const std::optional& topic, const std::string& content, const std::vector& attachments, const Str& pollQuestion, const std::vector& pollOptions, const Str& projectLink, Done done) = 0; virtual CancelPtr editPost(const std::string& slug, const std::string& title, PostTopic topic, const std::string& content, const std::string& projectLink, Done done) = 0; virtual CancelPtr deletePost(const std::string& slug, Done done) = 0; virtual CancelPtr deleteComment(const std::string& uid, Done done) = 0; virtual CancelPtr editComment(const std::string& uid, const std::string& content, Done done) = 0; virtual CancelPtr createComment(TargetType targetType, const std::string& targetId, const std::string& content, const Str& parentId, const std::vector& attachments, Done done) = 0; virtual CancelPtr profile(const Str& username, Done done) = 0; virtual CancelPtr followUser(const std::string& username, Done done) = 0; virtual CancelPtr unfollowUser(const std::string& username, Done done) = 0; virtual CancelPtr blockUser(const std::string& username, Done done) = 0; virtual CancelPtr unblockUser(const std::string& username, Done done) = 0; virtual CancelPtr muteUser(const std::string& username, Done done) = 0; virtual CancelPtr unmuteUser(const std::string& username, Done done) = 0; virtual CancelPtr messages(const Str& withUid, Done done) = 0; virtual CancelPtr sendMessage(const std::string& receiverId, const std::string& content, const std::vector& attachments, Done done) = 0; virtual std::unique_ptr makeMessagesSocket(const std::string& otherUserId) = 0; virtual CancelPtr usersForMentioning(const std::string& query, Done done) = 0; virtual CancelPtr notifications(const std::optional& before, Done done) = 0; virtual CancelPtr openNotification(const std::string& uid, Done done) = 0; virtual CancelPtr notificationCounts(Done done) = 0; virtual CancelPtr markNotificationRead(const std::string& uid, Done done) = 0; virtual CancelPtr markAllNotificationsRead(Done done) = 0; virtual CancelPtr registerPushDevice(const std::string& deviceToken, Done done) = 0; virtual CancelPtr unregisterPushDevice(const std::string& deviceToken, Done done) = 0; // The backend toggles: always send Vote::Up to add or remove an upvote (see AppState::performVoteToggle). virtual CancelPtr vote(TargetType targetType, const std::string& targetId, Vote vote, Done done) = 0; virtual CancelPtr submitPollChoice(const std::string& pollId, const std::string& optionId, Done done) = 0; virtual CancelPtr react(TargetType targetType, const std::string& targetId, const std::string& emoji, Done done) = 0; virtual CancelPtr reportReasons(Done> done) = 0; virtual CancelPtr report(TargetType targetType, const std::string& targetId, const std::string& reason, const Str& detail, Done done) = 0; virtual CancelPtr uploadFile(const std::string& data, const std::string& filename, const std::string& mimeType, Done done) = 0; virtual CancelPtr uploadFromUrl(const std::string& url, const Str& filename, Done done) = 0; virtual CancelPtr deleteAttachment(const std::string& uid, Done done) = 0; // Convenience overloads (Swift protocol extension). Derived classes must `using DevPlaceApi::feed;` etc. CancelPtr feed(Done done) { return feed(std::nullopt, std::move(done)); } CancelPtr notifications(Done done) { return notifications(std::nullopt, std::move(done)); } CancelPtr messages(Done done) { return messages(std::nullopt, std::move(done)); } // Swift extension: when AppState has a token that willExpireSoon, log in again with the stored session // credentials (silently succeeds without them), then call `done`. A login failure is reported to `done`. CancelPtr refreshTokenIfNeeded(Done done); }; } // namespace dp