feat:完成私聊限制需求(每发消息都请求接口)
This commit is contained in:
@@ -53,6 +53,7 @@ import com.netease.nimlib.sdk.robot.model.RobotMsgType;
|
||||
import com.tbruyelle.rxpermissions2.RxPermissions;
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.common.widget.OriginalDrawStatusClickSpan;
|
||||
import com.yizhuan.erban.common.widget.dialog.DialogManager;
|
||||
import com.yizhuan.erban.ui.im.GreetPresenter;
|
||||
import com.yizhuan.erban.ui.im.MessageListPanelEx;
|
||||
import com.yizhuan.erban.ui.im.chat.MVHChatterBoxStart;
|
||||
@@ -104,6 +105,8 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
protected AitManager aitManager;
|
||||
protected String recordId = "";
|
||||
|
||||
private DialogManager dialogManager;
|
||||
|
||||
/**
|
||||
* 消息接收观察者
|
||||
*/
|
||||
@@ -189,6 +192,10 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
if (aitManager != null) {
|
||||
aitManager.reset();
|
||||
}
|
||||
if (dialogManager != null) {
|
||||
dialogManager.dismissDialog();
|
||||
}
|
||||
dialogManager = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,7 +340,37 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
if (!isAllowSendMessage(message)) {
|
||||
return false;
|
||||
}
|
||||
MsgTypeEnum msgTypeEnum = message.getMsgType();
|
||||
String content = null;
|
||||
if (msgTypeEnum == MsgTypeEnum.text) {
|
||||
content = message.getContent();
|
||||
} else if (msgTypeEnum == MsgTypeEnum.audio) {
|
||||
content = "";
|
||||
} else if (msgTypeEnum == MsgTypeEnum.image) {
|
||||
content = "";
|
||||
}
|
||||
if (content != null) {
|
||||
showLoading();
|
||||
Disposable disposable = IMCustomModel.get().privateChatCheck(message.getContent(), sessionId).subscribe(((privateChatLimitInfo, throwable) -> {
|
||||
if (isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
dismissLoading();
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
SingleToastUtil.showToast(throwable.getMessage());
|
||||
} else {
|
||||
sendMessageImpl(message);
|
||||
}
|
||||
}));
|
||||
compositeDisposable.add(disposable);
|
||||
} else {
|
||||
sendMessageImpl(message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendMessageImpl(IMMessage message) {
|
||||
appendTeamMemberPush(message);
|
||||
message = changeToRobotMsg(message);
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
@@ -357,7 +394,6 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
NIMClient.getService(MsgService.class).sendMessage(message, false).setCallback(new RequestCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void param) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -376,7 +412,6 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
if (aitManager != null) {
|
||||
aitManager.reset();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,7 +634,10 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
tvChatLimit.setVisibility(View.GONE);
|
||||
inputPanel.setLimitLevel(true, "");
|
||||
} else {
|
||||
IMCustomModel.get().getPrivateChatLimit(sessionId).subscribe(((privateChatLimitInfo, throwable) -> {
|
||||
Disposable disposable = IMCustomModel.get().getPrivateChatLimit(sessionId).subscribe(((privateChatLimitInfo, throwable) -> {
|
||||
if (isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
} else {
|
||||
@@ -642,6 +680,7 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
tvChatLimit.setVisibility(isChat ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}));
|
||||
compositeDisposable.add(disposable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -685,4 +724,19 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
public void setCurrentLevel(int currentLevel) {
|
||||
}
|
||||
|
||||
private void showLoading(){
|
||||
if (isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
if (dialogManager == null) {
|
||||
dialogManager = new DialogManager(getContext());
|
||||
}
|
||||
dialogManager.showProgressDialog(getContext());
|
||||
}
|
||||
|
||||
private void dismissLoading(){
|
||||
if (dialogManager != null) {
|
||||
dialogManager.dismissDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.yizhuan.erban.ui.im.model;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.yizhuan.xchat_android_core.bean.PrivateChatLimitInfo;
|
||||
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
|
||||
import com.yizhuan.xchat_android_core.manager.BaseMvpModel;
|
||||
@@ -31,6 +32,12 @@ public class IMCustomModel extends BaseMvpModel {
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
public Single<String> privateChatCheck(String content, String receiverUid) {
|
||||
return api.privateChatCheck(content, receiverUid)
|
||||
.compose(RxHelper.handleIgnoreData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
private interface Api {
|
||||
/**
|
||||
* 获取是否可以发送私聊
|
||||
@@ -38,5 +45,11 @@ public class IMCustomModel extends BaseMvpModel {
|
||||
*/
|
||||
@GET("/privateChat/limit")
|
||||
Single<ServiceResult<PrivateChatLimitInfo>> getPrivateChatLimit(@Query("receiverUid") String receiverUid);
|
||||
|
||||
/**
|
||||
* 私聊发送消息时检测
|
||||
*/
|
||||
@GET("/privateChat/check")
|
||||
Single<ServiceResult<JsonElement>> privateChatCheck(@Query("content") String content, @Query("toUid") String toUid);
|
||||
}
|
||||
}
|
||||
|
@@ -31,8 +31,8 @@ COMPILE_SDK_VERSION=33
|
||||
MIN_SDK_VERSION=21
|
||||
TARGET_SDK_VERSION=33
|
||||
|
||||
version_name=2.2.0
|
||||
version_code=2200
|
||||
version_name=2.5.0
|
||||
version_code=2500
|
||||
|
||||
#systemProp.https.proxyHost=127.0.0.1
|
||||
#systemProp.https.proxyPort=7890
|
@@ -12,6 +12,8 @@ import androidx.fragment.app.Fragment;
|
||||
import com.netease.nim.uikit.common.activity.UI;
|
||||
import com.netease.nim.uikit.common.util.log.LogUtil;
|
||||
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public abstract class TFragment extends Fragment {
|
||||
private static final Handler handler = new Handler();
|
||||
|
||||
@@ -31,6 +33,8 @@ public abstract class TFragment extends Fragment {
|
||||
this.containerId = containerId;
|
||||
}
|
||||
|
||||
protected CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
@@ -39,9 +43,20 @@ public abstract class TFragment extends Fragment {
|
||||
destroyed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (compositeDisposable != null) {
|
||||
compositeDisposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (compositeDisposable != null) {
|
||||
compositeDisposable.dispose();
|
||||
}
|
||||
compositeDisposable = null;
|
||||
LogUtil.ui("fragment: " + getClass().getSimpleName() + " onDestroy()");
|
||||
|
||||
destroyed = true;
|
||||
|
Reference in New Issue
Block a user