Skip to content

模型、枚举与错误

1. 模型命名

原生端公开模型统一以 XHIM 开头。iOS 与 macOS 使用 Swift struct/enum,Android 使用 Kotlin data class/sealed interface,Windows 使用 C# class/record/enum, HarmonyOS 使用 ArkTS interface/class/enum。字段采用各语言惯例:

text
iOS/macOS  serverMessageID
Android    serverMessageId
Windows    ServerMessageId
HarmonyOS  serverMessageId

同名语义、空值规则和单位保持一致。

2. 生命周期与配置模型

类型关键字段 / 用途
XHIMEvent状态、消息、会话、社交、媒体、Presence 和 Typing 事件联合类型
XHIMProjectionChangedurable 本地投影的轻量失效通知
XHIMProjectionKindmessage upsert/state、conversation、social、sync
XHIMProjectionOriginlocal、remoteSync、outbox、未来值
XHIMSocialProjectionScopefriend requests、friendships、groups、members、blocks、join requests
XHIMClientConfigurationappID、账号存储、事件容量、运行策略、部署发现结果
XHIMRuntimePolicyrequest timeout、sync page size、reconnect backoff/attempts
XHIMDeploymentbootstrap URL、Endpoint signing key ID/public key
XHIMClientModeproduction 或仅测试构建允许的 local preview
XHIMAuthenticationdevelopment、accessToken、business provider
XHIMCompatibilitySnapshotclient/server protocol、最低客户端协议、capabilities
XHIMDiagnostics无敏感信息的容量、队列、请求和回调计数
XHIMDeviceSessionPolicy多端登录策略、设备上限和当前 session

3. 消息与会话模型

类型关键字段
XHIMOutgoingMessagecontentType、contentVersion、payload、fallbackText
XHIMMessagelocal/server identity、sender、state、内容、mutation revision
XHIMSendReceiptSDK 接受操作的 opaque payload
XHIMMessagePagemessages、nextCursor
XHIMMessageHistoryContinuationbeforeServerSequence
XHIMMessageHistoryPagemessages、continuation、latestServerSequence、view
XHIMMessageSearchQuerytext、conversation、sender、content types、时间范围
XHIMMessageVisibility当前账号是否删除、revision、mutation ID
XHIMMessageVisibilityMutationvisibility、idempotent replay
XHIMConversationID、类型/标题、last message、unread、read sequence、revision
XHIMConversationPageconversations、nextCursor
XHIMConversationViewcleared/hidden watermark、revision
XHIMConversationViewMutationview、idempotent replay
XHIMConversationPreferencepinned、notifications muted、revision
XHIMConversationDraftconversation、optional outgoing message、updated time
XHIMDirectConversationconversationID、participant user IDs
XHIMConversationReadReceiptread sequence、unread count、updated time
XHIMConversationReadSnapshotconversation、read server sequence
XHIMMarkAllConversationsReadResultchanged count、changed reads、truncation flags
XHIMConversationPeerReadreader、read sequence、revision、updated time
XHIMConversationPeerReadPageconversation、reads、truncated

消息的 payload 始终保持原始不可变字节。未知 contentType 不能丢弃,必须使用 fallbackText 安全降级。

4. 用户、关系链与群组模型

类型关键字段
XHIMUserProfileuserID、displayName、avatarURL、revision、updated time
XHIMUserProfileBatchprofiles、missingUserIDs
XHIMUserProfileUpdate可选 displayName/avatarURL 等更新字段
XHIMFriendRequestrequestID、from/to、introduction、state、revision
XHIMFriendshippeer profile/remark、revision、created/updated time
XHIMFriendRequestResolutionrequest、friendship、idempotent replay
XHIMFriendshipDeletionpeer、deleted、idempotent replay
XHIMFriendRemarkChangepeer、remark、revision、idempotent replay
XHIMGroupconversationID、title、avatar、owner、member count、revision
XHIMGroupMembergroup、user、role、state、mute、revision
XHIMGroupJoinRequestrequest、group、applicant、state、revision
XHIMGroupChangegroup、revision、changed member count、idempotent replay
XHIMGroupLifecycleResultgroup、left/dismissed、idempotent replay
XHIMGroupJoinMutationrequest、membership result、idempotent replay
XHIMBlockblocked user、active、revision、updated time
XHIMSocialPage<T>items、nextCursor、可选 group revision fence

5. Presence、Typing、Push 和设备

类型关键字段
XHIMPresenceUpdateeventID、userID、status、sequence、expiresAt
XHIMTypingUpdateeventID、conversationID、userID、isTyping、expiresAt
XHIMPresencePublication服务端接受后的 presence 快照
XHIMTypingPublication服务端接受后的 typing 快照
XHIMPushDeviceplatform、deviceID、秘密 token、environment、locale
XHIMPushDeviceRegistrationenabled、token reassigned、device limit/evictions
XHIMPushDeviceDisableResultdisabled、changed
XHIMDeviceSessionsession/device/platform、current/active、时间、revoke reason
XHIMDeviceSessionPagesessions、policy
XHIMDeviceSessionRevocationsession、revoked、idempotent replay

Push Token 的 description/debug output 会被替换为 <redacted>

6. 媒体模型

类型用途
XHIMMediaEncryptionscheme、keyID、nonce、wrappedKey
XHIMMediaRef不可变服务端媒体身份和内容哈希
XHIMMediaTaskdurable upload/download 状态快照
XHIMMediaTaskUpdate轻量事件载荷;用 taskID 重查完整任务
XHIMMediaUploadIntent本地上传文件和依赖消息元数据
XHIMMediaDownloadIntentmedia ref、cache key 和下载目的
XHIMMediaUploadRequest兼容旧 uploader 的直接上传请求
XHIMMediaUploadProgressphase、completed bytes、total bytes
XHIMMediaCacheReaderSDK 缓存对象的有界读取句柄

