Skip to content

Commit

Permalink
修复超级群组会话,跳转到收条未读消息时,消息内容不显示
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Oct 22, 2024
1 parent f3aeaa3 commit 9908310
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ public long getFirstUnreadMessageId(Conversation conversation) {
* @param before true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
* @param count 获取消息条数
* @param withUser 只有会话类型为{@link cn.wildfirechat.model.Conversation.ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
* @return 由于ipc大小限制,本接口获取到的消息列表可能不完整,请使用异步获取
* @return 由于ipc大小限制,本接口获取到的消息列表可能不完整,并且超级群里面,可能返回为完全加载的消息,请使用异步获取
*/
@Deprecated
public List<Message> getMessages(Conversation conversation, long fromIndex, boolean before, int count, String withUser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import cn.wildfire.chat.kit.common.AppScopeViewModel;
import cn.wildfire.chat.kit.common.OperateResult;
Expand All @@ -27,6 +28,7 @@
import cn.wildfirechat.remote.CreateSecretChatCallback;
import cn.wildfirechat.remote.GeneralCallback;
import cn.wildfirechat.remote.GetMessageCallback;
import cn.wildfirechat.remote.GetOneRemoteMessageCallback;
import cn.wildfirechat.remote.GetRemoteMessageCallback;
import cn.wildfirechat.remote.SecretChatStateChangeListener;

Expand Down Expand Up @@ -132,29 +134,77 @@ public void onFail(int errorCode) {
public MutableLiveData<List<UiMessage>> loadAroundMessages(Conversation conversation, String withUser, long focusIndex, int count) {
MutableLiveData<List<UiMessage>> result = new MutableLiveData<>();
ChatManager.Instance().getWorkHandler().post(() -> {
List<Message> oldMessageList = ChatManager.Instance().getMessages(conversation, focusIndex, true, count, withUser);
List<UiMessage> oldMessages = new ArrayList<>();
if (oldMessageList != null) {
for (Message msg : oldMessageList) {
if (conversation.type == Conversation.ConversationType.SecretChat) {
BurnMessageInfo burnMessageInfo = ChatManager.Instance().getBurnMessageInfo(msg.messageId);
oldMessages.add(new UiMessage(msg, burnMessageInfo));
} else {
oldMessages.add(new UiMessage(msg));
List<Message> oldMessageList = new ArrayList<>();
List<Message> newMessageList = new ArrayList<>();
CountDownLatch countDownLatch = new CountDownLatch(3);
ChatManager.Instance().getMessages(conversation, focusIndex, true, count, withUser, new GetMessageCallback() {
@Override
public void onSuccess(List<Message> messages, boolean hasMore) {
oldMessageList.addAll(messages);
countDownLatch.countDown();
}

@Override
public void onFail(int errorCode) {
countDownLatch.countDown();
}
});

ChatManager.Instance().getMessages(conversation, focusIndex, false, count, withUser, new GetMessageCallback() {

@Override
public void onSuccess(List<Message> messages, boolean hasMore) {
newMessageList.addAll(messages);
countDownLatch.countDown();
}

@Override
public void onFail(int errorCode) {
countDownLatch.countDown();
}
});

final Message[] focusMessage = {ChatManager.Instance().getMessage(focusIndex)};
if (focusMessage[0] == null || focusMessage[0].content.notLoaded == 0) {
countDownLatch.countDown();
} else {
ChatManager.Instance().getRemoteMessage(focusMessage[0].messageUid, new GetOneRemoteMessageCallback() {
@Override
public void onSuccess(Message message) {
focusMessage[0] = message;
countDownLatch.countDown();
}

@Override
public void onFail(int errorCode) {
countDownLatch.countDown();
}
});
}

try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}

List<UiMessage> oldMessages = new ArrayList<>();
for (Message msg : oldMessageList) {
if (conversation.type == Conversation.ConversationType.SecretChat) {
BurnMessageInfo burnMessageInfo = ChatManager.Instance().getBurnMessageInfo(msg.messageId);
oldMessages.add(new UiMessage(msg, burnMessageInfo));
} else {
oldMessages.add(new UiMessage(msg));
}
}
Message message = ChatManager.Instance().getMessage(focusIndex);
List<Message> newMessageList = ChatManager.Instance().getMessages(conversation, focusIndex, false, count, withUser);

List<UiMessage> newMessages = new ArrayList<>();
if (newMessageList != null) {
for (Message msg : newMessageList) {
if (conversation.type == Conversation.ConversationType.SecretChat) {
BurnMessageInfo burnMessageInfo = ChatManager.Instance().getBurnMessageInfo(msg.messageId);
newMessages.add(new UiMessage(msg, burnMessageInfo));
} else {
newMessages.add(new UiMessage(msg));
}
for (Message msg : newMessageList) {
if (conversation.type == Conversation.ConversationType.SecretChat) {
BurnMessageInfo burnMessageInfo = ChatManager.Instance().getBurnMessageInfo(msg.messageId);
newMessages.add(new UiMessage(msg, burnMessageInfo));
} else {
newMessages.add(new UiMessage(msg));
}
}

Expand All @@ -170,8 +220,8 @@ public MutableLiveData<List<UiMessage>> loadAroundMessages(Conversation conversa
tipMessage.messageId = Long.MAX_VALUE;
messages.add(new UiMessage(tipMessage));

if (message != null) {
messages.add(new UiMessage(message));
if (focusMessage[0] != null) {
messages.add(new UiMessage(focusMessage[0]));
}
messages.addAll(newMessages);
result.postValue(messages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ConversationViewHolder(Fragment fragment, RecyclerView.Adapter adapter, V
this.itemView = itemView;
this.adapter = adapter;
bindViews(itemView);
conversationListViewModel = new ViewModelProvider(fragment.getActivity(), new ConversationListViewModelFactory(Arrays.asList(Conversation.ConversationType.Single, Conversation.ConversationType.Group, Conversation.ConversationType.SecretChat), Arrays.asList(0)))
conversationListViewModel = new ViewModelProvider(fragment.getActivity(), new ConversationListViewModelFactory(Arrays.asList(Conversation.ConversationType.Single, Conversation.ConversationType.Group, Conversation.ConversationType.SecretChat, Conversation.ConversationType.ChatRoom), Arrays.asList(0)))
.get(ConversationListViewModel.class);
conversationViewModel = ViewModelProviders.of(fragment).get(ConversationViewModel.class);
}
Expand Down

0 comments on commit 9908310

Please sign in to comment.