fix: preserve user chat messages after ai onboarding
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user