Android/HarmonyOS 在文件或 URI 模型上使用平台原生类型,但进入 Core 后语义 相同。

7. 自定义消息模型

类型用途
XHIMMessagePlugin / IXHIMMessagePlugin版本校验与展示适配协议
XHIMMessagePluginRegistry注册、反注册、校验和 presentation 查询
XHIMMessagePresentationconversation preview、notification preview、renderer key
XHIMMentionContent标准 @ 消息解码结果
XHIMForwardItem合并转发中一个不可变消息条目

8. 主要枚举值

XHIMClientState

含义
created已创建,Core 未启动
startedCore 已启动,未登录
authenticating正在认证
connecting正在建立实时连接
synchronizing正在同步本地投影
ready可读写
credentialRequired需要续凭
loggingOut正在退出
closed已不可逆关闭
fatal不可恢复错误

XHIMMessageState

pendingsendingretryingserverAcceptedfailedcancelled, 以及平台用于前向兼容的 unknown

XHIMMessageContentKind

text(1)image(2)audio(3)video(4)file(5)custom(1000)unknown。业务判断优先使用 contentType,不要只依赖这个旧式 粗粒度 kind。

XHIMMessageMutationKind

noneeditTextrecallunknown

XHIMMediaTaskState

pendingauthorizingtransferringpausedverifyingcompletedfailedcancelledunknown

XHIMMediaTaskDirectionuploaddownloadunknown

Projection 与短暂状态

  • XHIMProjectionKind:messageUpserted、messageStateChanged、 conversationChanged、socialChanged、syncApplied、unknown;
  • XHIMProjectionOrigin:local、remoteSync、outbox、unknown;C ABI 也保留 realtime 原始值供未来 Facade 使用;
  • XHIMSocialProjectionScope:none、friendRequests、friendships、groups、 groupMembers、blocks、groupJoinRequests、unknown;
  • XHIMPresenceStatus:online、away、offline、unknown。

关系链与群组

  • XHIMFriendRequestState:pending、accepted、rejected、unknown;
  • XHIMFriendRequestDecision:accept、reject;
  • XHIMGroupMemberRole:owner、administrator、member、unknown;
  • XHIMGroupMemberState:joined、removed、unknown;
  • XHIMGroupJoinRequestState:pending、accepted、rejected、unknown;
  • XHIMGroupJoinDecision:accept、reject;
  • XHIMMultiLoginPolicy:由服务端 capability snapshot 给出稳定策略名。

XHIMPushPlatform

apns(1)fcm(2)huawei(3)web(4)

XHIMDevicePlatform:iOS、Android、macOS、Windows、HarmonyOS、Web、Linux 和 unknown。

XHIMUserAction

noneretryupdateCredentialcheckNetworkcontactSupport

9. 稳定错误模型

iOS/macOS/HarmonyOS 暴露 XHIMNativeError,Android/Windows 暴露 XHIMException。业务分支使用这些字段:

字段稳定性用途
codeABI 稳定粗粒度状态
domain + stableCode跨语言稳定推荐的业务判断键
nativeCode透传HTTP、系统或服务端原始码
retryable稳定是否允许自动/手动重试
retryAfterMilliseconds稳定最早重试等待
userAction稳定UI 建议动作
operationID + traceID稳定诊断服务端链路排查
message不稳定文本仅日志和开发提示,禁止业务字符串匹配

ABI code

数值名称常见处理
0OK成功
1INVALID_ARGUMENT修正调用参数,不重试
2INVALID_STATE等待 ready 或修正生命周期
3NOT_INITIALIZED先 start/connect
4ALREADY_CLOSED新建 Client
5BACKEND_NOT_CONFIGURED当前发行包缺少 Product Adapter
100STORAGE_ERROR检查空间/数据库 Key,必要时联系支持
101IDEMPOTENCY_CONFLICT重查实体,不盲目换 mutation ID
102NOT_FOUND刷新列表或提示对象不存在
103UNSUPPORTED检查 capability/version
104FORBIDDEN按服务端权限提示
200CANCELLED调用被取消
201SDK_SHUTDOWNClient 正在/已经关闭
202CALLBACK_QUEUE_FULL降低请求洪峰并收集诊断
203CREDENTIAL_REQUIRED由账号层 Provider 续凭
900INTERNAL_ERROR记录 operation/trace ID 并联系支持

推荐处理:

swift
catch let error as XHIMNativeError {
    switch (error.domain, error.stableCode, error.userAction) {
    case (_, _, .updateCredential):
        accountSession.requireLogin()
    case (_, _, .checkNetwork):
        banner.showOffline()
    default:
        logger.error("XHIM \(error.operationID) \(error.traceID)")
    }
}

10. 一键连接错误

一键连接异常专用于 Server URL 验证、公开发现和首个凭证获取:iOS、macOS 和 HarmonyOS 为 XHIMConnectionError,Android 为 XHIMConnectionException, Windows 为 XHIMConnectionException。其错误类别包括:

  • invalid server URL / identity / server configuration;
  • insecure transport not allowed;
  • development login disabled;
  • credential unavailable;
  • server rejected(含 HTTP status);
  • response too large。

它发生在 Client 完全建立之前,与运行期 XHIMNativeError 分开处理。

XHIM 客户端 SDK 与服务端文档