进房历史消息查询方式优化(只在进房成功后查询一次,与最小化无关)

This commit is contained in:
huangjian
2022-07-20 16:39:11 +08:00
parent e18b5f612c
commit 3c3ca67a76
15 changed files with 113 additions and 153 deletions

View File

@@ -109,9 +109,6 @@ import com.yizhuan.xchat_android_core.room.bean.RoomModeType;
import com.yizhuan.xchat_android_core.room.bean.SimplePartyRoomInfo;
import com.yizhuan.xchat_android_core.room.dragonball.DragonBallModel;
import com.yizhuan.xchat_android_core.room.event.FinishAvRoomEvent;
import com.yizhuan.xchat_android_core.room.event.RoomClearScreenEvent;
import com.yizhuan.xchat_android_core.room.model.AvRoomModel;
import com.yizhuan.xchat_android_core.room.model.RoomBaseModel;
import com.yizhuan.xchat_android_core.room.pk.event.PKStateEvent;
import com.yizhuan.xchat_android_core.statistic.StatisticManager;
import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol;
@@ -122,7 +119,6 @@ import com.yizhuan.xchat_android_core.user.bean.UserInfo;
import com.yizhuan.xchat_android_core.utils.LogUtils;
import com.yizhuan.xchat_android_core.utils.StringUtils;
import com.yizhuan.xchat_android_library.base.factory.CreatePresenter;
import com.yizhuan.xchat_android_library.net.rxnet.callback.CallBack;
import com.yizhuan.xchat_android_library.utils.JavaUtil;
import com.yizhuan.xchat_android_library.utils.UIUtils;
@@ -366,7 +362,6 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
roomUid = newRoomUid;
// 相同类型的房间,但是是不同人的房间
if (AvRoomDataManager.get().isFirstEnterRoomOrChangeOtherRoom(roomUid)) {
EventBus.getDefault().post(new RoomClearScreenEvent());
showLoadingDialog();
dismissRedPackageDialog();
if (mRoomInfo == null) {
@@ -416,7 +411,7 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
EventBus.getDefault().register(this);
if (mAdapter == null) {
mAdapter = new VerticalViewPagerAdapter(this, !AvRoomDataManager.get().isFirstEnterRoomOrChangeOtherRoom(roomUid));
mAdapter = new VerticalViewPagerAdapter(this);
viewpager.setOffscreenPageLimit(2);
viewpager.setOrientation(ViewPager2.ORIENTATION_VERTICAL);
viewpager.getChildAt(0).setOverScrollMode(View.OVER_SCROLL_NEVER);
@@ -968,10 +963,6 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
@Override
public void onOk() {
// cp房切换嗨聊房弹框点击确定清屏并重置公屏数据
// 普通房切嗨聊房直接清屏(清屏调用在homePartyFragment 随机切换嗨聊房 监听)
// cp房切换嗨聊房不会先清屏防止用户点击取消按钮不进行切换房间操作但是公屏被清的情况
EventBus.getDefault().post(new RoomClearScreenEvent());
enterRoom(roomInfo);
}
});

View File

@@ -142,7 +142,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
private var mDisposable: Disposable? = null
private var isCloseScreen = false
private var isOpenRedPackage = false
private var isRoomMin = false
@JvmField
protected var isDatingMode = false
@@ -221,14 +220,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
softKeyboardListener()
}
override fun onInitArguments(bundle: Bundle?) {
super.onInitArguments(bundle)
if (bundle != null) {
isRoomMin = bundle.getBoolean(Constants.IS_ROOM_MIN, false)
}
}
@SuppressLint("CheckResult")
@CallSuper
override fun initiate() {
@@ -274,12 +265,7 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
GiftModel.get().refreshGiftList(AvRoomDataManager.get().roomUid.toString()).subscribe()
checkFollowOwner()
mvpPresenter?.loadRoomRank()
//最小化恢复时,更新礼物值
if (isRoomMin) {
GiftValueMrg.get().updateRoomGiftValue(false)
} else {
mvpPresenter?.loadMessageHistory(AvRoomDataManager.get().clearScreenTime)
}
}
@CallSuper
@@ -631,7 +617,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
*/
@Subscribe(threadMode = ThreadMode.MAIN)
fun onClearScreenEvent(event: RoomClearScreenEvent?) {
AvRoomDataManager.get().chatRoomDataRelease(false)
messageView.clear()
}
@@ -1115,11 +1100,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
}
}
override fun showMessageHistory(messages: List<ChatRoomMessage>?) {
messageView.addHistoryMessages(messages)
}
override fun onFollowSuccess(position: Int) {
StatisticManager.Instance()
.onEvent(StatisticsProtocol.EVENT_FOLLOW_OWNER_FROM_ROOM, "语音房-关注房主")

View File

@@ -12,6 +12,10 @@ import com.yizhuan.xchat_android_core.room.bean.RoomInfo
import com.yizhuan.xchat_android_core.room.model.AvRoomModel
import com.yizhuan.xchat_android_core.utils.CurrentTimeUtils
import com.yizhuan.xchat_android_core.utils.StringUtils
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import java.util.concurrent.TimeUnit
class FakeSingleRoomFragment : BaseViewBindingFragment<FragmentFakeSingleRoomBinding>() {
@@ -22,11 +26,7 @@ class FakeSingleRoomFragment : BaseViewBindingFragment<FragmentFakeSingleRoomBin
private val bgPicture = arrayOf("")
private var requesting = false
private var initBg = false
private val stopRunnable = {
if (!isDestroyView) {
binding.svgaImageViewBg.stopAnimation()
}
}
private var disposable: Disposable? = null
override fun init() {
}
@@ -36,9 +36,7 @@ class FakeSingleRoomFragment : BaseViewBindingFragment<FragmentFakeSingleRoomBin
if (!initBg) {
playSvgaBg(binding.svgaImageViewBg, "svga/single_back.svga")
initBg = true
}
if (!binding.svgaImageViewBg.isAnimating) {
binding.svgaImageViewBg.removeCallbacks(stopRunnable)
} else if (!binding.svgaImageViewBg.isAnimating) {
binding.svgaImageViewBg.startAnimation()
}
if (requesting || CurrentTimeUtils.getCurrentTime() - lastRequestTime < minRequestTime) {
@@ -80,8 +78,14 @@ class FakeSingleRoomFragment : BaseViewBindingFragment<FragmentFakeSingleRoomBin
lastRequestTime = 0
needJump = false
requesting = false
binding.svgaImageViewBg.removeCallbacks(stopRunnable)
binding.svgaImageViewBg.postDelayed(stopRunnable, 10 * 1000)
disposable?.dispose()
disposable = Single.timer(10, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
binding.svgaImageViewBg.stopAnimation()
}, {
it.printStackTrace()
})
}
private fun playSvgaBg(svgaRoomBg: SVGAImageView, assets: String) {
@@ -99,7 +103,9 @@ class FakeSingleRoomFragment : BaseViewBindingFragment<FragmentFakeSingleRoomBin
}
override fun onDestroyView() {
binding.svgaImageViewBg.removeCallbacks(stopRunnable)
initBg = false
disposable?.dispose()
binding.svgaImageViewBg.clear()
super.onDestroyView()
}
}

