diff --git a/client/src/main/java/cn/wildfirechat/model/QuoteInfo.java b/client/src/main/java/cn/wildfirechat/model/QuoteInfo.java index 069c45eee..e3b2f1a61 100644 --- a/client/src/main/java/cn/wildfirechat/model/QuoteInfo.java +++ b/client/src/main/java/cn/wildfirechat/model/QuoteInfo.java @@ -15,6 +15,8 @@ public class QuoteInfo implements Parcelable { private long messageUid; + // 本地使用 + private Message message; private String userId; private String userDisplayName; private String messageDigest; @@ -27,6 +29,14 @@ public void setMessageUid(long messageUid) { this.messageUid = messageUid; } + public void setMessage(Message message) { + this.message = message; + } + + public Message getMessage() { + return this.message; + } + public String getUserId() { return userId; } @@ -53,6 +63,7 @@ public void setMessageDigest(String messageDigest) { public static QuoteInfo initWithMessage(Message message) { QuoteInfo info = new QuoteInfo(); + info.message = message; if (message != null) { info.messageUid = message.messageUid; info.userId = message.sender; diff --git a/client/src/main/java/cn/wildfirechat/remote/ChatManager.java b/client/src/main/java/cn/wildfirechat/remote/ChatManager.java index 9c8e3fb9b..6a40fe3a3 100644 --- a/client/src/main/java/cn/wildfirechat/remote/ChatManager.java +++ b/client/src/main/java/cn/wildfirechat/remote/ChatManager.java @@ -185,6 +185,7 @@ import cn.wildfirechat.model.NullGroupInfo; import cn.wildfirechat.model.NullUserInfo; import cn.wildfirechat.model.PCOnlineInfo; +import cn.wildfirechat.model.QuoteInfo; import cn.wildfirechat.model.ReadEntry; import cn.wildfirechat.model.SecretChatInfo; import cn.wildfirechat.model.Socks5ProxyInfo; @@ -3421,6 +3422,32 @@ public void onFailure(int errorCode) throws RemoteException { } } + public void loadRemoteQuotedMessage(Message message) { + if (!(message.content instanceof TextMessageContent)) { + return; + } + TextMessageContent textMessageContent = (TextMessageContent) message.content; + QuoteInfo quoteInfo = textMessageContent.getQuoteInfo(); + if (quoteInfo == null || quoteInfo.getMessageUid() == 0) { + return; + } + + this.getRemoteMessage(quoteInfo.getMessageUid(), new GetOneRemoteMessageCallback() { + @Override + public void onSuccess(Message msg) { + textMessageContent.getQuoteInfo().setMessage(msg); + for (OnMessageUpdateListener listener : messageUpdateListeners) { + listener.onMessageUpdate(message); + } + } + + @Override + public void onFail(int errorCode) { + + } + }); + } + /** * 获取远程历史消息 * @@ -3433,12 +3460,10 @@ public void getRemoteMessage(long messageUid, GetOneRemoteMessageCallback callba } try { - List outMsgs = new ArrayList<>(); mClient.getRemoteMessage(messageUid, new IGetRemoteMessagesCallback.Stub() { @Override public void onSuccess(List messages, boolean hasMore) throws RemoteException { if (callback != null) { - outMsgs.addAll(messages); if (!hasMore) { mainHandler.post(() -> { callback.onSuccess(messages.get(0)); diff --git a/client/src/main/java/cn/wildfirechat/remote/GetOneRemoteMessageCallback.java b/client/src/main/java/cn/wildfirechat/remote/GetOneRemoteMessageCallback.java index f68804ddf..a77197ed1 100644 --- a/client/src/main/java/cn/wildfirechat/remote/GetOneRemoteMessageCallback.java +++ b/client/src/main/java/cn/wildfirechat/remote/GetOneRemoteMessageCallback.java @@ -4,12 +4,10 @@ package cn.wildfirechat.remote; -import java.util.List; - import cn.wildfirechat.message.Message; public interface GetOneRemoteMessageCallback { - void onSuccess(Message messages); + void onSuccess(Message message); void onFail(int errorCode); } diff --git a/uikit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/TextMessageContentViewHolder.java b/uikit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/TextMessageContentViewHolder.java index 6745c807d..b20ffe85d 100644 --- a/uikit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/TextMessageContentViewHolder.java +++ b/uikit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/TextMessageContentViewHolder.java @@ -33,6 +33,7 @@ import cn.wildfirechat.message.PTextMessageContent; import cn.wildfirechat.message.TextMessageContent; import cn.wildfirechat.message.VideoMessageContent; +import cn.wildfirechat.message.notification.RecallMessageContent; import cn.wildfirechat.model.QuoteInfo; import cn.wildfirechat.remote.ChatManager; @@ -95,12 +96,32 @@ public boolean onLinkClick(String link) { quoteInfo = textMessageContent.getQuoteInfo(); if (quoteInfo != null && quoteInfo.getMessageUid() > 0) { refTextView.setVisibility(View.VISIBLE); - refTextView.setText(quoteInfo.getUserDisplayName() + ": " + quoteInfo.getMessageDigest()); + refTextView.setText(this.quoteMessageDigest(quoteInfo)); } else { refTextView.setVisibility(View.GONE); } } + private String quoteMessageDigest(QuoteInfo quoteInfo) { + Message message = quoteInfo.getMessage(); + if (message == null) { + message = ChatManager.Instance().getMessageByUid(quoteInfo.getMessageUid()); + } + String desc; + if (message != null) { + if (message.content instanceof RecallMessageContent) { + desc = "消息已被撤回"; + } else { + desc = message.content.digest(message); + } + } else { + desc = "消息不可用,可能被删除或者过期"; + ChatManager.Instance().loadRemoteQuotedMessage(this.message.message); + } + + return desc; + } + public void onClick(View view) { String content = ((TextMessageContent) message.message.content).getContent(); WfcWebViewActivity.loadHtmlContent(fragment.getActivity(), "消息内容", content);