MM 去掉撤销通知,修改MM世界聊天

This commit is contained in:
guozhen
2024-12-27 16:29:33 +08:00
committed by xuhuixiang
parent b13a542488
commit 4125a69573
7 changed files with 192 additions and 232 deletions

View File

@@ -164,8 +164,6 @@ public class IMUIKitConfig {
public static String SERVICES_IDS_TAG = "services_id";
public static String RING_MESSAGE_TAG = "message_rings";
public static String RING_CALL_TAG = "call_rings";
//世界聊天ids
public static String SHIJIECHAT_IDS_TAG = "shijiechat_id";
/**
* GoogleMap apikey

View File

@@ -87,6 +87,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
@@ -121,7 +122,6 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
private Observer<FetchResult<Integer>> unreadCountObserver;
private ChatDraftDataDao dataDao;
private ChatTabFragment chatTabParentFragment;
protected final EventNotify<ChangeChatDraftEvent> changeDraftEvent =
new EventNotify<ChangeChatDraftEvent>() {
@@ -223,111 +223,146 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
bindView();
registerObserver();
EventCenter.registerEventNotify(changeDraftEvent);
// if (conversationType != 1) {
// getNotifiesCount();
// }
if (conversationType != 1) {
getNotifiesCount();
}
}
public ArrayList<String> groupShiJieIds = new ArrayList<>(); //官方群聊
private List<String> groupIds = new ArrayList<>();
// private void getNotifiesCount() {
// Api.getInstance().notifiesmessageCountNew(IMKitClient.account(), DataUtils.getCurrentTimeType(System.currentTimeMillis()))
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new BaseObserver<>() {
// @Override
// public void onSuccess(Result<NotifyCountBean> feedbackResp) {
// LogUtils.i("获取到的错误:" + feedbackResp + "" + feedbackResp.data);
// String groupId = feedbackResp.data.getGroupId();
// if (!TextUtils.isEmpty(groupId)) {
// try {
// JSONArray array = new JSONArray(groupId);
// if (array.length() > 0) {
// String values = array.getString(0);
// if (!TextUtils.isEmpty(values)) {
// String[] groupIdStr = values.split(",");
// groupShiJieIds.addAll(Arrays.asList(groupIdStr));
// queryTeamInfo();
// }
// }
// } catch (JSONException e) {
// throw new RuntimeException(e);
// }
// }
// }
//
//
// @Override
// public void onError(int code, String msg) {
// LogUtils.i("获取到的错误:" + code + "" + msg);
//// WidgetUtils.showToast(getActivity(), msg, WidgetUtils.ToastType.ERROR);
// LogUtils.i("获取到的错误:" + code + "" + msg);
// }
// });
// }
//
// private void queryTeamInfo() {
// for (String groupId : groupShiJieIds) {
// NIMClient.getService(TeamService.class).searchTeam(groupId).setCallback(new RequestCallback<Team>() {
// @Override
// public void onSuccess(Team result) {
// addShiJieConversation(result);
// }
//
// @Override
// public void onFailed(int code) {
//
// }
//
// @Override
// public void onException(Throwable exception) {
//
// }
// });
// }
//
// }
// public void addShiJieConversation(Team team) {
// RecentContact recentContact = NIMClient.getService(MsgService.class).createEmptyRecentContact(team.getId(), SessionTypeEnum.Team, 0, System.currentTimeMillis(), true, true);
// ConversationInfo info = new ConversationInfo(recentContact);
// info.setTeamInfo(team);
// info.setStickTop(true);
// ConversationBean conversationBean = new ConversationBean(info);
// conversationBean.isShiJie = true;
// List<ConversationBean> list = new ArrayList<>();
// if (conversationType == 0) {
// boolean isAdd = false;
// for (ConversationBean conversationBean1 : conversationViewTop.getAdatper().getConversationList()) {
// if (conversationBean1.infoData.getTeamInfo() != null && Objects.equals(conversationBean1.infoData.getTeamInfo().getId(), team.getId())) {
// conversationBean1.infoData.setStickTop(true);
// conversationBean1.isShiJie = true;
// isAdd = true;
// break;
// }
// }
// if (!isAdd) {
// list.add(conversationBean);
// conversationViewTop.addData(list);
// }
// } else if (conversationType == 2) {
// boolean isAdd = false;
// for (ConversationBean conversationBean1 : conversationViewShiJie.getAdatper().getConversationList()) {
// if (conversationBean1.infoData.getTeamInfo() != null && Objects.equals(conversationBean1.infoData.getTeamInfo().getId(), team.getId())) {
// conversationBean1.infoData.setStickTop(true);
// conversationBean1.isShiJie = true;
// isAdd = true;
// break;
// }
// }
// if (!isAdd) {
// list.add(conversationBean);
// conversationViewShiJie.addData(list);
// }
// }
//
//
// }
private void getNotifiesCount() {
Api.getInstance().notifiesmessageCountNew(IMKitClient.account(), DataUtils.getCurrentTimeType(System.currentTimeMillis()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObserver<>() {
@Override
public void onSuccess(Result<NotifyCountBean> feedbackResp) {
LogUtils.i("获取到的错误:" + feedbackResp + "" + feedbackResp.data);
String groupId = feedbackResp.data.getGroupId();
if (!TextUtils.isEmpty(groupId)) {
try {
JSONArray array = new JSONArray(groupId);
if (array.length() > 0) {
String values = array.getString(0);
if (!TextUtils.isEmpty(values)) {
String[] groupIdStr = values.split(",");
groupIds.addAll(Arrays.asList(groupIdStr));
queryTeamInfo();
}
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}
@Override
public void onError(int code, String msg) {
LogUtils.i("获取到的错误:" + code + "" + msg);
// WidgetUtils.showToast(getActivity(), msg, WidgetUtils.ToastType.ERROR);
LogUtils.i("获取到的错误:" + code + "" + msg);
}
});
}
private void queryTeamInfo() {
for (String groupId : groupIds) {
NIMClient.getService(TeamService.class).searchTeam(groupId).setCallback(new RequestCallback<Team>() {
@Override
public void onSuccess(Team result) {
addShiJieConversation(result);
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
});
}
}
public void addShiJieConversation(Team team) {
RecentContact recentContact = NIMClient.getService(MsgService.class).createEmptyRecentContact(team.getId(), SessionTypeEnum.Team, 0, System.currentTimeMillis(), true, true);
ConversationInfo info = new ConversationInfo(recentContact);
info.setTeamInfo(team);
ConversationBean conversationBean = new ConversationBean(info);
conversationBean.isShiJie = true;
conversationBean.infoData.setTeamInfo(team);
conversationBean.infoData.setStickTop(true);
List<ConversationBean> list = new ArrayList<>();
if (conversationType == 0) {
boolean isAdd = false;
for (ConversationBean conversationBean1 : conversationViewTop.getAdatper().getConversationList()) {
Team team1 = conversationBean1.infoData.getTeamInfo();
if (conversationBean1.isShiJie || (team1 != null && Objects.equals(team1.getId(), team.getId()))) {
conversationBean1.infoData.setStickTop(true);
conversationBean1.isShiJie = true;
conversationBean1.infoData.setTeamInfo(team1 == null ? team : team1);
isAdd = true;
break;
}
}
if (!isAdd) {
list.add(conversationBean);
conversationViewTop.addData(list);
conversationViewTop.addStickTop(team.getId());
}
} else if (conversationType == 2) {
ConversationBean conversationBeanItem = null;
for (ConversationBean conversationBean1 : conversationViewTop.getAdatper().getConversationList()) {
if (conversationBean1.infoData.getTeamInfo() != null && Objects.equals(conversationBean1.infoData.getTeamInfo().getId(), team.getId())) {
conversationBean1.infoData.setStickTop(true);
conversationBean1.isShiJie = true;
conversationBeanItem = conversationBean1;
conversationViewTop.getAdatper().removeData(conversationBean1.infoData.getContactId());
break;
}
}
for (ConversationBean conversationBean1 : conversationViewBottom.getAdatper().getConversationList()) {
if (conversationBean1.infoData.getTeamInfo() != null && Objects.equals(conversationBean1.infoData.getTeamInfo().getId(), team.getId())) {
conversationBean1.infoData.setStickTop(true);
conversationBean1.isShiJie = true;
conversationBeanItem = conversationBean1;
conversationViewBottom.getAdatper().removeData(conversationBean1.infoData.getContactId());
break;
}
}
setDataNumber();
boolean isAdd = false;
for (ConversationBean conversationBean1 : conversationViewShiJie.getAdatper().getConversationList()) {
if (conversationBean1.infoData.getTeamInfo() != null && Objects.equals(conversationBean1.infoData.getTeamInfo().getId(), team.getId())) {
conversationBean1.infoData.setStickTop(true);
conversationBean1.isShiJie = true;
isAdd = true;
break;
}
}
if (!isAdd) {
if (conversationBeanItem != null) {
list.add(conversationBeanItem);
} else {
list.add(conversationBean); //有时候这个创建的空会话数据不全
}
conversationViewShiJie.addData(list);
conversationViewShiJie.addStickTop(team.getId());
}
}
}
private void registerObserver() {
viewModel.getChangeLiveData().observeForever(changeObserver);
@@ -391,7 +426,7 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
public List<ConversationBean> removeShiJieConversation(List<ConversationBean> conversationBeans) {
List<ConversationBean> conversationBeans1 = new ArrayList<>();
for (ConversationBean conversationBean : conversationBeans) {
if (!chatTabParentFragment.groupIds.contains(conversationBean.infoData.getContactId())) {
if (!groupIds.contains(conversationBean.infoData.getContactId())) {
conversationBeans1.add(conversationBean);
}
}
@@ -422,7 +457,6 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
}
}
doEmptyView();
doCallback();
if (conversationType == 1) {
@@ -470,6 +504,8 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
conversationViewTop.updateTeamInfoType(result.getData(), true);
conversationViewBottom.updateTeamInfoType(result.getData(), false);
conversationViewShiJie.updateTeamInfo(result.getData());
doEmptyView();
}
}
};
@@ -567,7 +603,6 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
private boolean showAllJoinTeam = false;
private void initView() {
chatTabParentFragment = (ChatTabFragment) getParentFragment();
viewBinding.layoutShijiechat.setVisibility(View.GONE);
conversationViewTop = viewBinding.conversationViewTop;
conversationViewShiJie = viewBinding.conversationViewTeamShijie;
@@ -638,6 +673,7 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
}
}
private void initData() {
viewModel
.getQueryLiveData()
@@ -689,13 +725,13 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
switch (conversationType) {
case 0:
List<ConversationBean> listconversation = updateServicesConversation(result.getData());
if (chatTabParentFragment.groupIds != null) { //添加世界聊天窗口
LogUtils.d("shijie", "添加世界聊天==" + chatTabParentFragment.groupIds.size());
List<ConversationBean> conversationShiJieList = addConversationTeamShiJie(listconversation);
LogUtils.d("shijie", "添加世界聊天==" + conversationShiJieList.size());
listconversation.addAll(conversationShiJieList);
}
Collections.sort(listconversation, conversationShiJieComparator);
// if (chatTabParentFragment.groupIds != null) { //添加世界聊天窗口
// LogUtils.d("shijie", "添加世界聊天==" + chatTabParentFragment.groupIds.size());
// List<ConversationBean> conversationShiJieList = addConversationTeamShiJie(listconversation);
// LogUtils.d("shijie", "添加世界聊天==" + conversationShiJieList.size());
// listconversation.addAll(conversationShiJieList);
// }
// Collections.sort(listconversation, conversationShiJieComparator);
conversationViewTop.setData(listconversation);
break;
case 1:
@@ -704,9 +740,6 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
break;
case 2:
getConversationTeamTypeList(result.getData());
LogUtils.d("shijie", "添加世界聊天 群组 groupsid==" + chatTabParentFragment.groupIds.size());
listGuanfangTeam.addAll(addConversationTeamShiJie(listGuanfangTeam));
LogUtils.d("shijie", "添加世界聊天 群组==" + listGuanfangTeam.size());
setChatDraftDataList(listMyTeam);
setChatDraftDataList(listJoinTeam);
setChatDraftDataList(listGuanfangTeam);
@@ -718,35 +751,35 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
}
//在已有的会话中添加世界聊天会话
public List<ConversationBean> addConversationTeamShiJie(List<ConversationBean> recentContactList) {
List<ConversationBean> listconversation = new ArrayList<>();
for (int i = 0; i < chatTabParentFragment.groupIds.size(); i++) {
boolean isAdd = false;
for (ConversationBean conversationBean : recentContactList) {
if (conversationBean.infoData.getContactId().equals(chatTabParentFragment.groupIds.get(i))) {
conversationBean.isShiJie = true;
conversationBean.infoData.setStickTop(true);
isAdd = true;
}
}
if (!isAdd) {
RecentContact recentContact = NIMClient.getService(MsgService.class).createEmptyRecentContact(chatTabParentFragment.groupIds.get(i), SessionTypeEnum.Team, 0, System.currentTimeMillis(), true, true);
ConversationInfo info = new ConversationInfo(recentContact);
if (chatTabParentFragment.teamInfos.size() > 0) {
info.setTeamInfo(chatTabParentFragment.teamInfos.get(i));
}
info.setStickTop(true);
ConversationBean conversationBean = new ConversationBean(info);
conversationBean.isShiJie = true;
listconversation.add(conversationBean);
}
}
return listconversation;
}
// //在已有的会话中添加世界聊天会话
// public List<ConversationBean> addConversationTeamShiJie(List<ConversationBean> recentContactList) {
// List<ConversationBean> listconversation = new ArrayList<>();
// for (int i = 0; i < chatTabParentFragment.groupIds.size(); i++) {
// boolean isAdd = false;
// for (ConversationBean conversationBean : recentContactList) {
// if (conversationBean.infoData.getContactId().equals(chatTabParentFragment.groupIds.get(i))) {
// conversationBean.isShiJie = true;
// conversationBean.infoData.setStickTop(true);
// isAdd = true;
// }
// }
// if (!isAdd) {
// RecentContact recentContact = NIMClient.getService(MsgService.class).createEmptyRecentContact(chatTabParentFragment.groupIds.get(i), SessionTypeEnum.Team, 0, System.currentTimeMillis(), true, true);
// ConversationInfo info = new ConversationInfo(recentContact);
// if (chatTabParentFragment.teamInfos.size() > 0) {
// info.setTeamInfo(chatTabParentFragment.teamInfos.get(i));
// }
// info.setStickTop(true);
// ConversationBean conversationBean = new ConversationBean(info);
// conversationBean.isShiJie = true;
// listconversation.add(conversationBean);
// }
//
// }
// return listconversation;
//
//
// }
// // 設置包含世界聊天
@@ -803,7 +836,6 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
private void setUpdateViewData(int conversationType, List<ConversationBean> result) {
switch (conversationType) {
case 0:
LogUtils.d("shijie", "更新世界聊天" + result.size());
conversationViewTop.update(updateServicesConversation(result));
break;
case 1:
@@ -811,11 +843,9 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
conversationViewTop.update(updateServicesConversation(listFriend));
break;
case 2:
LogUtils.d("shijie", "更新世界聊天2 " + result.size());
getConversationTeamTypeList(result);
setChatDraftDataList(listMyTeam);
setChatDraftDataList(listJoinTeam);
LogUtils.d("shijie", "更新世界聊天2 " + listGuanfangTeam.size());
conversationViewTop.update(listMyTeam);
conversationViewBottom.update(listJoinTeam);
conversationViewShiJie.update(listGuanfangTeam);
@@ -851,7 +881,7 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
if (servicesIds == null || servicesIds.size() == 0) {
return beans;
}
if (chatTabParentFragment.groupIds == null) {
if (groupIds == null) {
return beans;
}
@@ -862,7 +892,7 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
conversationBean.isServices = true;
}
if (conversationBean.infoData.getSessionType() == SessionTypeEnum.Team || conversationBean.infoData.getSessionType() == SessionTypeEnum.SUPER_TEAM) {
if (chatTabParentFragment.groupIds.contains(conversationBean.infoData.getContactId())) {
if (groupIds.contains(conversationBean.infoData.getContactId())) {
conversationBean.isShiJie = true;
conversationBean.infoData.setStickTop(true);
}
@@ -908,7 +938,7 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
}
public boolean isShiJieConversation(ConversationBean conversationBean) {
return chatTabParentFragment.groupIds.contains(conversationBean.infoData.getContactId());
return groupIds.contains(conversationBean.infoData.getContactId());
}
private void doEmptyView() {
@@ -1126,4 +1156,6 @@ public class ChatConversationFragment extends BaseFragment implements ILoadListe
EventCenter.unregisterEventNotify(changeDraftEvent);
super.onDestroyView();
}
}

View File

@@ -158,7 +158,6 @@ public class ChatTabFragment extends BaseFragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getServicesData();
getGroupIdsData();
initView();
// NetworkUtils.registerNetworkStatusChangedListener(networkStateListener);
EventCenter.registerEventNotify(editConversation);
@@ -234,7 +233,6 @@ public class ChatTabFragment extends BaseFragment {
int verifyCount = 0;
int notifyCount = 0;
public ArrayList<String> groupIds = new ArrayList<>(); //官方群聊
public List<Team> teamInfos = new ArrayList<>();
private void getNotifiesCount() {
notifyCount = 0;
@@ -260,7 +258,6 @@ public class ChatTabFragment extends BaseFragment {
String[] groupIdStr = values.split(",");
groupIds.clear();
groupIds.addAll(Arrays.asList(groupIdStr));
queryTeamInfo();
}
}
} catch (JSONException e) {
@@ -271,7 +268,8 @@ public class ChatTabFragment extends BaseFragment {
if (activityMsgCount > msgcount) {
DataUtils.set(getActivity(), "activity_message_count", activityMsgCount);
}
notifyCount = count + activityMsgCount;
// notifyCount = count + activityMsgCount; MM 活动通知取消
notifyCount = count + 0;
setNotifyTotalCount();
}
@@ -285,27 +283,7 @@ public class ChatTabFragment extends BaseFragment {
});
}
private void queryTeamInfo() {
for (String groupId : groupIds) {
NIMClient.getService(TeamService.class).searchTeam(groupId).setCallback(new RequestCallback<Team>() {
@Override
public void onSuccess(Team result) {
teamInfos.add(result);
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
});
}
}
private void getServicesData() {
String tagString = DataUtils.get(IMApplication.getAppContext(), IMUIKitConfig.SERVICES_IDS_TAG + "_" + IMKitClient.account(), "");
@@ -316,28 +294,6 @@ public class ChatTabFragment extends BaseFragment {
}
}
private void getGroupIdsData() {
String tagString = DataUtils.get(IMApplication.getAppContext(), IMUIKitConfig.SHIJIECHAT_IDS_TAG, "");
if (!TextUtils.isEmpty(tagString)) {
try {
JSONArray array = new JSONArray(tagString);
if (array.length() > 0) {
String values = array.getString(0);
if (!TextUtils.isEmpty(values)) {
String[] groupIdStr = values.split(",");
groupIds.clear();
groupIds.addAll(Arrays.asList(groupIdStr));
queryTeamInfo();
}
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}
public Comparator<ConversationInfo> conversationComparator =
(bean1, bean2) -> {
int result;

View File

@@ -106,7 +106,6 @@ public class WelcomeActivity extends BaseActivity {
getScheme(uri);
// initClip();
//activityWelcomeBinding.bigBg.setBackgroundResource(R.color.color_white);
getNotifiesCount();
if (TextUtils.isEmpty(NIMClient.getCurrentAccount())) {
startLogin();
} else {
@@ -141,31 +140,6 @@ public class WelcomeActivity extends BaseActivity {
}
private void getNotifiesCount(){
Api.getInstance().notifiesmessageCountNew(IMKitClient.account(), DataUtils.getCurrentTimeType(System.currentTimeMillis()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObserver<>() {
@Override
public void onSuccess(Result<NotifyCountBean> feedbackResp) {
LogUtils.i("获取到的错误:" + feedbackResp + "" + feedbackResp.data);
String groupId = feedbackResp.data.getGroupId();
if (!TextUtils.isEmpty(groupId)) {
DataUtils.set(WelcomeActivity.this, IMUIKitConfig.SHIJIECHAT_IDS_TAG, groupId);
}
}
@Override
public void onError(int code, String msg) {
LogUtils.i("获取到的错误:" + code + "" + msg);
// WidgetUtils.showToast(getActivity(), msg, WidgetUtils.ToastType.ERROR);
LogUtils.i("获取到的错误:" + code + "" + msg);
}
});
}
private void showIsLogin(boolean isLogin) {
//加载动画