9892b65a19
CI / flutter-gates (push) Successful in 3m9s
- 新增 PostComposePage(P3 发布页,push 路由 post_form):正文/类目 (general·help)/九宫格选图(组装 MediaUploader + UploadProgressOverlay, 删格按列表序重发 position)/发布 gating(正文非空 + 在场媒体全 ready) - 发布走「createPost(draft) → PATCH status=published」两步:迁移失败时草稿 已在服务端,UI 明确提示「草稿已保存」;40905 重置幂等键、42203 提示等图、 网络失败同键重放不重复建帖;40902 自动取新 version 重提一次 - 草稿:「存草稿」(manual) 与「取消 → 保留」(on_exit) 两路径 + 进页恢复最新 一条草稿(提示条/清空);「不保留」软删服务端草稿(post_deleted 触点) - 埋点:新增 post_analytics.dart(发布漏斗五事件 + 媒体三段,键集对齐字典 v3);MediaUploader 挂接 started/succeeded/failed(含 cancelled) 与 attemptSeq; pageName 枚举补 post_form - PostMediaEditGrid(同文件编辑态):3 列九宫格 + 虚线「+」格 + 删除角标 + 进度覆盖层 + 失败整格重试;页级上传汇总条 - create 页只余 AI 生成模拟(M4 原样保留),demo 发布流与 AppState.posts / publishPost / updatePost 及其持久化一并退役;首页 story「发布」与 Feed 空态 CTA 改为 push 真实发布页 - 测试 458 → 502(+44):发布页 widget 22、发布埋点 11、媒体三段 7、编辑态 九宫格 4、主壳发布闭环 1;另加桌面真链路 integration_test(env 门控) - flutter analyze 0 问题、dart format 无 diff;compose 六容器真链路实测通过 (选图上传 → 发布 → Feed 置顶 → 第二客户端可见) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
60 lines
3.2 KiB
Dart
60 lines
3.2 KiB
Dart
import 'package:patbond_flutter/core/network/api_exception.dart';
|
|
import 'package:patbond_flutter/features/community/community_exceptions.dart';
|
|
import 'package:patbond_flutter/features/community/community_models.dart';
|
|
|
|
/// 降级作者([AuthorSummary.isDegraded],资料暂不可得或已注销)的
|
|
/// 统一占位名(05 号规范:占位头像 + 默认名,客户端不做昵称回退拼装)。
|
|
const degradedAuthorName = '宠友';
|
|
|
|
/// 作者展示名:正常路径 nickname 恒非空(服务端已回退 username);
|
|
/// 降级形态统一 [degradedAuthorName]。
|
|
String authorDisplayName(AuthorSummary author) =>
|
|
author.nickname ?? degradedAuthorName;
|
|
|
|
/// Feed 卡片元信息的相对时间(正典「2 小时前」语言)。
|
|
/// [now] 注入口供测试锁定时钟。
|
|
String feedRelativeTime(DateTime time, {DateTime? now}) {
|
|
final reference = now ?? DateTime.now();
|
|
final difference = reference.difference(time.toLocal());
|
|
if (difference.inMinutes < 1) return '刚刚';
|
|
if (difference.inHours < 1) return '${difference.inMinutes} 分钟前';
|
|
if (difference.inDays < 1) return '${difference.inHours} 小时前';
|
|
if (difference.inDays < 7) return '${difference.inDays} 天前';
|
|
final local = time.toLocal();
|
|
if (local.year == reference.year) return '${local.month}月${local.day}日';
|
|
return '${local.year}年${local.month}月${local.day}日';
|
|
}
|
|
|
|
/// Feed 加载失败的用户话术(pets 域 petLoadErrorMessage 同构;
|
|
/// 服务端原始 message 不上屏)。
|
|
String feedLoadErrorMessage(ApiException? error) => switch (error) {
|
|
ApiNetworkException _ => '网络异常,请检查网络后重试',
|
|
ApiRateLimitException _ => '请求过于频繁,请稍后再试',
|
|
_ => '动态加载失败,请稍后重试',
|
|
};
|
|
|
|
/// 发布失败的用户话术(T3-17,三条关键语义各自可辨;服务端原始
|
|
/// message 不上屏):
|
|
///
|
|
/// - 40905 同键异 payload:提交标识已被页面重置,再点一次即可;
|
|
/// - 42203 asset 未 ready:等图片传完再发;
|
|
/// - 网络失败:可重试(同键重放,服务端不会重复建帖)。
|
|
String postPublishErrorMessage(ApiException? error) => switch (error) {
|
|
IdempotencyMismatchException _ => '提交内容与上次重试不一致,已重置提交标识,请再点一次「发布」',
|
|
MediaNotReadyException _ => '有图片还没上传完成,请等图片就绪后再发布',
|
|
PostNotFoundException _ => '草稿已不存在(可能已在别处删除),请重新发布',
|
|
PostVersionConflictException _ => '草稿在别处被修改过,请重试发布',
|
|
ApiNetworkException _ => '网络异常,请检查网络后重试',
|
|
ApiRateLimitException _ => '请求过于频繁,请稍后再试',
|
|
ApiBusinessException(:final code) when code == ApiCodes.paramError =>
|
|
'内容不符合发布要求,请修改后重试',
|
|
_ => '发布失败,请稍后重试',
|
|
};
|
|
|
|
/// 草稿保存失败的用户话术(发布页 SnackBar)。
|
|
String draftSaveErrorMessage(ApiException? error) => switch (error) {
|
|
ApiNetworkException _ => '网络异常,草稿未保存,请重试',
|
|
ApiRateLimitException _ => '请求过于频繁,请稍后再试',
|
|
_ => '草稿保存失败,请重试',
|
|
};
|