#pragma once // Spec: shell.md section 6 (ProdDevPlaceApi). Network implementation over DevPlaceRequest. Pattern of every // authenticated method (exactly like Swift): no token -> notLoggedIn; refreshTokenIfNeeded(); then the SDK call with // the token captured BEFORE the refresh (feed, postDetail, profile and the websocket URL read it AFTER the refresh). // Refresh has no lock: parallel requests can each re-login. logIn stores the token in AppState, then the own user // (profile failure sets currentUser to nil, login still succeeds). No API-side error mapping: use AlertMessage. // DIFF: unregisterPushDevice is a no-op after login+refresh (no backend endpoint), registerPushDevice sends "apns". #include "api/DevPlaceApi.hpp" #include "api/DevPlaceRequest.hpp" namespace dp { class ProdDevPlaceApi : public DevPlaceApi { public: using DevPlaceApi::feed; using DevPlaceApi::messages; using DevPlaceApi::notifications; static ProdDevPlaceApi& shared(); explicit ProdDevPlaceApi(NetworkService& network = NetworkService::instance()); DevPlaceRequest& request() { return request_; } CancelPtr logIn(const std::string& email, const std::string& password, Done done) override; 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) override; CancelPtr deleteAccount(const std::string& password, Done done) override; CancelPtr feed(const std::optional& before, Done done) override; CancelPtr postDetail(const std::string& slug, Done done) override; 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) override; CancelPtr editPost(const std::string& slug, const std::string& title, PostTopic topic, const std::string& content, const std::string& projectLink, Done done) override; CancelPtr deletePost(const std::string& slug, Done done) override; CancelPtr deleteComment(const std::string& uid, Done done) override; CancelPtr editComment(const std::string& uid, const std::string& content, Done done) override; CancelPtr createComment(TargetType targetType, const std::string& targetId, const std::string& content, const Str& parentId, const std::vector& attachments, Done done) override; CancelPtr profile(const Str& username, Done done) override; CancelPtr followUser(const std::string& username, Done done) override; CancelPtr unfollowUser(const std::string& username, Done done) override; CancelPtr blockUser(const std::string& username, Done done) override; CancelPtr unblockUser(const std::string& username, Done done) override; CancelPtr muteUser(const std::string& username, Done done) override; CancelPtr unmuteUser(const std::string& username, Done done) override; CancelPtr messages(const Str& withUid, Done done) override; CancelPtr sendMessage(const std::string& receiverId, const std::string& content, const std::vector& attachments, Done done) override; std::unique_ptr makeMessagesSocket(const std::string& otherUserId) override; CancelPtr usersForMentioning(const std::string& query, Done done) override; CancelPtr notifications(const std::optional& before, Done done) override; CancelPtr openNotification(const std::string& uid, Done done) override; CancelPtr notificationCounts(Done done) override; CancelPtr markNotificationRead(const std::string& uid, Done done) override; CancelPtr markAllNotificationsRead(Done done) override; CancelPtr registerPushDevice(const std::string& deviceToken, Done done) override; CancelPtr unregisterPushDevice(const std::string& deviceToken, Done done) override; CancelPtr vote(TargetType targetType, const std::string& targetId, Vote vote, Done done) override; CancelPtr submitPollChoice(const std::string& pollId, const std::string& optionId, Done done) override; CancelPtr react(TargetType targetType, const std::string& targetId, const std::string& emoji, Done done) override; CancelPtr reportReasons(Done> done) override; CancelPtr report(TargetType targetType, const std::string& targetId, const std::string& reason, const Str& detail, Done done) override; CancelPtr uploadFile(const std::string& data, const std::string& filename, const std::string& mimeType, Done done) override; CancelPtr uploadFromUrl(const std::string& url, const Str& filename, Done done) override; CancelPtr deleteAttachment(const std::string& uid, Done done) override; private: // Captured-token pattern: call(token, done) runs after the refresh with the token read before it. template CancelPtr withToken(Done done, Call call); // Fresh-token pattern: refresh first, then call(AppState token or nullopt, done). template CancelPtr afterRefresh(Done done, Call call); template static CancelPtr failLater(Done done, Error error); void fetchOwnUser(const AuthToken& token, Done done); DevPlaceRequest request_; }; } // namespace dp