feat:完成消息页UI改版(删除部分无用代码)
This commit is contained in:
@@ -28,8 +28,6 @@ import com.chwl.core.im.custom.bean.MultiLuckyGiftAttachment;
|
||||
import com.chwl.core.manager.AvRoomDataManager;
|
||||
import com.chwl.core.manager.IMNetEaseManager;
|
||||
import com.chwl.core.manager.RoomEvent;
|
||||
import com.chwl.core.public_chat_hall.manager.PublicChatHallDataManager;
|
||||
import com.chwl.core.public_chat_hall.model.PublicChatHallModel;
|
||||
import com.chwl.core.retry.ImRetryManager;
|
||||
import com.chwl.core.room.bean.RoomInfo;
|
||||
import com.chwl.core.user.UserModel;
|
||||
@@ -481,76 +479,4 @@ public class GiftToolbox {
|
||||
return IMNetEaseManager.get()
|
||||
.sendMessageSingle(imMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公聊大厅发送礼物消息
|
||||
*
|
||||
* @param multiGiftReceiveInfo
|
||||
*/
|
||||
public static Single<ChatRoomMessage> sendGiftPublicChatHallMessage(GiftMultiReceiverInfo multiGiftReceiveInfo) {
|
||||
UserInfo myUserInfo = UserModel.get().getCacheLoginUserInfo();
|
||||
if (myUserInfo == null) return null;
|
||||
GiftReceiveInfo giftReceiveInfo = new GiftReceiveInfo();
|
||||
GiftAttachment giftAttachment = new GiftAttachment(CustomAttachment.CUSTOM_MSG_PUBLIC_CHAT_HALL,
|
||||
CustomAttachment.CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_GIFT);
|
||||
giftAttachment.setUid(myUserInfo.getUid() + "");
|
||||
giftReceiveInfo.setUid(myUserInfo.getUid());
|
||||
giftReceiveInfo.setNick(myUserInfo.getNick());
|
||||
giftReceiveInfo.setAvatar(myUserInfo.getAvatar());
|
||||
List<GiftReceiver> targetUsers = multiGiftReceiveInfo.getTargetUsers();
|
||||
if (!ListUtils.isListEmpty(targetUsers) && targetUsers.size() >= 1) {
|
||||
giftReceiveInfo.setTargetUid(targetUsers.get(0).getUid());
|
||||
giftReceiveInfo.setTargetNick(targetUsers.get(0).getNick());
|
||||
giftReceiveInfo.setTargetAvatar(targetUsers.get(0).getAvatar());
|
||||
}
|
||||
giftReceiveInfo.setGiftNum(multiGiftReceiveInfo.getGiftNum());
|
||||
giftAttachment.setGiftReceiveInfo(giftReceiveInfo);
|
||||
giftReceiveInfo.setGift(multiGiftReceiveInfo.getGift());
|
||||
ChatRoomMessage imMessage = ChatRoomMessageBuilder.createChatRoomCustomMessage(PublicChatHallDataManager.get().getPublicChatHallId() + "",
|
||||
giftAttachment);
|
||||
return PublicChatHallModel.get().sendChatRoomMessage(imMessage, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 群聊送礼消息
|
||||
*/
|
||||
public static Single<IMMessage> sendGiftTeamMessage(String sessionId, GiftMultiReceiverInfo multiGiftReceiveInfo) {
|
||||
UserInfo myUserInfo = UserModel.get().getCacheLoginUserInfo();
|
||||
if (myUserInfo == null) return Single.error(new Throwable("current cached user is null"));
|
||||
GiftInfo giftInfo = multiGiftReceiveInfo.getGift();
|
||||
int giftId = multiGiftReceiveInfo.getGiftId();
|
||||
giftId = giftId > 0 ? giftId : giftInfo != null ? giftInfo.getGiftId() : 0;
|
||||
if (giftInfo == null) {
|
||||
giftInfo = new GiftInfo();
|
||||
giftInfo.setGiftId(giftId);
|
||||
giftInfo.setCount(multiGiftReceiveInfo.getGiftNum());
|
||||
}
|
||||
Long targetUid = multiGiftReceiveInfo.getTargetUsers().get(0).getUid();
|
||||
String targetNick = multiGiftReceiveInfo.getTargetUsers().get(0).getNick();
|
||||
GiftAttachment giftAttachment = new GiftAttachment(CustomAttachment.CUSTOM_MSG_HEADER_TYPE_GIFT,
|
||||
CustomAttachment.CUSTOM_MSG_SUB_TYPE_SEND_GIFT);
|
||||
giftAttachment.setUid(myUserInfo.getUid() + "");
|
||||
GiftReceiveInfo giftReceiveInfo = new GiftReceiveInfo();
|
||||
giftReceiveInfo.setNick(myUserInfo.getNick());
|
||||
giftReceiveInfo.setTargetUid(targetUid);
|
||||
giftReceiveInfo.setTargetNick(targetNick);
|
||||
giftReceiveInfo.setAvatar(myUserInfo.getAvatar());
|
||||
giftReceiveInfo.setGiftId(giftId);
|
||||
giftReceiveInfo.setUid(myUserInfo.getUid());
|
||||
giftReceiveInfo.setGiftNum(multiGiftReceiveInfo.getGiftNum());
|
||||
giftReceiveInfo.setGift(multiGiftReceiveInfo.getGift());
|
||||
giftAttachment.setGiftReceiveInfo(giftReceiveInfo);
|
||||
GiftInfo giftInfo1 = GiftModel.get().findGiftInfoById(giftReceiveInfo.getGiftId());
|
||||
if (giftInfo1 == null || TextUtils.isEmpty(giftInfo1.getGiftUrl())) {
|
||||
giftInfo1 = giftReceiveInfo.getGift();
|
||||
}
|
||||
giftReceiveInfo.setGift(giftInfo1);
|
||||
giftAttachment.setGiftReceiveInfo(giftReceiveInfo);
|
||||
CustomMessageConfig customMessageConfig = new CustomMessageConfig();
|
||||
customMessageConfig.enablePush = false;
|
||||
IMMessage imMessage = MessageBuilder.createCustomMessage(sessionId,
|
||||
SessionTypeEnum.Team, "", giftAttachment, customMessageConfig);
|
||||
return IMNetEaseManager.get()
|
||||
.sendMessageSingle(imMessage);
|
||||
}
|
||||
}
|
||||
|
@@ -1,286 +0,0 @@
|
||||
package com.chwl.core.public_chat_hall.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@Data
|
||||
public class PublicChatHallMessage {
|
||||
|
||||
public static final String TYPE_MSG_TEXT = "TEXT";
|
||||
public static final String TYPE_MSG_CUSTOM = "CUSTOM";
|
||||
|
||||
/**
|
||||
* eventType : 4
|
||||
* attach : {"first":28,"data":{"first":0,"atUids":["900114"],"atNames":[ResUtil.getString(R.string.public_chat_hall_bean_publicchathallmessage_01)],"second":0,"content":ResUtil.getString(R.string.public_chat_hall_bean_publicchathallmessage_02)},"second":282}
|
||||
* ext : {"900111":{"charmLevelSeq":16,"experUrl":"https:\/\/img.erbanyy.com\/new_ul_14.png","erbanNo":"3237053","charmUrl":"https:\/\/img.erbanyy.com\/new_ml_16.png","hasPrettyErbanNo":false,"experLevelSeq":14,"defUser":1}}
|
||||
* fromAccount : 900111
|
||||
* fromAvator : https://image.zhongjialx.com/Fms5Po_CANCiQowH9yu6D7WPDeC1?imageslim
|
||||
* fromClientType : IOS
|
||||
* fromExt : {"900111":{"charmLevelSeq":16,"experUrl":"https:\/\/img.erbanyy.com\/new_ul_14.png","erbanNo":"3237053","charmUrl":"https:\/\/img.erbanyy.com\/new_ml_16.png","hasPrettyErbanNo":false,"experLevelSeq":14,"defUser":1}}
|
||||
* fromNick : smile
|
||||
* msgTimestamp : 1542941627270
|
||||
* msgType : CUSTOM
|
||||
* msgidClient : 31f329c4-9521-4407-af5f-ae35901ec5d8
|
||||
* resendFlag : 0
|
||||
* roleInfoTimetag : 1542941426110
|
||||
* roomId : 57147316
|
||||
* customMsgType : 4
|
||||
* toAccounts : [{"uid":900114}]
|
||||
*/
|
||||
|
||||
/**
|
||||
* 值为4,表示是聊天室消息
|
||||
*/
|
||||
private String eventType;
|
||||
|
||||
/**
|
||||
* 消息内容,若msgType为CUSTOM自定义消息,该字段为JSON格式;否则该字段为普通字符串类型
|
||||
*/
|
||||
private String attach;
|
||||
|
||||
/**
|
||||
* 第三方扩展字段, 格式不限,长度限制4096,字符串类型
|
||||
*/
|
||||
private String ext;
|
||||
|
||||
/**
|
||||
* 消息发送者的账号,字符串类型
|
||||
*/
|
||||
private long fromAccount;
|
||||
|
||||
/**
|
||||
* 发送者的头像,字符串类型
|
||||
*/
|
||||
private String fromAvator;
|
||||
|
||||
/**
|
||||
* 客户端类型: AOS、IOS、PC、WINPHONE、WEB、REST,字符串类型
|
||||
*/
|
||||
private String fromClientType;
|
||||
|
||||
/**
|
||||
* 发送者身份的扩展字段,开发者可以自定义,字符串类型
|
||||
*/
|
||||
private String fromExt;
|
||||
|
||||
/**
|
||||
* 发送方昵称,字符串类型
|
||||
*/
|
||||
private String fromNick;
|
||||
|
||||
/**
|
||||
* 消息发送的时间戳
|
||||
*/
|
||||
private long msgTimestamp;
|
||||
|
||||
/**
|
||||
* 消息类型:
|
||||
* TEXT、
|
||||
* PICTURE、
|
||||
* AUDIO、
|
||||
* VIDEO、
|
||||
* LOCATION 、
|
||||
* NOTIFICATION、
|
||||
* FILE、 //文件消息
|
||||
* NETCALL_AUDIO、 //网络电话音频聊天
|
||||
* NETCALL_VEDIO、 //网络电话视频聊天
|
||||
* DATATUNNEL_NEW、 //新的数据通道请求通知
|
||||
* TIPS、 //提示类型消息
|
||||
* CUSTOM //自定义消息
|
||||
*/
|
||||
private String msgType;
|
||||
|
||||
/**
|
||||
* 客户端生成的消息id
|
||||
*/
|
||||
private String msgidClient;
|
||||
|
||||
/**
|
||||
* 重发标记:0不是重发, 1是重发
|
||||
*/
|
||||
private int resendFlag;
|
||||
|
||||
/**
|
||||
* 消息发送者用户名片的最后更新时间,可转为Long型数据
|
||||
*/
|
||||
private long roleInfoTimetag;
|
||||
|
||||
/**
|
||||
* 消息所属的聊天室id,可转为Long型数据
|
||||
*/
|
||||
private int roomId;
|
||||
private int customMsgType;
|
||||
private List<ToAccountsBean> toAccounts;
|
||||
|
||||
public String getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public void setEventType(String eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public String getAttach() {
|
||||
return attach;
|
||||
}
|
||||
|
||||
public void setAttach(String attach) {
|
||||
this.attach = attach;
|
||||
}
|
||||
|
||||
public String getExt() {
|
||||
return ext;
|
||||
}
|
||||
|
||||
public void setExt(String ext) {
|
||||
this.ext = ext;
|
||||
}
|
||||
|
||||
public long getFromAccount() {
|
||||
return fromAccount;
|
||||
}
|
||||
|
||||
public void setFromAccount(long fromAccount) {
|
||||
this.fromAccount = fromAccount;
|
||||
}
|
||||
|
||||
public String getFromAvator() {
|
||||
return fromAvator;
|
||||
}
|
||||
|
||||
public void setFromAvator(String fromAvator) {
|
||||
this.fromAvator = fromAvator;
|
||||
}
|
||||
|
||||
public String getFromClientType() {
|
||||
return fromClientType;
|
||||
}
|
||||
|
||||
public void setFromClientType(String fromClientType) {
|
||||
this.fromClientType = fromClientType;
|
||||
}
|
||||
|
||||
public String getFromExt() {
|
||||
return fromExt;
|
||||
}
|
||||
|
||||
public void setFromExt(String fromExt) {
|
||||
this.fromExt = fromExt;
|
||||
}
|
||||
|
||||
public String getFromNick() {
|
||||
return fromNick;
|
||||
}
|
||||
|
||||
public void setFromNick(String fromNick) {
|
||||
this.fromNick = fromNick;
|
||||
}
|
||||
|
||||
public long getMsgTimestamp() {
|
||||
return msgTimestamp;
|
||||
}
|
||||
|
||||
public void setMsgTimestamp(long msgTimestamp) {
|
||||
this.msgTimestamp = msgTimestamp;
|
||||
}
|
||||
|
||||
public String getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public String getMsgidClient() {
|
||||
return msgidClient;
|
||||
}
|
||||
|
||||
public void setMsgidClient(String msgidClient) {
|
||||
this.msgidClient = msgidClient;
|
||||
}
|
||||
|
||||
public int getResendFlag() {
|
||||
return resendFlag;
|
||||
}
|
||||
|
||||
public void setResendFlag(int resendFlag) {
|
||||
this.resendFlag = resendFlag;
|
||||
}
|
||||
|
||||
public long getRoleInfoTimetag() {
|
||||
return roleInfoTimetag;
|
||||
}
|
||||
|
||||
public void setRoleInfoTimetag(long roleInfoTimetag) {
|
||||
this.roleInfoTimetag = roleInfoTimetag;
|
||||
}
|
||||
|
||||
public int getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
public void setRoomId(int roomId) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
|
||||
public int getCustomMsgType() {
|
||||
return customMsgType;
|
||||
}
|
||||
|
||||
public void setCustomMsgType(int customMsgType) {
|
||||
this.customMsgType = customMsgType;
|
||||
}
|
||||
|
||||
public List<ToAccountsBean> getToAccounts() {
|
||||
return toAccounts;
|
||||
}
|
||||
|
||||
public void setToAccounts(List<ToAccountsBean> toAccounts) {
|
||||
this.toAccounts = toAccounts;
|
||||
}
|
||||
|
||||
public static class ToAccountsBean {
|
||||
/**
|
||||
* uid : 900114
|
||||
*/
|
||||
|
||||
private int uid;
|
||||
|
||||
public int getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(int uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ToAccountsBean{" +
|
||||
"uid=" + uid +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PublicChatHallMessage{" +
|
||||
"eventType='" + eventType + '\'' +
|
||||
", attach=" + attach +
|
||||
", ext='" + ext + '\'' +
|
||||
", fromAccount=" + fromAccount +
|
||||
", fromAvator='" + fromAvator + '\'' +
|
||||
", fromClientType='" + fromClientType + '\'' +
|
||||
", fromExt='" + fromExt + '\'' +
|
||||
", fromNick='" + fromNick + '\'' +
|
||||
", msgTimestamp=" + msgTimestamp +
|
||||
", msgType='" + msgType + '\'' +
|
||||
", msgidClient='" + msgidClient + '\'' +
|
||||
", resendFlag=" + resendFlag +
|
||||
", roleInfoTimetag=" + roleInfoTimetag +
|
||||
", roomId=" + roomId +
|
||||
", customMsgType=" + customMsgType +
|
||||
", toAccounts=" + toAccounts +
|
||||
'}';
|
||||
}
|
||||
}
|
@@ -38,7 +38,6 @@ 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.core.public_chat_hall.model.PublicChatHallModel;
|
||||
import com.chwl.library.utils.ListUtils;
|
||||
import com.chwl.library.utils.ResUtil;
|
||||
|
||||
@@ -133,9 +132,6 @@ public class PublicChatHallDataManager {
|
||||
if (attachment == null) continue;
|
||||
if (attachment.getType() == ChatRoomMemberTempMuteAdd) {
|
||||
List<String> targets = ((ChatRoomNotificationAttachment) attachment).getTargets();
|
||||
if (targets.contains(AuthModel.get().getCurrentUid() + "")) {
|
||||
PublicChatHallModel.get().getOwnerInfo().subscribe();
|
||||
}
|
||||
}
|
||||
} else if (msg.getMsgType() == MsgTypeEnum.custom) {
|
||||
MsgAttachment attachment = msg.getAttachment();
|
||||
|
@@ -1,42 +0,0 @@
|
||||
package com.chwl.core.public_chat_hall.model;
|
||||
|
||||
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomResultData;
|
||||
import com.chwl.core.base.IModel;
|
||||
import com.chwl.core.bean.response.ServiceResult;
|
||||
import com.chwl.core.public_chat_hall.bean.PublicChatHallMessage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
|
||||
public interface IPublicChatHallModel extends IModel {
|
||||
|
||||
/**
|
||||
* 进入云信聊天室(公聊大厅版本)
|
||||
* @param roomId
|
||||
* @param retryCount
|
||||
* @return
|
||||
*/
|
||||
Observable<EnterChatRoomResultData> enterRoom(final long roomId, final int retryCount);
|
||||
|
||||
/**
|
||||
* 获取艾特我的历史消息
|
||||
* @param page 页码
|
||||
*/
|
||||
Single<ServiceResult<List<PublicChatHallMessage>>> getAitMeHistoryMessage(int page);
|
||||
|
||||
/**
|
||||
* 获取我发出的历史消息
|
||||
* @param page 页码
|
||||
*/
|
||||
Single<ServiceResult<List<PublicChatHallMessage>>> getSentHistoryMessage(int page);
|
||||
|
||||
/**
|
||||
* 禁言
|
||||
*/
|
||||
Single<String> userMute(long roomId,
|
||||
long targetUid,
|
||||
long muteTime,
|
||||
String reason);
|
||||
}
|
@@ -1,309 +0,0 @@
|
||||
package com.chwl.core.public_chat_hall.model;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.netease.nimlib.sdk.AbortableFuture;
|
||||
import com.netease.nimlib.sdk.NIMChatRoomSDK;
|
||||
import com.netease.nimlib.sdk.RequestCallback;
|
||||
import com.netease.nimlib.sdk.ResponseCode;
|
||||
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.chwl.core.R;
|
||||
import com.chwl.core.Constants;
|
||||
import com.chwl.core.auth.AuthModel;
|
||||
import com.chwl.core.base.BaseModel;
|
||||
import com.chwl.core.bean.response.ServiceResult;
|
||||
import com.chwl.core.decoration.car.bean.CarInfo;
|
||||
import com.chwl.core.decoration.headwear.bean.HeadWearInfo;
|
||||
import com.chwl.core.initial.InitialModel;
|
||||
import com.chwl.core.level.UserLevelVo;
|
||||
import com.chwl.core.noble.bean.NobleInfo;
|
||||
import com.chwl.core.public_chat_hall.bean.PublicChatHallMessage;
|
||||
import com.chwl.core.public_chat_hall.manager.PublicChatHallDataManager;
|
||||
import com.chwl.core.user.UserModel;
|
||||
import com.chwl.core.user.bean.UserInfo;
|
||||
import com.chwl.core.user.event.LoadLoginUserInfoEvent;
|
||||
import com.chwl.core.utils.net.RxHelper;
|
||||
import com.chwl.library.net.rxnet.RxNet;
|
||||
import com.chwl.library.utils.ListUtils;
|
||||
import com.chwl.library.utils.ResUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleOnSubscribe;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public class PublicChatHallModel extends BaseModel implements IPublicChatHallModel {
|
||||
/**
|
||||
* 艾特我的消息查询类型
|
||||
*/
|
||||
private static final int QUERY_TYPE_AIT_ME = 1;
|
||||
|
||||
/**
|
||||
* 我发出的消息查询类型
|
||||
*/
|
||||
private static final int QUERY_TYPE_SENT_BY_ME = 2;
|
||||
|
||||
private Api api;
|
||||
|
||||
private PublicChatHallModel() {
|
||||
api = RxNet.create(Api.class);
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
public static PublicChatHallModel get() {
|
||||
return PublicChatHallModelHolder.instance;
|
||||
}
|
||||
|
||||
public static class PublicChatHallModelHolder {
|
||||
public static final PublicChatHallModel instance = new PublicChatHallModel();
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void loadLoginUserInfo(LoadLoginUserInfoEvent event) {
|
||||
// 登录成功后自动进入公聊大厅
|
||||
PublicChatHallModel.get()
|
||||
.enterRoom(PublicChatHallDataManager.get().getPublicChatHallId(), 3)
|
||||
.subscribe(enterChatRoomResultData -> {
|
||||
if (enterChatRoomResultData.getResCode() == ResponseCode.RES_SUCCESS) {
|
||||
PublicChatHallDataManager.get().loadHistory();
|
||||
}
|
||||
getOwnerInfo().subscribe();
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
|
||||
//获取自己信息
|
||||
public Single<String> getOwnerInfo() {
|
||||
return Single.create(e -> {
|
||||
ArrayList<String> objects = new ArrayList<>();
|
||||
objects.add(AuthModel.get().getCurrentUid() + "");
|
||||
NIMChatRoomSDK.getChatRoomService().fetchRoomMembersByIds(String.valueOf(PublicChatHallDataManager.get().getPublicChatHallId()),
|
||||
objects)
|
||||
.setCallback(new RequestCallback<List<ChatRoomMember>>() {
|
||||
@Override
|
||||
public void onSuccess(List<ChatRoomMember> param) {
|
||||
if (!ListUtils.isListEmpty(param)) {
|
||||
for (ChatRoomMember chatRoomMember : param) {
|
||||
if (Objects.equals(chatRoomMember.getAccount(), String.valueOf(AuthModel.get().getCurrentUid()))) {
|
||||
//自己
|
||||
PublicChatHallDataManager.get().mOwnerMember = chatRoomMember;
|
||||
}
|
||||
}
|
||||
}
|
||||
e.onSuccess(ResUtil.getString(R.string.public_chat_hall_model_publicchathallmodel_01));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(int code) {
|
||||
e.onError(new Throwable(ResUtil.getString(R.string.public_chat_hall_model_publicchathallmodel_02) + code));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable exception) {
|
||||
e.onError(new Throwable(ResUtil.getString(R.string.public_chat_hall_model_publicchathallmodel_03) + exception.toString()));
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入云信聊天室(公聊大厅)
|
||||
*
|
||||
* @param roomId
|
||||
* @param retryCount 重试次数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Observable<EnterChatRoomResultData> enterRoom(final long roomId, final int retryCount) {
|
||||
return Observable.create((ObservableOnSubscribe<EnterChatRoomResultData>) e -> {
|
||||
long tempRoomId = roomId;
|
||||
if (tempRoomId == 0) {
|
||||
tempRoomId = InitialModel.get().getCacheInitInfo().getPublicChatRoomId();
|
||||
}
|
||||
if (tempRoomId == 0) {
|
||||
e.onError(new Throwable("error:roomId == 0"));
|
||||
return;
|
||||
}
|
||||
EnterChatRoomData enterChatRoomData = new EnterChatRoomData(String.valueOf(tempRoomId));
|
||||
UserInfo userInfo = UserModel.get().getCurrentUserInfo().blockingGet();
|
||||
Map<String, Object> map = null;
|
||||
if (userInfo == null) {
|
||||
e.onError(new Throwable("userInfo is null"));
|
||||
} else {
|
||||
map = getUserExtension(userInfo);
|
||||
}
|
||||
if (map == null) return;
|
||||
if (map.size() > 0)
|
||||
enterChatRoomData.setExtension(map);
|
||||
|
||||
AbortableFuture<EnterChatRoomResultData> enterChatRoomEx =
|
||||
NIMChatRoomSDK.getChatRoomService().enterChatRoomEx(enterChatRoomData, retryCount);
|
||||
enterChatRoomEx.setCallback(new RequestCallback<EnterChatRoomResultData>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(EnterChatRoomResultData param) {
|
||||
e.onNext(param);
|
||||
e.onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(int code) {
|
||||
e.onError(new Throwable(String.valueOf(code)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable exception) {
|
||||
e.onError(exception);
|
||||
}
|
||||
});
|
||||
}).subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.unsubscribeOn(Schedulers.computation());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Map<String, Object> getUserExtension(UserInfo userInfo) {
|
||||
NobleInfo nobleInfo = userInfo.getNobleInfo();
|
||||
HeadWearInfo headWearInfo = userInfo.getUserHeadwear();
|
||||
UserLevelVo userLevelVo = userInfo.getUserLevelVo();
|
||||
CarInfo carInfo = userInfo.getCarInfo();
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
Map<String, Object> valueMap = null;
|
||||
valueMap = userInfo.toMap(valueMap, userInfo);
|
||||
if (userLevelVo != null) {
|
||||
valueMap = userLevelVo.toMapForPublicChatHall((nobleInfo != null && nobleInfo.getLevel() > 0) ? nobleInfo.toMap(valueMap) : valueMap);
|
||||
}
|
||||
if (carInfo != null) {
|
||||
valueMap = carInfo.toMap(valueMap, carInfo);
|
||||
}
|
||||
//多个判断,头饰不过期才传pic
|
||||
if (headWearInfo != null && headWearInfo.getStatus() == HeadWearInfo.STATUS_IN_USED) {
|
||||
valueMap = headWearInfo.toMap(valueMap);
|
||||
}
|
||||
if (valueMap != null && valueMap.size() > 0) {
|
||||
map.put(String.valueOf(AuthModel.get().getCurrentUid()), valueMap);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>发送 云信聊天室信息</p>
|
||||
* <p>返回的是一个观察者,需要subscribe才会开始发送信息</p>
|
||||
* <p>不关心信息发送是否成功的,可以直接调用无参subscribe()方法,
|
||||
* 相反关心的则需要在subscribe(new Consumer(..){...})方法中通过Consumer来消耗事件</p>
|
||||
* <p>ps: 无参subscribe()方法调用如果发生错误,会在rxjava的error handler中得到回调,默认的实现在application的onCreate中</p>
|
||||
*
|
||||
* @param chatRoomMessage 自定义的聊天室信息
|
||||
* @param resend 是否自动重发
|
||||
* @return 返回一个可被observer观察订阅的observable
|
||||
*/
|
||||
public Single<ChatRoomMessage> sendChatRoomMessage(final ChatRoomMessage chatRoomMessage, final boolean resend) {
|
||||
if (chatRoomMessage == null) {
|
||||
throw new IllegalArgumentException("ChatRoomMessage can't be null!");
|
||||
}
|
||||
return Single.create((SingleOnSubscribe<ChatRoomMessage>) e -> {
|
||||
long currentUid = AuthModel.get().getCurrentUid();
|
||||
UserInfo userInfo = UserModel.get().getUserInfo(currentUid).blockingGet();
|
||||
Map<String, Object> map = null;
|
||||
if (userInfo == null) {
|
||||
e.onError(new Throwable("userInfo is null"));
|
||||
} else {
|
||||
map = getUserExtension(userInfo);
|
||||
}
|
||||
chatRoomMessage.setLocalExtension(map);
|
||||
chatRoomMessage.setRemoteExtension(map);
|
||||
NIMChatRoomSDK.getChatRoomService().sendMessage(
|
||||
chatRoomMessage,
|
||||
resend
|
||||
)
|
||||
.setCallback(new RequestCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void param) {
|
||||
e.onSuccess(chatRoomMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(int code) {
|
||||
e.onError(new Exception(String.valueOf(code)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable exception) {
|
||||
e.onError(exception);
|
||||
}
|
||||
});
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<ServiceResult<List<PublicChatHallMessage>>> getAitMeHistoryMessage(int page) {
|
||||
return api.getMyHistoryMessage(String.valueOf(AuthModel.get().getCurrentUid()),
|
||||
QUERY_TYPE_AIT_ME, page, Constants.PAGE_SIZE)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<ServiceResult<List<PublicChatHallMessage>>> getSentHistoryMessage(int page) {
|
||||
return api.getMyHistoryMessage(String.valueOf(AuthModel.get().getCurrentUid()),
|
||||
QUERY_TYPE_SENT_BY_ME, page, Constants.PAGE_SIZE)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<String> userMute(long roomId, long targetUid, long muteTime, String reason) {
|
||||
return api.userMute(roomId, targetUid, muteTime, reason)
|
||||
.compose(RxHelper.singleMainResult(true));
|
||||
}
|
||||
|
||||
interface Api {
|
||||
|
||||
/**
|
||||
* 获取用户在公聊大厅里的消息
|
||||
*
|
||||
* @param uid 用户 ID
|
||||
* @param type 查询类型(1:@我的,2:我发出的)
|
||||
* @param page 页码
|
||||
* @param pageSize 分页大小
|
||||
* @return
|
||||
*/
|
||||
@GET("/public/chatroom/getMsg")
|
||||
Single<ServiceResult<List<PublicChatHallMessage>>> getMyHistoryMessage(@Query("uid") String uid,
|
||||
@Query("type") int type,
|
||||
@Query("page") int page,
|
||||
@Query("pageSize") int pageSize);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("/userMute/record/add")
|
||||
Single<ServiceResult<String>> userMute(@Field("roomId") long roomId,
|
||||
@Field("targetUid") long targetUid,
|
||||
@Field("muteTime") long muteTime,
|
||||
@Field("reason") String reason);
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
package com.chwl.core.public_chat_hall.util;
|
||||
|
||||
public class PublicChatHallMessageConvertor {
|
||||
|
||||
// public static ChatRoomMessage getChatRoomMessage(PublicChatHallMessage message) {
|
||||
// switch (message.getMsgType()) {
|
||||
// ChatRoomMessageBuilder.
|
||||
// }
|
||||
// }
|
||||
}
|
Reference in New Issue
Block a user