Skip to content

Commit

Permalink
解决被引用的消息被撤回后的显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Feb 18, 2024
1 parent 2c35775 commit 558a571
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
11 changes: 11 additions & 0 deletions client/src/main/java/cn/wildfirechat/model/QuoteInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

public class QuoteInfo implements Parcelable {
private long messageUid;
// 本地使用
private Message message;
private String userId;
private String userDisplayName;
private String messageDigest;
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
29 changes: 27 additions & 2 deletions client/src/main/java/cn/wildfirechat/remote/ChatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {

}
});
}

/**
* 获取远程历史消息
*
Expand All @@ -3433,12 +3460,10 @@ public void getRemoteMessage(long messageUid, GetOneRemoteMessageCallback callba
}

try {
List<Message> outMsgs = new ArrayList<>();
mClient.getRemoteMessage(messageUid, new IGetRemoteMessagesCallback.Stub() {
@Override
public void onSuccess(List<Message> messages, boolean hasMore) throws RemoteException {
if (callback != null) {
outMsgs.addAll(messages);
if (!hasMore) {
mainHandler.post(() -> {
callback.onSuccess(messages.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 558a571

Please sign in to comment.