|
@@ -1,21 +1,43 @@
|
|
|
package com.cooleshow.chatmodule.ui;
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
+import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
|
import com.cooleshow.base.common.BaseConstant;
|
|
|
import com.cooleshow.base.data.net.BaseResponse;
|
|
|
import com.cooleshow.base.data.net.RetrofitFactory;
|
|
|
import com.cooleshow.base.utils.ErrorParse;
|
|
|
+import com.cooleshow.base.utils.LOG;
|
|
|
import com.cooleshow.base.widgets.dialog.CommonDialog;
|
|
|
+import com.cooleshow.chatmodule.R;
|
|
|
import com.cooleshow.chatmodule.api.IMApi;
|
|
|
import com.cooleshow.chatmodule.bean.IMGroupInfo;
|
|
|
import com.cooleshow.chatmodule.manager.IMCenter;
|
|
|
+import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
+import com.tencent.imsdk.v2.V2TIMGroupChangeInfo;
|
|
|
+import com.tencent.imsdk.v2.V2TIMGroupMemberChangeInfo;
|
|
|
+import com.tencent.imsdk.v2.V2TIMGroupMemberFullInfo;
|
|
|
+import com.tencent.imsdk.v2.V2TIMGroupMemberInfo;
|
|
|
+import com.tencent.imsdk.v2.V2TIMGroupTipsElem;
|
|
|
+import com.tencent.imsdk.v2.V2TIMManager;
|
|
|
+import com.tencent.imsdk.v2.V2TIMMessage;
|
|
|
+import com.tencent.imsdk.v2.V2TIMValueCallback;
|
|
|
import com.tencent.qcloud.tuicore.TUIConstants;
|
|
|
+import com.tencent.qcloud.tuikit.timcommon.bean.MessageReceiptInfo;
|
|
|
+import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
|
|
|
import com.tencent.qcloud.tuikit.timcommon.component.interfaces.IUIKitCallback;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.bean.GroupInfo;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIGroupChatActivity;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.classicui.widget.input.InputView;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.interfaces.GroupChatEventListener;
|
|
|
+import com.tencent.qcloud.tuikit.tuigroup.model.GroupInfoProvider;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
|
import io.reactivex.rxjava3.annotations.NonNull;
|
|
@@ -24,15 +46,24 @@ import io.reactivex.rxjava3.core.Observer;
|
|
|
import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
|
|
|
|
|
+import static com.tencent.imsdk.v2.V2TIMGroupMemberFullInfo.V2TIM_GROUP_MEMBER_ROLE_ADMIN;
|
|
|
+import static com.tencent.imsdk.v2.V2TIMGroupMemberFullInfo.V2TIM_GROUP_MEMBER_ROLE_MEMBER;
|
|
|
+import static com.tencent.imsdk.v2.V2TIMGroupMemberFullInfo.V2TIM_GROUP_MEMBER_ROLE_OWNER;
|
|
|
+
|
|
|
/**
|
|
|
* Author by pq, Date on 2023/8/8.
|
|
|
* 为了实现checkInGroup这个逻辑,所以继承TUIGroupChatActivity
|
|
|
*/
|
|
|
public class TUIChatGroupActivityV2 extends TUIGroupChatActivity {
|
|
|
+ public static final String TAG = "TUIChatGroupActivityV2";
|
|
|
public static int GROUP_INFO_ERROR = 204;//群组相关信息异常
|
|
|
private String groupId;
|
|
|
private CommonDialog mTipdialog;
|
|
|
private String conversationId;
|
|
|
+ private GroupInfoProvider mGroupInfoProvider;
|
|
|
+ private String currentImUserId;
|
|
|
+ private GroupChatEventListener mGroupChatEventListener;
|
|
|
+ private View muteInputView;
|
|
|
|
|
|
@Override
|
|
|
public void initChat(ChatInfo chatInfo) {
|
|
@@ -40,11 +71,271 @@ public class TUIChatGroupActivityV2 extends TUIGroupChatActivity {
|
|
|
conversationId = getIntent().getStringExtra(TUIConstants.TUIChat.CONVERSATION_ID);
|
|
|
GroupInfo groupInfo = (GroupInfo) chatInfo;
|
|
|
groupId = groupInfo.getId();
|
|
|
+ currentImUserId = UserHelper.getImUserId();
|
|
|
if (groupInfo != null) {
|
|
|
checkInGroup(groupInfo.getId());
|
|
|
+ loadGroupInfo();
|
|
|
+ addListener();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addListener() {
|
|
|
+ if (mGroupChatEventListener == null) {
|
|
|
+ mGroupChatEventListener = new GroupChatEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onGroupForceExit(String groupId) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exitGroupChat(String chatId) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void clearGroupMessage(String chatId) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onApplied() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handleRevoke(String msgId) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRecvNewMessage(TUIMessageBean message) {
|
|
|
+ LOG.i(TAG, "onRecvNewMessage");
|
|
|
+ if (!TextUtils.equals(message.getGroupId(), groupId)) {
|
|
|
+ LOG.i(TAG, "receive a new message , not belong to current chat.");
|
|
|
+ } else {
|
|
|
+ handleRecvNewMessage(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReadReport(List<MessageReceiptInfo> receiptInfoList) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGroupNameChanged(String groupId, String newName) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGroupFaceUrlChanged(String groupId, String faceUrl) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRecvMessageModified(TUIMessageBean messageBean) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addMessage(TUIMessageBean messageBean, String chatId) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onMessageChanged(TUIMessageBean messageBean, int dataChangeType) {
|
|
|
+ }
|
|
|
+ };
|
|
|
+ TUIChatService.getInstance().addGroupChatEventListener(mGroupChatEventListener);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void handleRecvNewMessage(TUIMessageBean message) {
|
|
|
+ V2TIMMessage v2TIMMessage = message.getV2TIMMessage();
|
|
|
+ V2TIMGroupTipsElem groupTipElem = v2TIMMessage.getGroupTipsElem();
|
|
|
+ if (groupTipElem == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int tipsType = groupTipElem.getType();
|
|
|
+ if (tipsType == V2TIMGroupTipsElem.V2TIM_GROUP_TIPS_TYPE_GROUP_INFO_CHANGE) {
|
|
|
+ List<V2TIMGroupChangeInfo> modifyList = groupTipElem.getGroupChangeInfoList();
|
|
|
+ for (int i = 0; i < modifyList.size(); i++) {
|
|
|
+ V2TIMGroupChangeInfo modifyInfo = modifyList.get(i);
|
|
|
+ int modifyType = modifyInfo.getType();
|
|
|
+ if (modifyType == V2TIMGroupChangeInfo.V2TIM_GROUP_INFO_CHANGE_TYPE_SHUT_UP_ALL) {
|
|
|
+ boolean isShutUpAll = modifyInfo.getBoolValue();
|
|
|
+ if (isShutUpAll) {
|
|
|
+ //禁言全员
|
|
|
+ LOG.i(TAG, "禁言全员");
|
|
|
+ TUIChatGroupActivityV2.this.isMuteAll = true;
|
|
|
+ } else {
|
|
|
+ //取消禁言全员
|
|
|
+ LOG.i(TAG, "取消禁言全员");
|
|
|
+ TUIChatGroupActivityV2.this.isMuteAll = false;
|
|
|
+ }
|
|
|
+ handleMuteLayout();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (modifyType == V2TIMGroupChangeInfo.V2TIM_GROUP_INFO_CHANGE_TYPE_OWNER) {
|
|
|
+ //群主变化
|
|
|
+ handleOwnerChange(groupTipElem);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tipsType == V2TIMGroupTipsElem.V2TIM_GROUP_TIPS_TYPE_SET_ADMIN) {
|
|
|
+ //管理员变化
|
|
|
+ handleAdminChange(groupTipElem, true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tipsType == V2TIMGroupTipsElem.V2TIM_GROUP_TIPS_TYPE_CANCEL_ADMIN) {
|
|
|
+ //取消管理员
|
|
|
+ handleAdminChange(groupTipElem, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tipsType == V2TIMGroupTipsElem.V2TIM_GROUP_TIPS_TYPE_MEMBER_INFO_CHANGE) {
|
|
|
+ List<V2TIMGroupMemberChangeInfo> modifyList = groupTipElem.getMemberChangeInfoList();
|
|
|
+ if (modifyList.size() > 0) {
|
|
|
+ V2TIMGroupMemberChangeInfo v2TIMGroupMemberChangeInfo = modifyList.get(0);
|
|
|
+ String userID = v2TIMGroupMemberChangeInfo.getUserID();
|
|
|
+ if (TextUtils.equals(userID, currentImUserId)) {
|
|
|
+ long shutupTime = v2TIMGroupMemberChangeInfo.getMuteTime();
|
|
|
+ if (shutupTime > 0) {
|
|
|
+ //禁言个人
|
|
|
+ LOG.i(TAG, "禁言个人:" + userID);
|
|
|
+ TUIChatGroupActivityV2.this.isMuteUser = true;
|
|
|
+ } else {
|
|
|
+ //取消禁言个人
|
|
|
+ LOG.i(TAG, "取消禁言个人:" + userID);
|
|
|
+ TUIChatGroupActivityV2.this.isMuteUser = false;
|
|
|
+ }
|
|
|
+ handleMuteLayout();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTargetId(V2TIMGroupTipsElem groupTipElem) {
|
|
|
+ if (groupTipElem == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<V2TIMGroupMemberInfo> v2TIMGroupMemberInfoList = groupTipElem.getMemberList();
|
|
|
+ if (v2TIMGroupMemberInfoList != null && v2TIMGroupMemberInfoList.size() > 0) {
|
|
|
+ V2TIMGroupMemberInfo v2TIMGroupMemberInfo = v2TIMGroupMemberInfoList.get(0);
|
|
|
+ LOG.i(TAG, "变化:" + v2TIMGroupMemberInfo.getUserID());
|
|
|
+ LOG.i(TAG, "变化:" + v2TIMGroupMemberInfo.getNickName());
|
|
|
+ return v2TIMGroupMemberInfo.getUserID();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleOwnerChange(V2TIMGroupTipsElem groupTipElem) {
|
|
|
+ String targetId = getTargetId(groupTipElem);
|
|
|
+ if (TextUtils.isEmpty(targetId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LOG.i(TAG, "群主变化:" + targetId);
|
|
|
+ boolean equals = TextUtils.equals(targetId, currentImUserId);
|
|
|
+ role = equals ? V2TIM_GROUP_MEMBER_ROLE_OWNER : V2TIM_GROUP_MEMBER_ROLE_MEMBER;
|
|
|
+ handleMuteLayout();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleAdminChange(V2TIMGroupTipsElem groupTipElem, boolean isAdd) {
|
|
|
+ String targetId = getTargetId(groupTipElem);
|
|
|
+ if (TextUtils.isEmpty(targetId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LOG.i(TAG, "管理员变化:" + targetId + "--isAdd:" + isAdd);
|
|
|
+ if (TextUtils.equals(targetId, currentImUserId)) {
|
|
|
+ role = isAdd ? V2TIM_GROUP_MEMBER_ROLE_ADMIN : V2TIM_GROUP_MEMBER_ROLE_MEMBER;
|
|
|
+ handleMuteLayout();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean getMuteResult() {
|
|
|
+ LOG.i(TAG, "isMuteUser:" + isMuteUser);
|
|
|
+ if (isMuteUser) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ boolean adminOrOWNER = isAdminOrOWNER();
|
|
|
+ LOG.i(TAG, "isAdminOrOWNER:" + adminOrOWNER);
|
|
|
+ if (adminOrOWNER) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ LOG.i(TAG, "isMuteAll:" + isMuteAll);
|
|
|
+ if (isMuteAll) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isAdminOrOWNER() {
|
|
|
+ return role == V2TIM_GROUP_MEMBER_ROLE_ADMIN || role == V2TIM_GROUP_MEMBER_ROLE_OWNER;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isMuteAll = false;
|
|
|
+ private boolean isMuteUser = false;
|
|
|
+ private int role = V2TIM_GROUP_MEMBER_ROLE_MEMBER;
|
|
|
+
|
|
|
+ private void loadGroupInfo() {
|
|
|
+ if (mGroupInfoProvider == null) {
|
|
|
+ mGroupInfoProvider = new GroupInfoProvider();
|
|
|
+ }
|
|
|
+ mGroupInfoProvider.loadGroupInfo(groupId, new IUIKitCallback<com.tencent.qcloud.tuikit.tuigroup.bean.GroupInfo>() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(com.tencent.qcloud.tuikit.tuigroup.bean.GroupInfo data) {
|
|
|
+ TUIChatGroupActivityV2.this.isMuteAll = data.isAllMuted();
|
|
|
+ LOG.i(TAG, "Thread:" + Thread.currentThread().getName());
|
|
|
+ getGroupMemberInfo();
|
|
|
+ LOG.i(TAG, "allMuted:" + isMuteAll);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(String module, int errCode, String errMsg) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getGroupMemberInfo() {
|
|
|
+ ArrayList<String> strings = new ArrayList<>();
|
|
|
+ strings.add(currentImUserId);
|
|
|
+ V2TIMManager.getGroupManager().getGroupMembersInfo(groupId, strings, new V2TIMValueCallback<List<V2TIMGroupMemberFullInfo>>() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(List<V2TIMGroupMemberFullInfo> v2TIMGroupMemberFullInfos) {
|
|
|
+ if (v2TIMGroupMemberFullInfos != null && v2TIMGroupMemberFullInfos.size() > 0) {
|
|
|
+ V2TIMGroupMemberFullInfo v2TIMGroupMemberFullInfo = v2TIMGroupMemberFullInfos.get(0);
|
|
|
+ TUIChatGroupActivityV2.this.role = v2TIMGroupMemberFullInfo.getRole();
|
|
|
+ LOG.i(TAG, "查询role:" + role);
|
|
|
+ long l = IMCenter.getInstance().getServerTime();
|
|
|
+ TUIChatGroupActivityV2.this.isMuteUser = v2TIMGroupMemberFullInfo.getMuteUntil() > l;
|
|
|
+ handleMuteLayout();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(int i, String s) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleMuteLayout() {
|
|
|
+ boolean muteResult = getMuteResult();
|
|
|
+ changeMuteLayoutVisibility(muteResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeMuteLayoutVisibility(Boolean flag) {
|
|
|
+ if (flag != null && chatFragment!=null) {
|
|
|
+ InputView inputLayout = chatFragment.getChatView().getInputLayout();
|
|
|
+ ViewGroup inputMuteContainer = inputLayout.getInputMuteContainer();
|
|
|
+ if (inputMuteContainer.getChildCount() == 0) {
|
|
|
+ View muteView = getMuteView(inputMuteContainer);
|
|
|
+ inputMuteContainer.addView(muteView);
|
|
|
+ }
|
|
|
+ inputLayout.controlMuteViewVisibility(flag ? View.VISIBLE : View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private View getMuteView(ViewGroup inputMuteContainer) {
|
|
|
+ if (muteInputView == null) {
|
|
|
+ muteInputView = LayoutInflater.from(this).inflate(R.layout.view_mute_input_layout, inputMuteContainer, false);
|
|
|
+ }
|
|
|
+ return muteInputView;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void checkInGroup(String groupId) {
|
|
|
//根据用户编号获取用户基本信息
|
|
@@ -114,4 +405,9 @@ public class TUIChatGroupActivityV2 extends TUIGroupChatActivity {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
}
|