fix: preserve user chat messages after ai onboarding

This commit is contained in:
kris
2026-03-31 16:30:21 +08:00
parent 70494fc15b
commit 71d0979292
4 changed files with 223 additions and 4 deletions

View File

@@ -701,8 +701,10 @@ public class BossApiClient {
void rememberIdentity(JSONObject json) {
if (json == null) return;
JSONObject session = json.optJSONObject("session");
JSONObject source = session != null ? session : json;
JSONObject source = resolveSessionIdentitySource(json);
if (source == null) {
return;
}
SharedPreferences.Editor editor = prefs.edit();
String restoreToken = source.optString("restoreToken", "");
@@ -723,6 +725,24 @@ public class BossApiClient {
editor.apply();
}
@Nullable
private JSONObject resolveSessionIdentitySource(JSONObject json) {
JSONObject session = json.optJSONObject("session");
if (session != null) {
return session;
}
if (
json.has("restoreToken")
|| json.has("account")
|| json.has("role")
|| json.has("expiresAt")
|| json.has("sessionCookie")
) {
return json;
}
return null;
}
private void clearSession() {
prefs.edit()
.remove(KEY_SESSION_COOKIE)

View File

@@ -718,11 +718,12 @@ public class ProjectDetailActivity extends BossScreenActivity {
private View buildMessageView(JSONObject message) {
String messageId = message.optString("id", "");
String sender = message.optString("sender", "");
String senderLabel = message.optString("senderLabel", "消息");
String body = message.optString("body", "");
String meta = formatMessageTime(message.optString("sentAt", ""));
String kind = message.optString("kind", "");
boolean outgoing = isOutgoingMessage(senderLabel);
boolean outgoing = isOutgoingMessage(senderLabel, sender);
View messageView;
View.OnClickListener messagePrimaryClick = null;
@@ -1293,7 +1294,10 @@ public class ProjectDetailActivity extends BossScreenActivity {
return remainingScroll <= BossUi.dp(this, 96);
}
private boolean isOutgoingMessage(String senderLabel) {
private boolean isOutgoingMessage(String senderLabel, @Nullable String sender) {
if ("user".equals(sender)) {
return true;
}
if (TextUtils.isEmpty(senderLabel)) {
return false;
}