feat : 去掉公聊大厅代码
This commit is contained in:
@@ -30,7 +30,6 @@ import com.chwl.core.module_hall.hall.HallModel;
|
||||
import com.chwl.core.monsterhunting.bean.MonsterInfo;
|
||||
import com.chwl.core.monsterhunting.model.MonsterHuntingModel;
|
||||
import com.chwl.core.patriarch.exception.PmRoomLimitException;
|
||||
import com.chwl.core.public_chat_hall.manager.PublicChatHallDataManager;
|
||||
import com.chwl.core.room.anotherroompk.RoomPKModel;
|
||||
import com.chwl.core.room.bean.RoomInfo;
|
||||
import com.chwl.core.room.giftvalue.helper.GiftValueMrg;
|
||||
@@ -60,7 +59,6 @@ import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
@@ -98,12 +96,7 @@ public class AvRoomPresenter extends BaseMvpPresenter<IAvRoomView> {
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
public void enterRoom(@NonNull RoomInfo roomInfo, int fromType, String fromNick, String fromUid) {
|
||||
if (!TextUtils.isEmpty(PublicChatHallDataManager.get().getPublicChatHallUid()) &&
|
||||
Objects.equals(roomInfo.getUid(), Long.parseLong(
|
||||
PublicChatHallDataManager.get().getPublicChatHallUid()))) {
|
||||
dealEnterRoomError(new Throwable("13002"));
|
||||
return;
|
||||
}
|
||||
|
||||
final RoomInfo currentRoom = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (currentRoom != null) {
|
||||
if (currentRoom.getUid() == roomInfo.getUid()) {
|
||||
|
@@ -30,7 +30,6 @@ import com.chwl.core.initial.bean.InitInfo;
|
||||
import com.chwl.core.initial.bean.SplashComponent;
|
||||
import com.chwl.core.manager.AvRoomDataManager;
|
||||
import com.chwl.core.noble.NobleDataManager;
|
||||
import com.chwl.core.public_chat_hall.manager.PublicChatHallDataManager;
|
||||
import com.chwl.core.room.face.DynamicFaceModel;
|
||||
import com.chwl.core.user.UserModel;
|
||||
import com.chwl.core.user.bean.UserInfo;
|
||||
@@ -262,16 +261,7 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
SharedPreferenceUtils.setExchangeGoldRate(initInfo.getExchangeGoldRate());
|
||||
}
|
||||
|
||||
// 获取公聊大厅的 ID
|
||||
if (initInfo.getPublicChatRoomId() != 0) {
|
||||
PublicChatHallDataManager.get().setPublicChatHallId(initInfo.getPublicChatRoomId());
|
||||
}
|
||||
|
||||
// 获取公聊大厅房间 UID
|
||||
if (!TextUtils.isEmpty(initInfo.getPublicChatRoomUid())) {
|
||||
publicChatHallUid = initInfo.getPublicChatRoomUid();
|
||||
PublicChatHallDataManager.get().setPublicChatHallUid(initInfo.getPublicChatRoomUid());
|
||||
}
|
||||
|
||||
// 是否可以开启 一起玩 按钮
|
||||
AvRoomDataManager.get().setAllowedToPlayTogether(initInfo.isPlayTogether());
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package com.chwl.core.initial.bean;
|
||||
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.chwl.core.monsterhunting.bean.MonsterInitInfo;
|
||||
import com.chwl.core.noble.bean.NobleRight;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
@@ -49,12 +48,7 @@ public class InitInfo implements Serializable {
|
||||
*/
|
||||
private String webHostName;
|
||||
|
||||
// 公聊大厅 ID
|
||||
private long publicChatRoomId;
|
||||
// 公聊大厅房间Uid
|
||||
private String publicChatRoomUid;
|
||||
// 公聊大厅等级限制
|
||||
private int publicChatRoomLevelNo;
|
||||
|
||||
// 私聊等级限制
|
||||
private int privateChatLevelNo;
|
||||
// 私聊注册天数限制
|
||||
|
@@ -95,7 +95,6 @@ import com.chwl.core.msg.sysv2.bean.ErbanSysMsgV2Info;
|
||||
import com.chwl.core.noble.NobleResourceType;
|
||||
import com.chwl.core.noble.NobleUtil;
|
||||
import com.chwl.core.noble.bean.NobleInfo;
|
||||
import com.chwl.core.public_chat_hall.manager.PublicChatHallDataManager;
|
||||
import com.chwl.core.redpackage.bean.RedPackageLuckyBag;
|
||||
import com.chwl.core.retry.ImRetryManager;
|
||||
import com.chwl.core.retry.ReconnectListener;
|
||||
@@ -622,9 +621,7 @@ public final class IMNetEaseManager {
|
||||
}
|
||||
|
||||
private boolean filterAnotherChatRoomInternal(String sessionId) {
|
||||
if (Objects.equals(sessionId, String.valueOf(PublicChatHallDataManager.get().getPublicChatHallId()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Objects.equals(sessionId, gameChatRoomId)) {
|
||||
return true;
|
||||
}
|
||||
|
@@ -1,348 +0,0 @@
|
||||
package com.chwl.core.public_chat_hall.manager;
|
||||
|
||||
import static com.netease.nimlib.sdk.msg.constant.NotificationType.ChatRoomMemberTempMuteAdd;
|
||||
|
||||
import android.os.CountDownTimer;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.netease.nim.uikit.business.session.module.Container;
|
||||
import com.netease.nimlib.sdk.NIMChatRoomSDK;
|
||||
import com.netease.nimlib.sdk.NIMClient;
|
||||
import com.netease.nimlib.sdk.Observer;
|
||||
import com.netease.nimlib.sdk.RequestCallbackWrapper;
|
||||
import com.netease.nimlib.sdk.ResponseCode;
|
||||
import com.netease.nimlib.sdk.chatroom.ChatRoomMessageBuilder;
|
||||
import com.netease.nimlib.sdk.chatroom.ChatRoomService;
|
||||
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.ChatRoomNotificationAttachment;
|
||||
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
|
||||
import com.netease.nimlib.sdk.msg.attachment.NotificationAttachment;
|
||||
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
|
||||
import com.netease.nimlib.sdk.msg.model.IMMessage;
|
||||
import com.netease.nimlib.sdk.msg.model.QueryDirectionEnum;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.chwl.core.R;
|
||||
import com.chwl.core.auth.AuthModel;
|
||||
import com.chwl.core.gift.GiftModel;
|
||||
import com.chwl.core.gift.bean.GiftInfo;
|
||||
import com.chwl.core.gift.bean.GiftReceiveInfo;
|
||||
import com.chwl.core.im.custom.bean.CustomAttachment;
|
||||
import com.chwl.core.im.custom.bean.GiftAttachment;
|
||||
import com.chwl.core.public_chat_hall.attachment.AitFriendsAttachment;
|
||||
import com.chwl.core.public_chat_hall.bean.AitFriendsInfo;
|
||||
import com.chwl.core.public_chat_hall.event.PublicChatHallAitMeEvent;
|
||||
import com.chwl.core.public_chat_hall.event.PublicChatHallHistoryEvent;
|
||||
import com.chwl.core.public_chat_hall.event.PublicChatHallMsgCountingDownEvent;
|
||||
import com.chwl.core.public_chat_hall.event.PublicChatHallMsgIncomingEvent;
|
||||
import com.chwl.core.public_chat_hall.event.PublicChatHallPlayGiftAnimationEvent;
|
||||
import com.chwl.library.utils.ListUtils;
|
||||
import com.chwl.library.utils.ResUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 公聊大厅数据管理类
|
||||
*/
|
||||
public class PublicChatHallDataManager {
|
||||
|
||||
private static final String TAG = "PublicChatHallDataMgr";
|
||||
private static final int LOAD_MESSAGE_COUNT = 10;
|
||||
private static final int MAX_MESSAGE_SIZE = 1000;
|
||||
|
||||
|
||||
/**
|
||||
* 房间管理员集合
|
||||
*/
|
||||
public List<ChatRoomMember> mRoomManagerList;
|
||||
public ChatRoomMember mOwnerMember;
|
||||
private static final class Helper {
|
||||
private static final PublicChatHallDataManager INSTANCE = new PublicChatHallDataManager();
|
||||
}
|
||||
|
||||
public static PublicChatHallDataManager get() {
|
||||
return Helper.INSTANCE;
|
||||
}
|
||||
|
||||
private PublicChatHallDataManager() {
|
||||
registerInComingRoomMessage();
|
||||
mRoomManagerList = new ArrayList<>();
|
||||
mOwnerMember = new ChatRoomMember();
|
||||
}
|
||||
|
||||
// 公聊大厅 ID
|
||||
private long publicChatHallId;
|
||||
// 公聊大厅房间 UID
|
||||
private String publicChatHallUid;
|
||||
|
||||
// 缓存消息列表
|
||||
private volatile List<ChatRoomMessage> messages = new ArrayList<>();
|
||||
|
||||
public long getPublicChatHallId() {
|
||||
return publicChatHallId;
|
||||
}
|
||||
|
||||
public void setPublicChatHallId(long publicChatHallId) {
|
||||
this.publicChatHallId = publicChatHallId;
|
||||
}
|
||||
|
||||
public String getPublicChatHallUid() {
|
||||
return publicChatHallUid;
|
||||
}
|
||||
|
||||
public void setPublicChatHallUid(String publicChatHallUid) {
|
||||
this.publicChatHallUid = publicChatHallUid;
|
||||
}
|
||||
|
||||
public boolean isRoomAdmin() {
|
||||
return mOwnerMember.getMemberType() == MemberType.ADMIN;
|
||||
}
|
||||
|
||||
public boolean isRoomAdmin(String account) {
|
||||
if (ListUtils.isListEmpty(mRoomManagerList)) return false;
|
||||
for (ChatRoomMember chatRoomMember : mRoomManagerList) {
|
||||
if (Objects.equals(chatRoomMember.getAccount(), account)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void registerInComingRoomMessage() {
|
||||
Observer<List<ChatRoomMessage>> incomingChatObserver = (Observer<List<ChatRoomMessage>>) chatRoomMessages -> {
|
||||
if (ListUtils.isListEmpty(chatRoomMessages)) return;
|
||||
dealChatMessage(chatRoomMessages);
|
||||
};
|
||||
NIMChatRoomSDK.getChatRoomServiceObserve().observeReceiveMessage(incomingChatObserver, true);
|
||||
}
|
||||
|
||||
private void dealChatMessage(List<ChatRoomMessage> chatRoomMessages) {
|
||||
ArrayList<ChatRoomMessage> messages = new ArrayList<>();
|
||||
for (ChatRoomMessage msg : chatRoomMessages) {
|
||||
// 过滤其他房间的信息
|
||||
if (filterAnotherChatRoom(msg)) return;
|
||||
if (msg.getMsgType() == MsgTypeEnum.notification) {
|
||||
NotificationAttachment attachment = (NotificationAttachment) msg.getAttachment();
|
||||
if (attachment == null) continue;
|
||||
if (attachment.getType() == ChatRoomMemberTempMuteAdd) {
|
||||
List<String> targets = ((ChatRoomNotificationAttachment) attachment).getTargets();
|
||||
}
|
||||
} else if (msg.getMsgType() == MsgTypeEnum.custom) {
|
||||
MsgAttachment attachment = msg.getAttachment();
|
||||
if (attachment == null) return;
|
||||
|
||||
//自定义消息
|
||||
CustomAttachment customAttachment = (CustomAttachment) msg.getAttachment();
|
||||
// if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_AUCTION
|
||||
// || customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_GIFT
|
||||
// || customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_ROOM_TIP
|
||||
// || customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_SEND_MAGIC
|
||||
// || customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_MULTI_GIFT
|
||||
// || customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_KICK_MIC
|
||||
// || customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_MONSTER_HUNTING) {
|
||||
// addMessages(msg);
|
||||
// }
|
||||
Logger.i(ResUtil.getString(R.string.public_chat_hall_manager_publicchathalldatamanager_01) + customAttachment);
|
||||
int second = customAttachment.getSecond();
|
||||
switch (customAttachment.getFirst()) {
|
||||
case CustomAttachment.CUSTOM_MSG_PUBLIC_CHAT_HALL:
|
||||
switch (second) {
|
||||
// 艾特人
|
||||
case CustomAttachment.CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_AIT:
|
||||
AitFriendsAttachment aitFriendsAttachment = (AitFriendsAttachment) customAttachment;
|
||||
AitFriendsInfo aitFriendsInfo = aitFriendsAttachment.getAitFriendsInfo();
|
||||
List<String> atUids = aitFriendsInfo.getAtUids();
|
||||
// 有艾特到我了,就发出去给首页,让首页提醒显示
|
||||
if (atUids != null && atUids.contains(String.valueOf(AuthModel.get().getCurrentUid()))) {
|
||||
EventBus.getDefault()
|
||||
.post(new PublicChatHallAitMeEvent().setNick(msg.getFromNick()));
|
||||
}
|
||||
break;
|
||||
|
||||
// 礼物
|
||||
case CustomAttachment.CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_GIFT:
|
||||
GiftAttachment giftAttachment = (GiftAttachment) customAttachment;
|
||||
GiftReceiveInfo giftReceiveInfo = giftAttachment.getGiftReceiveInfo();
|
||||
if (giftReceiveInfo != null) {
|
||||
GiftInfo giftInfo = giftReceiveInfo.getGift();
|
||||
if (giftInfo == null) {
|
||||
giftInfo = GiftModel.get().findGiftInfoById(giftReceiveInfo.getGiftId());
|
||||
}
|
||||
// 要大于等于66钻石的时候才有动画效果
|
||||
if (giftInfo.getGoldPrice() * giftReceiveInfo.getGiftNum() >= 66) {
|
||||
EventBus.getDefault()
|
||||
.post(new PublicChatHallPlayGiftAnimationEvent()
|
||||
.setGiftReceiveInfo(giftReceiveInfo));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
addMessages(msg);
|
||||
} else if (msg.getMsgType() == MsgTypeEnum.text) {
|
||||
addMessages(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean filterAnotherChatRoom(ChatRoomMessage chatRoomMessage) {
|
||||
return chatRoomMessage != null && filterAnotherChatRoomInternal(chatRoomMessage.getSessionId());
|
||||
}
|
||||
|
||||
private boolean filterAnotherChatRoomInternal(String sessionId) {
|
||||
String roomId = String.valueOf(PublicChatHallDataManager.get().getPublicChatHallId());
|
||||
System.out.println("publicChatHallId: " + roomId + ", sessionId: " + sessionId);
|
||||
boolean notTheSameRoom = !Objects.equals(roomId, sessionId);
|
||||
return !(TextUtils.isEmpty(sessionId) || TextUtils.isEmpty(roomId)) && notTheSameRoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自己发的消息插入到消息队列里
|
||||
*
|
||||
* @param chatRoomMessage
|
||||
*/
|
||||
public void pushMyMessage(ChatRoomMessage chatRoomMessage) {
|
||||
if (!messages.contains(chatRoomMessage)) {
|
||||
addMessages(chatRoomMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加消息到公聊大厅
|
||||
* <p>
|
||||
* 由于拉取历史(loadHistory) 的时候,拉取到的数据是从新到旧的排序顺序,
|
||||
* 所以这里新数据就要用头插法的方式缓存起来
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
private void addMessages(ChatRoomMessage msg) {
|
||||
if (msg != null && !checkNoNeedMsg(msg)) {
|
||||
messages.add(0, msg);
|
||||
noticeReceiverMessage(msg);
|
||||
keepSizeUnderLimit();
|
||||
}
|
||||
}
|
||||
|
||||
private void keepSizeUnderLimit() {
|
||||
while (messages.size() > MAX_MESSAGE_SIZE) {
|
||||
messages.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkNoNeedMsg(ChatRoomMessage msg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void noticeReceiverMessage(ChatRoomMessage chatRoomMessage) {
|
||||
EventBus.getDefault().post(new PublicChatHallMsgIncomingEvent()
|
||||
.setChatRoomMessage(chatRoomMessage));
|
||||
}
|
||||
|
||||
public List<ChatRoomMessage> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页登录完后进入公聊大厅的聊天室,进入成功后通过此方法来拉取历史记录,方便首页上进行展示
|
||||
*/
|
||||
public void loadHistory() {
|
||||
IMMessage anchor = ChatRoomMessageBuilder.createEmptyChatRoomMessage(String.valueOf(publicChatHallId), 0);
|
||||
NIMClient.getService(ChatRoomService.class)
|
||||
.pullMessageHistoryExType(String.valueOf(publicChatHallId), anchor.getTime(),
|
||||
LOAD_MESSAGE_COUNT, QueryDirectionEnum.QUERY_OLD,
|
||||
new MsgTypeEnum[]{MsgTypeEnum.custom, MsgTypeEnum.text})
|
||||
.setCallback(new RequestCallbackWrapper<List<ChatRoomMessage>>() {
|
||||
@Override
|
||||
public void onResult(int code, List<ChatRoomMessage> result, Throwable exception) {
|
||||
if (code == ResponseCode.RES_SUCCESS && messages != null) {
|
||||
messages.clear();
|
||||
messages.addAll(result);
|
||||
EventBus.getDefault().post(new PublicChatHallHistoryEvent()
|
||||
.setMessages(result));
|
||||
} else {
|
||||
if (exception != null) {
|
||||
exception.printStackTrace();
|
||||
} else {
|
||||
Log.e(TAG, "onResult: code: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 进入公聊大厅页面,加载历史记录
|
||||
*/
|
||||
public void fetchHistory(Container container, IMMessage anchor, RequestCallbackWrapper callback) {
|
||||
NIMClient.getService(ChatRoomService.class)
|
||||
.pullMessageHistoryExType(container.account, anchor.getTime(),
|
||||
LOAD_MESSAGE_COUNT, QueryDirectionEnum.QUERY_OLD,
|
||||
new MsgTypeEnum[]{MsgTypeEnum.custom, MsgTypeEnum.text})
|
||||
.setCallback(new RequestCallbackWrapper<List<ChatRoomMessage>>() {
|
||||
@Override
|
||||
public void onResult(int code, List<ChatRoomMessage> result, Throwable exception) {
|
||||
if (code == ResponseCode.RES_SUCCESS && messages != null) {
|
||||
if (anchor.getTime() == 0) {
|
||||
messages.clear();
|
||||
}
|
||||
messages.addAll(result);
|
||||
}
|
||||
callback.onResult(code, result, exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public long millisUntilFinished = -1;
|
||||
private CountDownTimer timer = new CountDownTimer(5 * 1000, 1000) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
PublicChatHallDataManager.this.millisUntilFinished = millisUntilFinished;
|
||||
EventBus.getDefault().post(new PublicChatHallMsgCountingDownEvent()
|
||||
.setFinish(false)
|
||||
.setMillisUntilFinished(millisUntilFinished));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
PublicChatHallDataManager.this.millisUntilFinished = -1;
|
||||
EventBus.getDefault().post(new PublicChatHallMsgCountingDownEvent()
|
||||
.setFinish(true));
|
||||
}
|
||||
};
|
||||
|
||||
public void startCountingDown() {
|
||||
timer.start();
|
||||
PublicChatHallDataManager.this.millisUntilFinished = 5 * 1000;
|
||||
}
|
||||
|
||||
public void addManagerMember(ChatRoomMember member) {
|
||||
if (member == null) {
|
||||
return;
|
||||
}
|
||||
if (mRoomManagerList == null) {
|
||||
mRoomManagerList = new ArrayList<>();
|
||||
}
|
||||
boolean isContain = false;
|
||||
//ChatRoomMember没有重写equals方法
|
||||
for (ChatRoomMember index : mRoomManagerList) {
|
||||
if (index != null && !TextUtils.isEmpty(index.getAccount()) &&
|
||||
index.getAccount().equals(member.getAccount())) {
|
||||
isContain = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isContain) {
|
||||
mRoomManagerList.add(member);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user