进房历史消息查询方式优化(只在进房成功后查询一次,与最小化无关)
This commit is contained in:
@@ -28,6 +28,7 @@ import com.yizhuan.xchat_android_core.im.custom.bean.RoomPkBean;
|
||||
import com.yizhuan.xchat_android_core.room.bean.BoxSwitchVo;
|
||||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||||
import com.yizhuan.xchat_android_core.room.bean.SimplePartyRoomInfo;
|
||||
import com.yizhuan.xchat_android_core.room.event.RoomClearScreenEvent;
|
||||
import com.yizhuan.xchat_android_core.room.game.GameStatus;
|
||||
import com.yizhuan.xchat_android_core.room.giftvalue.helper.GiftValueMrg;
|
||||
import com.yizhuan.xchat_android_core.room.ktv.event.KtvEvent;
|
||||
@@ -40,8 +41,11 @@ import com.yizhuan.xchat_android_core.utils.StringUtils;
|
||||
import com.yizhuan.xchat_android_library.rxbus.RxBus;
|
||||
import com.yizhuan.xchat_android_library.utils.ListUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
@@ -89,6 +93,7 @@ public final class AvRoomDataManager {
|
||||
public final List<ChatRoomMember> roomSuperAdminList = new ArrayList<>();
|
||||
@NonNull
|
||||
public final MutableLiveData<RoomPkBean> roomPkLiveData = new MutableLiveData<>();
|
||||
private final PublishProcessor<List<ChatRoomMessage>> chatRoomMsgProcessor = PublishProcessor.create();
|
||||
@Nullable
|
||||
public RoomInfo mCurrentRoomInfo;
|
||||
public BoxSwitchVo mBoxSwitchVo;
|
||||
@@ -158,7 +163,6 @@ public final class AvRoomDataManager {
|
||||
* 龙珠数组
|
||||
*/
|
||||
public List<Integer> dragons;
|
||||
|
||||
// 房主基本信息
|
||||
public String nick;
|
||||
public int gender;
|
||||
@@ -174,7 +178,6 @@ public final class AvRoomDataManager {
|
||||
public String trtcSig;
|
||||
//清空公屏消息时间
|
||||
public long clearScreenTime;
|
||||
|
||||
public boolean showPkBeginTime;
|
||||
public long pkBeginTime;
|
||||
/**
|
||||
@@ -202,7 +205,6 @@ public final class AvRoomDataManager {
|
||||
* 公屏数据
|
||||
*/
|
||||
private List<ChatRoomMessage> chatRoomMessages = new LinkedList<>();
|
||||
private PublishProcessor<ChatRoomMessage> chatRoomMsgProcessor = PublishProcessor.create();
|
||||
|
||||
private AvRoomDataManager() {
|
||||
mRoomManagerList = new ArrayList<>();
|
||||
@@ -222,6 +224,7 @@ public final class AvRoomDataManager {
|
||||
}
|
||||
|
||||
public void release() {
|
||||
EventBus.getDefault().post(new RoomClearScreenEvent());
|
||||
IMNetEaseManager.get().release();
|
||||
AudioEngineManager.get().leaveChannel();
|
||||
clear();
|
||||
@@ -863,19 +866,27 @@ public final class AvRoomDataManager {
|
||||
|
||||
public void addChatRoomMessage(ChatRoomMessage msg) {
|
||||
if (msg == null) return;
|
||||
addChatRoomMessages(new ArrayList<>(Collections.singletonList(msg)));
|
||||
}
|
||||
|
||||
if (msg.getMsgType() == MsgTypeEnum.notification) {
|
||||
NotificationAttachment attachment = (NotificationAttachment) msg.getAttachment();
|
||||
if (attachment != null && attachment.getType() == NotificationType.ChatRoomMemberIn) {
|
||||
boolean isSuperAdmin = SuperAdminUtil.isSuperAdmin(msg);
|
||||
if (isSuperAdmin) return;
|
||||
public void addChatRoomMessages(List<ChatRoomMessage> msgList) {
|
||||
if (ListUtils.isListEmpty(msgList)) return;
|
||||
|
||||
Iterator<ChatRoomMessage> iterator = msgList.iterator();
|
||||
ChatRoomMessage msg;
|
||||
while (iterator.hasNext()) {
|
||||
msg = iterator.next();
|
||||
if (msg.getMsgType() == MsgTypeEnum.notification) {
|
||||
NotificationAttachment attachment = (NotificationAttachment) msg.getAttachment();
|
||||
if (attachment != null && attachment.getType() == NotificationType.ChatRoomMemberIn) {
|
||||
boolean isSuperAdmin = SuperAdminUtil.isSuperAdmin(msg);
|
||||
if (isSuperAdmin) iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
chatRoomMessages.add(msg);
|
||||
if (chatRoomMsgProcessor != null) {
|
||||
chatRoomMsgProcessor.onNext(msg);
|
||||
}
|
||||
chatRoomMessages.addAll(msgList);
|
||||
chatRoomMsgProcessor.onNext(msgList);
|
||||
keepSizeUnderLimit();
|
||||
}
|
||||
|
||||
@@ -885,7 +896,7 @@ public final class AvRoomDataManager {
|
||||
}
|
||||
}
|
||||
|
||||
public PublishProcessor<ChatRoomMessage> getChatRoomMsgProcessor() {
|
||||
public PublishProcessor<List<ChatRoomMessage>> getChatRoomMsgProcessor() {
|
||||
return chatRoomMsgProcessor;
|
||||
}
|
||||
|
||||
@@ -1085,7 +1096,7 @@ public final class AvRoomDataManager {
|
||||
List<String> accounts = new ArrayList<>();
|
||||
accounts.add(String.valueOf(uid));
|
||||
NIMChatRoomSDK.getChatRoomService().fetchRoomMembersByIds(
|
||||
String.valueOf(getRoomId()), accounts)
|
||||
String.valueOf(getRoomId()), accounts)
|
||||
.setCallback(new RequestCallback<List<ChatRoomMember>>() {
|
||||
@Override
|
||||
public void onSuccess(List<ChatRoomMember> param) {
|
||||
|
@@ -7,19 +7,27 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.netease.nimlib.sdk.AbortableFuture;
|
||||
import com.netease.nimlib.sdk.NIMChatRoomSDK;
|
||||
import com.netease.nimlib.sdk.NIMClient;
|
||||
import com.netease.nimlib.sdk.RequestCallback;
|
||||
import com.netease.nimlib.sdk.RequestCallbackWrapper;
|
||||
import com.netease.nimlib.sdk.ResponseCode;
|
||||
import com.netease.nimlib.sdk.chatroom.ChatRoomService;
|
||||
import com.netease.nimlib.sdk.chatroom.constant.MemberQueryType;
|
||||
import com.netease.nimlib.sdk.chatroom.constant.MemberType;
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMember;
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
|
||||
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomData;
|
||||
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomResultData;
|
||||
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
|
||||
import com.netease.nimlib.sdk.msg.model.QueryDirectionEnum;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
|
||||
import com.yizhuan.xchat_android_core.decoration.car.bean.CarInfo;
|
||||
import com.yizhuan.xchat_android_core.decoration.headwear.bean.HeadWearInfo;
|
||||
import com.yizhuan.xchat_android_core.home.bean.HomeRoomInfo;
|
||||
import com.yizhuan.xchat_android_core.initial.InitialModel;
|
||||
import com.yizhuan.xchat_android_core.initial.bean.InitInfo;
|
||||
import com.yizhuan.xchat_android_core.level.UserLevelVo;
|
||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||
@@ -52,6 +60,7 @@ import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -618,4 +627,43 @@ public class AvRoomModel extends RoomBaseModel implements IAvRoomModel {
|
||||
.compose(RxHelper.handleBeanData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
/**
|
||||
* 公屏历史消息
|
||||
*/
|
||||
@Override
|
||||
public void loadMessageHistory(long startTime) {
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
|
||||
if (roomInfo == null) return;
|
||||
if (!roomInfo.isCloseScreen()) {
|
||||
int count = 10;
|
||||
InitInfo initInfo = InitialModel.get().getCacheInitInfo();
|
||||
if (initInfo != null) count = initInfo.getRoomMessageCount();
|
||||
int finalCount = count;
|
||||
NIMClient.getService(ChatRoomService.class)
|
||||
.pullMessageHistoryExType(
|
||||
String.valueOf(roomInfo.getRoomId()),
|
||||
startTime,
|
||||
count,
|
||||
startTime == 0 ? QueryDirectionEnum.QUERY_OLD : QueryDirectionEnum.QUERY_NEW,
|
||||
new MsgTypeEnum[]{MsgTypeEnum.text})
|
||||
.setCallback(new RequestCallbackWrapper<List<ChatRoomMessage>>() {
|
||||
@Override
|
||||
public void onResult(int code, List<ChatRoomMessage> result, Throwable exception) {
|
||||
if (code == ResponseCode.RES_SUCCESS && result != null && result.size() > 0) {
|
||||
if (startTime != 0 && result.size() >= finalCount) {
|
||||
loadMessageHistory(0);
|
||||
return;
|
||||
}
|
||||
if (startTime == 0) {
|
||||
Collections.reverse(result);
|
||||
}
|
||||
AvRoomDataManager.get().addChatRoomMessages(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -179,4 +179,6 @@ public interface IAvRoomModel extends IModel {
|
||||
Single<List<HomeRoomInfo>> getRecommendRoomList(String roomId);
|
||||
|
||||
Single<RoomInfo> getNextSingleRoomInfo();
|
||||
|
||||
void loadMessageHistory(long startTime);
|
||||
}
|
||||
|
Reference in New Issue
Block a user