View File

@@ -44,11 +44,9 @@ class GameRoomFragment : BaseRoomFragment<IGameRoomView?, GameRoomPresenter?>(),
companion object {
@JvmStatic
fun newInstance(isRoomMin: Boolean): GameRoomFragment {
fun newInstance(): GameRoomFragment {
val roomFragment = GameRoomFragment()
val bundle = Bundle()
//是否是最小化进来
bundle.putBoolean(Constants.IS_ROOM_MIN, isRoomMin)
roomFragment.arguments = bundle
return roomFragment
}

View File

@@ -34,7 +34,6 @@ import com.yizhuan.erban.friend.view.SelectFriendActivity;
import com.yizhuan.erban.home.helper.OpenRoomHelper;
import com.yizhuan.erban.ui.widget.ShareDialog;
import com.yizhuan.erban.utils.RegexUtil;
import com.yizhuan.xchat_android_core.Constants;
import com.yizhuan.xchat_android_core.gift.bean.GiftMultiReceiverInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftReceiveInfo;
import com.yizhuan.xchat_android_core.gift.bean.LuckyBagGifts;
@@ -93,9 +92,6 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
private ImageView roomMore;
private ImageView ivRoomShare;
private boolean isRoomMin;
private GiftV2View giftView;
private ViewStub mVsGift2View;
@@ -112,11 +108,9 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
private SelectGameAdapter gameAdapter;
public static HomePartyFragment newInstance(boolean isRoomMin) {
public static HomePartyFragment newInstance() {
HomePartyFragment homePartyFragment = new HomePartyFragment();
Bundle bundle = new Bundle();
//是否是最小化进来
bundle.putBoolean(Constants.IS_ROOM_MIN, isRoomMin);
homePartyFragment.setArguments(bundle);
return homePartyFragment;
}
@@ -145,14 +139,6 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
roomId.setText(htmlText);
}
@Override
protected void onInitArguments(Bundle bundle) {
super.onInitArguments(bundle);
if (bundle != null) {
isRoomMin = bundle.getBoolean(Constants.IS_ROOM_MIN, false);
}
}
@Override
public int getRootLayoutId() {
return R.layout.fragment_chatroom_game_main;
@@ -403,17 +389,17 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
switch (currentRoomInfo.getType()) {
case RoomInfo.ROOMTYPE_GAME:
if (!(tempFragment instanceof GameRoomFragment)) {
tempFragment = GameRoomFragment.newInstance(isRoomMin);
tempFragment = GameRoomFragment.newInstance();
}
break;
case RoomInfo.ROOM_TYPE_SINGLE:
if (!(tempFragment instanceof SingleRoomFragment)) {
tempFragment = SingleRoomFragment.newInstance(isRoomMin);
tempFragment = SingleRoomFragment.newInstance();
}
break;
default:
if (!(tempFragment instanceof HomePartyRoomFragment)) {
tempFragment = HomePartyRoomFragment.newInstance(isRoomMin);
tempFragment = HomePartyRoomFragment.newInstance();
}
break;
}

View File

@@ -104,11 +104,9 @@ public class HomePartyRoomFragment extends BaseRoomFragment<IHomePartyView, Home
private PKMicQueueDialog pkMicQueueDialog;
private Disposable roomPkOrderDisposable;
public static HomePartyRoomFragment newInstance(boolean isRoomMin) {
public static HomePartyRoomFragment newInstance() {
HomePartyRoomFragment roomFragment = new HomePartyRoomFragment();
Bundle bundle = new Bundle();
//是否是最小化进来
bundle.putBoolean(Constants.IS_ROOM_MIN, isRoomMin);
roomFragment.setArguments(bundle);
return roomFragment;
}

View File

@@ -58,11 +58,9 @@ class SingleRoomFragment : BaseRoomFragment<ISingleRoomView?, SingleRoomPresente
companion object {
@JvmStatic
fun newInstance(isRoomMin: Boolean): SingleRoomFragment {
fun newInstance(): SingleRoomFragment {
val roomFragment = SingleRoomFragment()
val bundle = Bundle()
//是否是最小化进来
bundle.putBoolean(Constants.IS_ROOM_MIN, isRoomMin)
roomFragment.arguments = bundle
return roomFragment
}

View File

@@ -151,6 +151,7 @@ public class AvRoomPresenter extends BaseMvpPresenter<IAvRoomView> {
fromType == AVRoomActivity.FROM_TYPE_GAME_RECOMMEND ? 1 : 0
, fromUid)
.subscribe((stringServiceResult) -> EventBus.getDefault().post(new AudioPartyOpenEvent()));
mAvRoomModel.loadMessageHistory(AvRoomDataManager.get().clearScreenTime);
}, this::dealEnterRoomError);
}

View File

@@ -508,45 +508,6 @@ public class BaseRoomPresenter<V extends IBaseRoomView> extends BaseMvpPresenter
.subscribe(aLong -> getMvpView().noFollow2());
}
/**
* 公屏历史消息
*/
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);
}
if (getMvpView() != null) {
getMvpView().showMessageHistory(result);
}
}
}
});
}
}
/**
* 关注房主
*

View File

@@ -59,11 +59,6 @@ interface IBaseRoomView : IMvpBaseView {
*/
fun noFollow2()
/**
* 没有关注用户的监听
*/
fun showMessageHistory(messages: List<ChatRoomMessage>?)
/**
* 关注成功
* @param position

View File

@@ -1,6 +1,5 @@
package com.yizhuan.erban.avroom.widget;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_BOX;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_RED_PACKAGE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_BOX_ME;
import static com.yizhuan.xchat_android_core.redpackage.RedPackageTypeKt.ALL_DIAMOND;
@@ -11,7 +10,6 @@ import static com.yizhuan.xchat_android_core.redpackage.RedPackageTypeKt.ROOM_GI
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.text.Editable;
@@ -21,7 +19,6 @@ import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
@@ -44,16 +41,12 @@ import com.netease.nim.uikit.business.uinfo.UserInfoHelper;
import com.netease.nim.uikit.common.ui.span.RadiusBackgroundSpan;
import com.netease.nim.uikit.common.util.log.LogUtil;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
import com.netease.nimlib.sdk.InvocationFuture;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessageExtension;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomNotificationAttachment;
import com.netease.nimlib.sdk.msg.MessageBuilder;
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.netease.nimlib.sdk.msg.constant.NotificationType;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.orhanobut.logger.Logger;
import com.tongdaxing.erban.sadmin.utils.SaAttachmentToMsgUtil;
import com.yizhuan.erban.R;
import com.yizhuan.erban.UIHelper;
@@ -73,7 +66,6 @@ import com.yizhuan.erban.utils.RegexUtil;
import com.yizhuan.xchat_android_constants.XChatConstants;
import com.yizhuan.xchat_android_core.DemoCache;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.Constants;
import com.yizhuan.xchat_android_core.bean.attachmsg.RoomQueueMsgAttachment;
import com.yizhuan.xchat_android_core.decoration.car.bean.CarInfo;
import com.yizhuan.xchat_android_core.fansteam.FansTeamMsgInfo;
@@ -126,7 +118,6 @@ import com.yizhuan.xchat_android_core.magic.bean.MagicReceivedInfo;
import com.yizhuan.xchat_android_core.magic.bean.MagicReceiver;
import com.yizhuan.xchat_android_core.magic.bean.MultiMagicReceivedInfo;
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
import com.yizhuan.xchat_android_core.manager.IMMessageManager;
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
import com.yizhuan.xchat_android_core.miniworld.bean.MiniWorldInWorldInfo;
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterHuntingResult;
@@ -155,7 +146,6 @@ import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol;
import com.yizhuan.xchat_android_core.user.UserModel;
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
import com.yizhuan.xchat_android_core.utils.ExtensionUtil;
import com.yizhuan.xchat_android_core.utils.LogUtils;
import com.yizhuan.xchat_android_core.utils.net.DontWarnObserver;
import com.yizhuan.xchat_android_core.utils.net.RxHelper;
import com.yizhuan.xchat_android_core.vip.VipMessageInfo;
@@ -168,9 +158,7 @@ import com.yizhuan.xchat_android_library.utils.SizeUtils;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -186,7 +174,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import lombok.Setter;
/**
* 直播间消息界面
@@ -262,7 +249,7 @@ public class MessageView extends FrameLayout {
}
messageListView.scrollToPosition(mMessageAdapter.getItemCount() - 1);
disposable = AvRoomDataManager.get().getChatRoomMsgProcessor()
.subscribe(chatRoomMessage -> onCurrentRoomReceiveNewMsg(chatRoomMessage));
.subscribe(this::onCurrentRoomReceiveNewMsg);
}
@Override
@@ -409,8 +396,13 @@ public class MessageView extends FrameLayout {
}
public void onCurrentRoomReceiveNewMsg(ChatRoomMessage messages) {
addMessages(messages);
public void onCurrentRoomReceiveNewMsg(List<ChatRoomMessage> messages) {
if (messages == null) return;
if (messages.size() == 1) {
addMessages(messages.get(0));
} else {
addHistoryMessages(messages);
}
}
/**
@@ -425,13 +417,8 @@ public class MessageView extends FrameLayout {
checkAtMe(msg, false);
}
public void addHistoryMessages(List<ChatRoomMessage> messages) {
private void addHistoryMessages(List<ChatRoomMessage> messages) {
chatRoomMessages.addAll(chatRoomMessages.size() > 0 ? 1 : 0, messages);
//同步AvRoomDataManager里面的公屏消息列表
List<ChatRoomMessage> cacheMessages = AvRoomDataManager.get().getChatRoomMessages();
cacheMessages.addAll(cacheMessages.size() > 0 ? 1 : 0, messages);
mMessageAdapter.notifyDataSetChanged();
messageListView.scrollToPosition(mMessageAdapter.getItemCount() - 1);
for (ChatRoomMessage message : messages) {

View File

@@ -21,12 +21,10 @@ import com.yizhuan.erban.avroom.fragment.HomePartyFragment;
public class VerticalViewPagerAdapter extends FragmentStateAdapter {
private final SparseArray<Fragment> fragmentList;
private final boolean isRoomMin;
public VerticalViewPagerAdapter(FragmentActivity fm, boolean isRoomMin) {
public VerticalViewPagerAdapter(FragmentActivity fm) {
super(fm);
fragmentList = new SparseArray<>();
this.isRoomMin = isRoomMin;
}
@@ -36,7 +34,7 @@ public class VerticalViewPagerAdapter extends FragmentStateAdapter {
Fragment fragment = fragmentList.get(position);
if (fragment == null) {
if (position == 0) {
fragment = HomePartyFragment.newInstance(isRoomMin);
fragment = HomePartyFragment.newInstance();
} else {
fragment = new FakeSingleRoomFragment();
}

View File

@@ -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)));
}
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) return;
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;
}

View File

@@ -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);
}
}
});
}
}
}

View File

@@ -179,4 +179,6 @@ public interface IAvRoomModel extends IModel {
Single<List<HomeRoomInfo>> getRecommendRoomList(String roomId);
Single<RoomInfo> getNextSingleRoomInfo();
void loadMessageHistory(long startTime);
}