DevPlace SDK model inventory (for the C++ port)
Source (read-only): /home/retoor/projects/DevPlaceIOS/DevPlaceSwiftSDK/Sources/DevPlaceSwiftSDK.
Date decoding strategy source: KreeRequest JsonDecoder.DateDecodingStrategy+OptionalFractionalSeconds.swift (dependency, not in SDK tree).
Files and line counts
| File | Lines |
|---|---|
| DevPlaceConstants.swift | 13 |
| DevPlaceSwiftSDK.swift (request client, not a model) | 618 |
| DevPlace/DevPlaceApiError.swift | 52 |
| DevPlace/DevPlaceBackend.swift | 5 |
| DevPlace/DevPlaceJSONCoder.swift | 27 |
| Messaging/ChatSocketEvent.swift | 38 |
| Messaging/ChatSocketFrameCoding.swift | 144 |
| Messaging/ChatSocketFrameType.swift | 13 |
| Models/TypedNumbers/Vote.swift | 21 |
| Models/TypedStrings/NotificationType.swift | 9 |
| Models/TypedStrings/PostTopic.swift | 13 |
| Models/TypedStrings/PushProvider.swift | 4 |
| Models/TypedStrings/Role.swift | 4 |
| Models/TypedStrings/TargetType.swift | 17 |
| Models/Response/ActionResponse.swift | 21 |
| Models/Response/Article.swift | 154 |
| Models/Response/ArticleDetail.swift | 53 |
| Models/Response/Attachment.swift | 65 |
| Models/Response/AuthToken.swift | 40 |
| Models/Response/Badge.swift | 35 |
| Models/Response/BookmarkItem.swift | 46 |
| Models/Response/Bookmarks.swift | 30 |
| Models/Response/Comment.swift | 141 |
| Models/Response/Conversation.swift | 38 |
| Models/Response/Feed.swift | 72 |
| Models/Response/FollowUser.swift | 38 |
| Models/Response/Followers.swift | 48 |
| Models/Response/Following.swift | 48 |
| Models/Response/Gist.swift | 119 |
| Models/Response/GistDetail.swift | 68 |
| Models/Response/Gists.swift | 55 |
| Models/Response/Leaderboard.swift | 58 |
| Models/Response/LeaderboardEntry.swift | 48 |
| Models/Response/Media.swift | 85 |
| Models/Response/Message.swift | 94 |
| Models/Response/MessagesInbox.swift | 53 |
| Models/Response/MessagesWebSocketTicket.swift | 27 |
| Models/Response/News.swift | 30 |
| Models/Response/Notification.swift | 89 |
| Models/Response/NotificationCounts.swift | 28 |
| Models/Response/NotificationGroup.swift | 28 |
| Models/Response/NotificationOpen.swift | 30 |
| Models/Response/Notifications.swift | 30 |
| Models/Response/Poll.swift | 50 |
| Models/Response/PollOption.swift | 45 |
| Models/Response/Post.swift | 138 |
| Models/Response/PostDetail.swift | 88 |
| Models/Response/Profile.swift | 205 |
| Models/Response/Project.swift | 163 |
| Models/Response/ProjectDetail.swift | 92 |
| Models/Response/Projects.swift | 60 |
| Models/Response/Reactions.swift | 30 |
| Models/Response/ReportReason.swift | 34 |
| Models/Response/UploadResponse.swift | 60 |
| Models/Response/User.swift | 80 |
| Models/Response/UserSearch.swift | 59 |
| Total (53 files) | 3753 |
General coding rules (apply to every model)
- Pattern: every response model
Xhas a private wire structX.CodingData(Decodable, snake_case JSON keys, used verbatim, no key strategy) and a computedX.CodingData.decoded -> Xthat maps to the public model (camelCase). C++: onestruct XWireparsed from JSON, onetoModel(). decodedwrapper vs Data: the wire object is the whole JSON object; nested objects namedData(Article.Data, Comment.Data, Gist.Data, Message.Data, Notification.Data, Post.Data, Project.Data) are the inner entity under a wrapper key (article,comment,gist,message,notification,post,project). Public model keepsdata(or the key name for the *Detail types) holding that entity. Exception:Project.CodingDatais FLAT (entity fields at top level plus author_name/my_vote/recent_comments), and itsdecodedbuildsProject.Datainline.Identifiable.idis computed with a prefix where noted ("post:" + uid). The wire key for ids isuid(or*_uidfor references); C++ field isid/userIdetc.- Null handling: a Swift optional (
T?) accepts a missing key or JSON null. A non-optional key that is missing or null makes the whole decode throw (response rejected). Defaults listed below apply only wheredecodeduses??. - All
Datefields use the date rule below. Fields typedString(not Date) stay raw strings (Conversation.lastMessageAt,Article.Data.articlePublished,Project.Data.releaseDate/demoDate,MessagesInbox.otherLastSeen). time_agois present in the API in many objects but intentionally not decoded (formatted client side from created_at).- Unknown extra JSON keys are ignored.
- Ints are Swift
Int(64-bit): useint64_t. Paginationnext_cursoris a Date (null = no more pages).
Date decoding rules
Decoder: JSONDecoder.devPlace, dateDecodingStrategy = .iso8601WithOptionalFractionalSeconds (custom):
- Decode the JSON value as a String (non-string throws).
- Try
ISO8601DateFormatterwith options[.withInternetDateTime](e.g.2026-11-29T10:15:30Zor...+01:00; no fractional part allowed in this attempt). - If it fails, try options
[.withInternetDateTime, .withFractionalSeconds](e.g.2026-11-29T10:15:30.123Z; fractional part required here; Apple formatter accepts exactly the.SSSmillisecond style, parse generously in C++ for any digits). - Else throw
dataCorrupted("Could not decode date from <s>."), which fails the enclosing response. Both attempts require a timezone designator (Zor+hh:mm). Result is an absolute instant (UTC epoch).
Encoder: JSONEncoder.devPlace, dateEncodingStrategy = .iso8601 (whole seconds, UTC, yyyy-MM-ddTHH:mm:ssZ). Query parameter before is date.formatted(.iso8601) (whole seconds, UTC).
Birth date formatter: DateFormatter.devPlaceBirthDate: locale en_US_POSIX, format yyyy-MM-dd (device time zone, no explicit zone set).
Chat socket outgoing frames use a plain JSONEncoder() (no dates involved). Incoming chat frames use JSONDecoder.devPlace, so created_at follows the same rules.
Constants (DevPlaceConstants)
| Name | Value |
|---|---|
| maxPostTitleLength | 500 |
| minPostContentLength | 10 |
| maxPostContentLength | 125000 |
| minCommentContentLength | 3 |
| maxCommentContentLength | 125000 |
| maxDirectMessageLength | 2000 |
| maxReportDetailLength | 2000 |
| maxAttachmentsCount | 10 |
| maxPollOptionsCount | 6 |
Backend: DevPlaceBackend.baseURL = "https://devplace.net/". WebSocket URL (from SDK client): replace https:// with wss:// (or http:// with ws://), ensure trailing /, append messages/ws?ticket= + ticket percent-encoded with .urlQueryAllowed. Request headers: Accept: application/json; Authorization: Bearer <accessToken> when token given; Content-Type application/x-www-form-urlencoded (default), application/json, or multipart/form-data; boundary=<b>.
Typed strings and numbers (enum raw values exact)
Decoding of these from JSON is done by the owning model with Type(rawValue:); unknown value gives nil (only where noted).
| Enum | Case -> raw value |
|---|---|
| NotificationType | comment="comment", reply="reply", mention="mention", vote="vote", message="message", issue="issue", badge="badge" |
| PostTopic (CaseIterable, order as listed) | random="random", devlog="devlog", showcase="showcase", question="question", rant="rant", fun="fun", politics="politics". Computed name = rawValue.capitalized (first letter upper, rest lower: "Random", "Devlog", ...) |
| PushProvider | apns="apns", webpush="webpush" |
| Role | public="Public", member="Member" (capitalised raw values) |
| TargetType | post="post", comment="comment", gist="gist", project="project", projectFile="project_file", news="news", attachment="attachment", message="message", quiz="quiz", poll="poll", award="award", user="user", issue="issue", workspace="workspace", deviiOutput="devii_output" |
| Vote (typed number, not String) | init(value:Int): 1 -> up, -1 -> down, any other -> none. value: up=1, down=-1, none=0 |
Models
Column legend: JSON key -> C++ field -> type -> optional? (opt = key may be missing/null, req = required) -> notes.
ActionResponse (generic)
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| ok | ok | bool | req | |
| redirect | redirect | string | req | |
| data | data | Payload | opt |
EmptyActionPayload: Decodable with no fields; its decoder ignores content (accepts any JSON, even non-object). Not used by decoded wrappers in the client file (generic helper only).
AuthToken
Wire AuthToken.CodingData (Codable, also encodable):
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| token_type | tokenType | string | req | |
| access_token | accessToken | string | req | |
| expires_in | (expireTime) | int | req | seconds |
Model fields: tokenType (string), accessToken (string), expireTime (Date).
- decoded:
expireTime = now + expires_in seconds(Date(timeIntervalSinceNow: TimeInterval(expires_in)), computed at decode time). isExpired:expireTime < now(strict less than).willExpireSoon:oneHour = 3600.0 s; return expireTime.timeIntervalSinceNow < 3600i.e.(expireTime - now) < 3600strict. An already expired token also returns true (negative interval).- Auth request: POST
auth/token, JSON body{"email":..., "password":...}.
User
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| uid | id | string | req | |
| username | username | string | req | |
| avatar_seed | avatarSeed | string | opt | stays optional |
| role | role | Role enum | opt | Role(rawValue:): unknown string -> nullopt |
| bio | bio | string | opt on wire | null/missing -> "" |
| location | location | string | opt on wire | -> "" |
| git_link | gitLink | string | opt on wire | -> "" |
| website | website | string | opt on wire | -> "" |
| level | level | int | opt on wire | -> 0 |
| xp | xp | int | opt on wire | -> 0 |
| stars | stars | int | opt on wire | -> 0 |
| created_at | createdAt | Date | opt | stays optional |
Init default: role = nil.
Attachment
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| uid | id | string | req | |
| filename | filename | string | opt | |
| url | url | string | req | |
| size | size | int | opt | |
| is_image | isImage | bool | req | |
| is_video | isVideo | bool | req | |
| mime_type | mimeType | string | req | |
| created_at | createdAt | Date | req | |
| can_modify | canModify | bool | req |
(Chat socket attachments use a lenient variant, see chat section.)
UploadResponse
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| uid | id | string | req | |
| original_filename | filename | string | opt | |
| url | url | string | req | |
| size | size | int | opt | |
| is_image | isImage | bool | req | |
| is_video | isVideo | bool | req | |
| is_audio | isAudio | bool | req | |
| mime_type | mimeType | string | req | |
| thumbnail_url | (dropped) | string | opt | decoded but not mapped |
| has_thumbnail | (dropped) | bool | opt | decoded but not mapped |
Media
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| uid | id | string | req | |
| original_filename | originalFilename | string | req | |
| file_size | fileSize | int | req | |
| mime_type | mimeType | string | req | |
| url | url | string | req | |
| thumbnail_url | thumbnailUrl | string | req | |
| has_thumbnail | hasThumbnail | bool | req | |
| is_image | isImage | bool | req | |
| is_video | isVideo | bool | req | |
| target_type | targetType | string | req | raw string, not TargetType |
| target_uid | targetId | string | req | |
| target_url | targetUrl | string | req | |
| created_at | createdAt | Date | req |
Badge
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| name | name | string | opt | |
| icon | icon | string | opt | |
| created_at | createdAt | Date | req |
Reactions
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| mine | mine | vector | req | |
| counts | counts | map<string,int> | req | emoji -> count |
Comment
Wire (wrapper):
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| comment | data | Comment.Data | req | |
| author | author | User | req | |
| my_vote | myVote | Vote | req | Vote(value:) |
| votes | votes | Comment.Votes | req | |
| attachments | attachments | vector | req | |
| children | children | vector | req | recursive |
| reactions | reactions | Reactions | req |
Computed: id = "comment:" + data.id; voteCount = votes.up - votes.down.
Comment.Data (key comment): uid -> id (string, req); user_uid -> userId (string, req); content -> content (string, req); parent_uid -> parentId (string, opt); target_type -> targetType (string, req, raw); target_uid -> targetId (string, req); created_at -> createdAt (Date, req).
Comment.Votes: up -> up (int, req); down -> down (int, req).
Post
Wire (wrapper):
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| post | data | Post.Data | req | |
| author | author | User | req | |
| my_vote | myVote | Vote | req | |
| comment_count | commentCount | int | req | |
| recent_comments | recentComments | vector | req | |
| bookmarked | bookmarked | bool | req | |
| attachments | attachments | vector | req | |
| poll | poll | Poll | opt | |
| reactions | reactions | Reactions | req |
Computed id = "post:" + data.id.
Post.Data: uid -> id (string, req); title -> title (string, opt); topic -> topic (string, opt, raw string not PostTopic); content (string, req); slug (string, opt); user_uid -> userId (string, req); stars (int, req); image (string, opt); created_at -> createdAt (Date, req); updated_at -> updatedAt (Date, opt).
PostDetail
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| post | post | Post.Data | req | |
| author | author | User | req | |
| is_owner | isOwner | bool | req | |
| star_count | starCount | int | req | |
| my_vote | myVote | Vote | req | |
| comments | comments | vector | req | |
| attachments | attachments | vector | req | |
| bookmarked | bookmarked | bool | req | |
| poll | poll | Poll | opt | |
| comment_count | commentCount | int | req | |
| related_posts | relatedPosts | vector | req | |
| topics | topics | vector | req | |
| reactions | reactions | Reactions | req |
id = "post:" + post.id.
Poll
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| uid | id | string | req | |
| question | question | string | req | |
| options | options | vector | req | |
| total | total | int | req | |
| my_choice | myChoice | string | opt | |
| voted | voted | string | opt | string, not bool |
PollOption
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| uid | id | string | req | |
| label | label | string | req | |
| count | count | int | req | |
| votes | votes | int | opt on wire | null/missing -> 0 |
| pct | pct | int | req |
Feed
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| posts | posts | vector | req | |
| current_tab | currentTab | string | req | |
| current_topic | currentTopic | string | opt | |
| search | search | string | req | |
| next_cursor | nextCursor | Date | opt | |
| total_members | totalMembers | int | req | |
| posts_today | postsToday | int | req | |
| total_projects | totalProjects | int | req | |
| total_gists | totalGists | int | req | |
| top_authors | topAuthors | vector | req | |
| daily_topic | (not decoded) | ? | null in sample, ignored |
Article
Wire (wrapper):
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| article | data | Article.Data | req | |
| image_url | imageUrl | string | req | |
| grade | grade | int | req | |
| featured | featured | int | req | |
| recent_comments | recentComments | vector | req |
id = "article:" + data.id. time_ago not decoded.
Article.Data (key article): uid -> id (string); slug; title; description; content; url; source_name -> sourceName; author (all string, req); grade (int, req); ai_grade -> aiGrade (int, req); status (string, req); image_url -> imageUrl (string, req); featured (int, req); has_unique_image -> hasUniqueImage (int, req); article_published -> articlePublished (string, req, raw); created_at -> createdAt (Date, req); synced_at -> syncedAt (Date, req).
ArticleDetail
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| article | article | Article.Data | req | |
| canonical_slug | canonicalSlug | string | req | |
| image_url | imageUrl | string | req | |
| grade | grade | int | req | |
| comments | comments | vector | req | |
| bookmarked | bookmarked | bool | req |
id = "article:" + article.id.
News
articles (vector, req); next_cursor -> nextCursor (Date, opt).
Gist
Wire (wrapper):
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| gist | data | Gist.Data | req | |
| author | author | User | opt | |
| my_vote | myVote | Vote | req | |
| comment_count | commentCount | int | req | |
| recent_comments | recentComments | vector | req |
id = "gist:" + data.id.
Gist.Data (key gist): uid -> id; slug; user_uid -> userId; title; description; source_code -> sourceCode; language (all string, req); stars (int, req); created_at -> createdAt (Date, req); updated_at -> updatedAt (Date, opt).
GistDetail
gist (Gist.Data, req); author (User, req); is_owner -> isOwner (bool); star_count -> starCount (int); my_vote -> myVote (Vote); comments (vector); attachments (vector); bookmarked (bool); reactions (Reactions). All req. id = "gist:" + gist.id.
Gists
gists (vector, req); total_count -> totalCount (int, req); next_cursor -> nextCursor (Date, opt); current_language -> currentLanguage (string, req); search (string, req); languages (vector<vector>, req); gist_language_codes -> gistLanguageCodes (vector, req).
Project (list item, FLAT wire)
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| uid | data.id | string | req | |
| slug | data.slug | string | req | |
| user_uid | data.userId | string | req | |
| title | data.title | string | req | |
| description | data.description | string | req | |
| project_type | data.projectType | string | req | |
| status | data.status | string | req | |
| stars | data.stars | int | req | |
| is_private | data.isPrivate | bool | opt | |
| read_only | data.readOnly | bool | opt | |
| release_date | data.releaseDate | string | opt | raw string |
| demo_date | data.demoDate | string | opt | raw string |
| created_at | data.createdAt | Date | req | |
| updated_at | data.updatedAt | Date | opt | |
| author_name | authorName | string | req | |
| my_vote | myVote | Vote | req | |
| recent_comments | recentComments | vector | req | |
| platforms | (not decoded) | ? | null in sample |
id = "project:" + data.id.
Project.Data standalone wire (used by ProjectDetail project key and Profile projects): same fields as the data.* rows above with the same keys, nothing else.
ProjectDetail
project (Project.Data, req); author (User, req); is_owner (bool); star_count (int); my_vote (Vote); comments (vector); attachments (vector); bookmarked (bool); is_private -> isPrivate (bool, req); read_only -> readOnly (bool, req); fork_count -> forkCount (int, req); file_count -> fileCount (int, req); reactions (Reactions, req). Not decoded: platforms, forked_from. id = "project:" + project.id.
Projects
projects (vector, req); current_tab -> currentTab (string); search (string); project_type -> projectType (string); total_count -> totalCount (int); next_cursor -> nextCursor (Date, opt); total_members -> totalMembers (int); top_authors -> topAuthors (vector). All req except next_cursor.
Profile
Wire keys (all req unless marked):
| JSON | C++ | Type | Opt | Notes |
|---|---|---|---|---|
| profile_user | user | User | req | note key name |
| posts | posts | vector | req | |
| badges | badges | vector | req | |
| badge_total | badgeTotal | int | req | |
| badge_earned | badgeEarned | int | req | |
| projects | projects | vector<Project.Data> | req | |
| gists | gists | vector | req | |
| current_tab | currentTab | string | req | |
| posts_count | postsCount | int | req | |
| is_following | isFollowing | bool | req | |
| is_blocked | isBlocked | bool | req | |
| is_muted | isMuted | bool | req | |
| is_owner | isOwner | bool | req | |
| can_view_api_key | canViewApiKey | bool | req | |
| api_key | apiKey | string | req | |
| ai_correction_enabled | aiCorrectionEnabled | bool | req | |
| ai_correction_sync | aiCorrectionSync | bool | req | |
| ai_correction_prompt | aiCorrectionPrompt | string | opt | |
| ai_modifier_enabled | aiModifierEnabled | bool | req | |
| ai_modifier_sync | aiModifierSync | bool | req | |
| ai_modifier_prompt | aiModifierPrompt | string | opt | |
| telegram_paired | telegramPaired | bool | req | |
| notif_telegram_paired | notifTelegramPaired | bool | req | |
| can_manage_customization | canManageCustomization | bool | req | |
| cust_disable_global | custDisableGlobal | bool | req | |
| cust_disable_pagetype | custDisablePagetype | bool | req | |
| xp_progress_pct | xpProgressPercent | int | opt on wire | null/missing -> 0 |
| rank | rank | int | opt | stays optional |
| followers_count | followersCount | int | req | |
| following_count | followingCount | int | req | |
| viewer_is_admin | viewerIsAdmin | bool | req | |
| media | media | vector | req |
Not decoded (type unknown): achievements, ai_quota, correction_usage, modifier_usage, activities, heatmap, heatmap_months, streak, people, follow_pagination, media_pagination, notification_prefs. id = "profile:" + user.id.
Followers
username (string); mode (string); count (int); page (int); total_pages -> totalPages (int); followers (vector). All req.
Following
Same as Followers but list key is following -> following (vector). All req.
FollowUser
uid -> id (string); username (string); bio (string, non-optional, must be present and non-null); is_following -> isFollowing (bool). All req.
Leaderboard
entries (vector); user_rank -> userRank (int); total_members; posts_today; total_projects; total_gists (int); top_authors -> topAuthors (vector); featured_news -> featuredNews (vector<Article.Data>). All req.
LeaderboardEntry
uid -> id (string, req); username (string, req); avatar_seed -> avatarSeed (string, opt); stars (int); level (int); rank (int) req.
Bookmarks
items (vector, req); next_cursor -> nextCursor (Date, opt).
BookmarkItem
target_type -> targetType (string, raw); target_uid -> targetId (string); type_label -> typeLabel (string); title (string); url (string). All req. id = targetType + ":" + targetId (no prefix literal). time_ago not decoded.
Conversation
other_user -> otherUser (User, req); last_message -> lastMessage (string, req); last_message_at -> lastMessageAt (string, req, NOT a Date); unread (bool, req).
Message
Wire (wrapper): message -> data (Message.Data, req); sender (User, req); is_mine -> isMine (bool, req); attachments (vector, req). id = "message:" + data.id.
Message.Data (key message): uid -> id; sender_uid -> senderId; receiver_uid -> receiverId; content (string); read (bool); created_at -> createdAt (Date). All req.
MessagesInbox
conversations (vector, req); messages (vector, req); other_user -> otherUser (User, opt); current_conversation -> currentConversation (string, opt); search (string, req); other_online -> otherOnline (bool, req); other_last_seen -> otherLastSeen (string, opt, raw).
MessagesWebSocketTicket
ticket (string, req); expires_in -> expiresIn (int, req, seconds, kept as int, no Date conversion).
UserSearch
results (vector<UserSearch.Result>, req). Result: uid -> id (string, req); username (string, req); avatar_seed -> avatarSeed (string, opt).
Notifications
notification_groups -> groups (vector, req; note key); next_cursor -> nextCursor (Date, opt).
NotificationGroup
label (string, req); entries (vector, req).
Notification
Wire (wrapper): notification -> data (Notification.Data, req); actor (User, opt). id = "notification:" + data.id.
Notification.Data (key notification): uid -> id (string, req); type -> type (NotificationType, nullable: wire is string req, NotificationType(rawValue:) unknown -> nullopt); message (string, req); read (bool, req); related_uid -> relatedId (string, req); target_url -> targetUrl (string, req); created_at -> createdAt (Date, req).
NotificationCounts
notifications (int, req); messages (int, req).
NotificationOpen
ok (bool, req); redirect (string, req). data ignored (always null).
ReportReason
List wire ListCodingData: {"reasons":[{key,label},...]}. Item: key (string, req); label (string, req). id = key.
API error JSON shape and message selection
Wire DevPlaceApiError.CodingData (Decodable):
{ "error": <string | object>, "messages": [string]? }
object form: { "status": int?, "message": string?, "errors": [string]? }
erroris required. It is decoded as a single value: first try String; if that fails decode the object (Detail, all three fields optional; a non-string non-object, or an object where a field has wrong type, throws and the error body is unusable).messagesoptional array of strings (top level).- Result
DevPlaceApiError { message: string, isSpecific: bool }. - Selection (
specificMessage):- error is object:
detail.message ?? detail.errors?.first ?? messages?.first(first non-null in that order; empty array gives no element so falls through; empty strings are valid values and win). - error is string:
messages?.first ?? text(top-level messages[0] wins over the error string).
- error is object:
- If
specificMessageis non-null:{message: it, isSpecific: true}; else{message: "Something went wrong. Please try again.", isSpecific: false}(exact text, ends with period). Note a string error always yields isSpecific true. detail.statusis parsed but never used.
Chat websocket
Files: ChatSocketEvent.swift, ChatSocketFrameCoding.swift, ChatSocketFrameType.swift. Transport: text frames carrying UTF-8 JSON objects. Connect URL: see Constants section (ticket from POST messages/ws-ticket, response MessagesWebSocketTicket).
Frame types (internal enums)
ChatSocketServerFrameType (rawValue): ready="ready", message="message", typing="typing", read="read", error="error". ChatSocketClientFrameType (rawValue): send="send", typing="typing", read="read".
ChatSocketEvent (what the decoder emits)
| Case | Payload | Source frame |
|---|---|---|
| ready | userUid: string | ready |
| message | ChatSocketIncomingMessage | message |
| typing | fromUid: string | typing |
| read | byUid: string | read |
| failed | clientId: string?, text: string | error |
| disconnected | none | never produced by the decoder (raised by the socket layer on close) |
ChatSocketIncomingMessage: uid (string), senderUid (string), receiverUid (string), content (string), createdAt (Date), attachments (vector), clientId (string, opt).
Incoming decode algorithm (ChatSocketFrameDecoder.decode(Data) -> ChatSocketEvent?)
- Parse
{"type": string}from the bytes withJSONDecoder.devPlace. Parse failure, missing/non-stringtype, or atypenot in the server set returns nil (frame silently dropped). - Switch on type and parse the full object; any parse failure returns nil (dropped, no error event):
| type | Required keys | C++ event field |
|---|---|---|
| ready | user_uid: string | ready.userUid |
| message | uid, sender_uid, receiver_uid, content: string; created_at: Date (ISO rule above) | message.* |
| typing | from_uid: string | typing.fromUid |
| read | by_uid: string | read.byUid |
| error | text: string; client_id: string? (opt) | failed.text, failed.clientId |
Message frame optional keys: attachments: array of attachment frames (missing/null -> empty list); client_id: string (opt, echo of the sender's client id).
Attachment frame (lenient, all mapped by AttachmentFrame.attachment):
| JSON | C++ | Type | Opt | Default when missing/null |
|---|---|---|---|---|
| uid | id | string | req | |
| filename | filename | string | opt | nullopt |
| url | url | string | req | |
| size | size | int | opt | nullopt |
| is_image | isImage | bool | opt | false |
| is_video | isVideo | bool | opt | false |
| mime_type | mimeType | string | opt | "" |
| created_at | createdAt | Date | opt | now (Date() at decode time) |
| can_modify | canModify | bool | opt | false |
If any attachment element is malformed (e.g. missing uid), the entire message frame fails and is dropped.
Outgoing encode (ChatSocketFrameEncoder, returns String; plain JSONEncoder())
Key order: Swift synthesized Encodable emits properties in declaration order (type first); JSONEncoder default output formatting is compact (no spaces, no newlines), and key order is not guaranteed stable by Foundation (dictionary-free struct encoding in practice yields declaration order but the server must not depend on it). Slashes in strings are escaped as \/ by default JSONEncoder; non-ASCII is emitted raw UTF-8; control characters, " and \ are escaped. For byte-identical output replicate: compact, declaration order, / -> \/.
| Method | JSON (declaration order) |
|---|---|
| send(receiverUid, content, attachmentUids, clientId) | {"type":"send","receiver_uid":<s>,"content":<s>,"attachment_uids":[<s>,...],"client_id":<s>} |
| typing(receiverUid) | {"type":"typing","receiver_uid":<s>} |
| read(withUid) | {"type":"read","with_uid":<s>} |
attachment_uidsis always present (empty array[]when none);client_idis a required non-null string on send.- If encoding ever fails the encoder returns the literal string
{}(cannot happen for these types). - Length limits to enforce client side: content max 2000 (maxDirectMessageLength), attachments max 10.