fix:修复私聊未互相关注也可以发消息bug
This commit is contained in:
@@ -830,13 +830,17 @@ public class MessageListPanelEx {
|
||||
if (messages == null) {
|
||||
return;
|
||||
}
|
||||
List<IMMessage> tempMessages = new ArrayList<>();
|
||||
boolean isEmptyTextMessage = true;
|
||||
for (IMMessage message : messages) {
|
||||
if (message.getMsgType() == MsgTypeEnum.text) {
|
||||
tempMessages.add(message);
|
||||
String messageContext = message.getContent();
|
||||
if (!messageContext.equals("我对你很感兴趣并关注了你~快来和我成为好友一起玩吧")) {
|
||||
isEmptyTextMessage = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
EventBus.getDefault().post(new MessageSizeEvent(tempMessages.size()));
|
||||
EventBus.getDefault().post(new MessageSizeEvent(isEmptyTextMessage));
|
||||
if (onMessageFilterListener != null) {
|
||||
messages = onMessageFilterListener.filterLoadedMessage(messages);
|
||||
}
|
||||
|
@@ -625,6 +625,7 @@ public class NimP2PMessageActivity extends NewBaseMessageActivity {
|
||||
tvAttention.setVisibility(View.GONE);
|
||||
tvAttention.setOnClickListener(null);
|
||||
toast(event.isPraise() ? R.string.attention_success : R.string.cancel_fan_success);
|
||||
messageFragment.reloadChatLimitIfLimited();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
|
@@ -19,6 +19,7 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
|
||||
import com.netease.nim.uikit.api.UIKitOptions;
|
||||
import com.netease.nim.uikit.api.model.main.CustomPushContentProvider;
|
||||
@@ -590,59 +591,11 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onReloadInputPanel(MessageSizeEvent event) {
|
||||
if (inputPanel != null) {
|
||||
if (event.getSize() > 0) {
|
||||
if (!event.textMessageIsEmpty) {
|
||||
tvChatLimit.setVisibility(View.GONE);
|
||||
inputPanel.setLimitLevel(true, "");
|
||||
} else {
|
||||
IMCustomModel.get().getPrivateChatLimit(sessionId).subscribe(((privateChatLimitInfo, throwable) -> {
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
} else {
|
||||
isChat = privateChatLimitInfo.isChat();
|
||||
int model = privateChatLimitInfo.getModel();
|
||||
if (model == 2) {
|
||||
hintText = "互相关注成为好友可发起聊天";
|
||||
inputPanel.setLimitLevel(privateChatLimitInfo.isChat(), hintText);
|
||||
tvChatLimit.setText(hintText);
|
||||
tvChatLimit.setVisibility(isChat ? View.GONE : View.VISIBLE);
|
||||
} else {
|
||||
hintText = "暂未达到可发起私聊等级";
|
||||
inputPanel.setLimitLevel(privateChatLimitInfo.isChat(), hintText);
|
||||
String experLevel = "财富等级≥" + privateChatLimitInfo.getWealthLevel();
|
||||
String charmLevel = "魅力等级≥" + privateChatLimitInfo.getCharmLevel();
|
||||
String privacyAgreementDescTip = getContext().getString(R.string.text_chat_limit, experLevel, charmLevel);
|
||||
SpannableString ss = new SpannableString(privacyAgreementDescTip);
|
||||
int experLevelIndex = privacyAgreementDescTip.indexOf(experLevel);
|
||||
int charmLevelIndex = privacyAgreementDescTip.indexOf(charmLevel);
|
||||
|
||||
ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.appColor)), experLevelIndex, experLevelIndex + experLevel.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new OriginalDrawStatusClickSpan(ContextCompat.getColor(getContext(), R.color.appColor)) {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
if (widget instanceof TextView)
|
||||
((TextView) widget).setHighlightColor(getResources().getColor(android.R.color.transparent));
|
||||
|
||||
CommonWebViewActivity.start(getContext(), UriProvider.getUserLevelUrl());
|
||||
}
|
||||
}, experLevelIndex, experLevelIndex + experLevel.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.appColor)), charmLevelIndex, charmLevelIndex + charmLevel.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new OriginalDrawStatusClickSpan(ContextCompat.getColor(getContext(), R.color.appColor)) {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
if (widget instanceof TextView)
|
||||
((TextView) widget).setHighlightColor(getResources().getColor(android.R.color.transparent));
|
||||
|
||||
CommonWebViewActivity.start(getContext(), UriProvider.getUserLevelUrl());
|
||||
}
|
||||
}, charmLevelIndex, charmLevelIndex + experLevel.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
||||
tvChatLimit.setText(ss);
|
||||
tvChatLimit.setHighlightColor(Color.TRANSPARENT);
|
||||
tvChatLimit.setMovementMethod(new LinkMovementMethod());
|
||||
tvChatLimit.setVisibility(isChat ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}));
|
||||
loadChatLimit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -690,4 +643,68 @@ public class MessageFragment extends TFragment implements ModuleProxy, MessageLi
|
||||
public void setCurrentLevel(int currentLevel) {
|
||||
}
|
||||
|
||||
public void reloadChatLimitIfLimited() {
|
||||
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.CREATED)) {
|
||||
return;
|
||||
}
|
||||
if (inputPanel == null) {
|
||||
return;
|
||||
}
|
||||
if (!inputPanel.getLimitLevel()) {
|
||||
loadChatLimit();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private void loadChatLimit(){
|
||||
IMCustomModel.get().getPrivateChatLimit(sessionId).subscribe(((privateChatLimitInfo, throwable) -> {
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
} else {
|
||||
isChat = privateChatLimitInfo.isChat();
|
||||
int model = privateChatLimitInfo.getModel();
|
||||
if (model == 2) {
|
||||
hintText = "互相关注成为好友可发起聊天";
|
||||
inputPanel.setLimitLevel(privateChatLimitInfo.isChat(), hintText);
|
||||
tvChatLimit.setText(hintText);
|
||||
tvChatLimit.setVisibility(isChat ? View.GONE : View.VISIBLE);
|
||||
} else {
|
||||
hintText = "暂未达到可发起私聊等级";
|
||||
inputPanel.setLimitLevel(privateChatLimitInfo.isChat(), hintText);
|
||||
String experLevel = "财富等级≥" + privateChatLimitInfo.getWealthLevel();
|
||||
String charmLevel = "魅力等级≥" + privateChatLimitInfo.getCharmLevel();
|
||||
String privacyAgreementDescTip = getContext().getString(R.string.text_chat_limit, experLevel, charmLevel);
|
||||
SpannableString ss = new SpannableString(privacyAgreementDescTip);
|
||||
int experLevelIndex = privacyAgreementDescTip.indexOf(experLevel);
|
||||
int charmLevelIndex = privacyAgreementDescTip.indexOf(charmLevel);
|
||||
|
||||
ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.appColor)), experLevelIndex, experLevelIndex + experLevel.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new OriginalDrawStatusClickSpan(ContextCompat.getColor(getContext(), R.color.appColor)) {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
if (widget instanceof TextView)
|
||||
((TextView) widget).setHighlightColor(getResources().getColor(android.R.color.transparent));
|
||||
|
||||
CommonWebViewActivity.start(getContext(), UriProvider.getUserLevelUrl());
|
||||
}
|
||||
}, experLevelIndex, experLevelIndex + experLevel.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.appColor)), charmLevelIndex, charmLevelIndex + charmLevel.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new OriginalDrawStatusClickSpan(ContextCompat.getColor(getContext(), R.color.appColor)) {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
if (widget instanceof TextView)
|
||||
((TextView) widget).setHighlightColor(getResources().getColor(android.R.color.transparent));
|
||||
|
||||
CommonWebViewActivity.start(getContext(), UriProvider.getUserLevelUrl());
|
||||
}
|
||||
}, charmLevelIndex, charmLevelIndex + experLevel.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
||||
tvChatLimit.setText(ss);
|
||||
tvChatLimit.setHighlightColor(Color.TRANSPARENT);
|
||||
tvChatLimit.setMovementMethod(new LinkMovementMethod());
|
||||
tvChatLimit.setVisibility(isChat ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@@ -3,17 +3,11 @@ package com.nnbc123.core.room.event;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class MessageSizeEvent implements Serializable {
|
||||
private int size;
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
// 文本消息是否空(忽略了关注提醒文本消息)
|
||||
public boolean textMessageIsEmpty;
|
||||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public MessageSizeEvent(int size) {
|
||||
this.size = size;
|
||||
public MessageSizeEvent(boolean textMessageIsEmpty) {
|
||||
this.textMessageIsEmpty = textMessageIsEmpty;
|
||||
}
|
||||
}
|
||||
|
@@ -959,6 +959,10 @@ public class InputPanel implements IEmoticonSelectedListener, IAudioRecordCallba
|
||||
setEditTextState();
|
||||
}
|
||||
|
||||
public boolean getLimitLevel() {
|
||||
return isChat;
|
||||
}
|
||||
|
||||
private void setEditTextState() {
|
||||
if (!isChat) {
|
||||
messageEditText.setHint(hintText);
|
||||
|
Reference in New Issue
Block a user