添加禁言时例外消息类型

This commit is contained in:
imhao183
2021-03-19 14:33:17 +08:00
parent 1c9c77c06b
commit f04f4fb087
6 changed files with 107 additions and 15 deletions
+9
View File
@@ -81,6 +81,15 @@ message.recall_time_limit 120
## 一般用于重要类型消息,比如交易、充值等,禁止客户端发送,仅限于服务器发送,提高安全性。 ## 一般用于重要类型消息,比如交易、充值等,禁止客户端发送,仅限于服务器发送,提高安全性。
message.forbidden_client_send_types 3999,4000,4001 message.forbidden_client_send_types 3999,4000,4001
## 当禁止发送消息时,允许例外发送的消息。这种一般用户需要被动回应的消息。比如群中被禁言的用户,他无法主动发起音视频,但可以接听未被禁言用户的音视频
## 因为音视频使用了消息作为信令,所以就需要允许发送音视频信令。如果开发了其它场景也需要被动回应消息,可以加在这里。
## 黑名单时允许发送的消息类型
message.blacklist_exception_types 401,402,403,404,405,407,408,410,411
## 群禁言或者聊天室或者频道禁言时允许发送的消息类型
message.group_mute_exception_types 401,402,403,404,405,407,408,410,411
## 用户被全局禁言时允许发送的消息类型
message.global_mute_exception_types 401,402,403,404,405,407,408,410,411
##禁止搜索用户 ##禁止搜索用户
friend.disable_search false friend.disable_search false
@@ -157,6 +157,9 @@ public final class BrokerConstants {
public static final String USER_HIDE_PROPERTIES = "user.hide_properties"; public static final String USER_HIDE_PROPERTIES = "user.hide_properties";
public static final String MESSAGES_FORBIDDEN_CLIENT_SEND_TYPES = "message.forbidden_client_send_types"; public static final String MESSAGES_FORBIDDEN_CLIENT_SEND_TYPES = "message.forbidden_client_send_types";
public static final String MESSAGES_BLACKLIST_EXCEPTION_TYPES = "message.blacklist_exception_types";
public static final String MESSAGES_GROUP_MUTE_EXCEPTION_TYPES = "message.group_mute_exception_types";
public static final String MESSAGES_GLOBAL_MUTE_EXCEPTION_TYPES = "message.global_mute_exception_types";
public static final String MESSAGES_DISABLE_REMOTE_SEARCH = "message.disable_remote_search"; public static final String MESSAGES_DISABLE_REMOTE_SEARCH = "message.disable_remote_search";
@@ -105,17 +105,21 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
int userStatus = m_messagesStore.getUserStatus(fromUser); int userStatus = m_messagesStore.getUserStatus(fromUser);
if (userStatus == ProtoConstants.UserStatus.Muted || userStatus == ProtoConstants.UserStatus.Forbidden) { if (userStatus == ProtoConstants.UserStatus.Muted || userStatus == ProtoConstants.UserStatus.Forbidden) {
return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG; if(!m_messagesStore.getGlobalMuteExceptionTypes().contains(message.getContent().getType())) {
return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG;
}
} }
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private) { if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private) {
errorCode = m_messagesStore.isAllowUserMessage(message.getConversation().getTarget(), fromUser); if(!m_messagesStore.getBlackListExceptionTypes().contains(message.getContent().getType())) {
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) { errorCode = m_messagesStore.isAllowUserMessage(message.getConversation().getTarget(), fromUser);
if (errorCode == ErrorCode.ERROR_CODE_IN_BLACK_LIST && mBlacklistStrategy != ProtoConstants.BlacklistStrategy.Message_Reject) { if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
ignoreMsg = true; if (errorCode == ErrorCode.ERROR_CODE_IN_BLACK_LIST && mBlacklistStrategy != ProtoConstants.BlacklistStrategy.Message_Reject) {
errorCode = ErrorCode.ERROR_CODE_SUCCESS; ignoreMsg = true;
} else { errorCode = ErrorCode.ERROR_CODE_SUCCESS;
return errorCode; } else {
return errorCode;
}
} }
} }
@@ -126,17 +130,23 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
} }
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group ) { if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group ) {
errorCode = m_messagesStore.canSendMessageInGroup(fromUser, message.getConversation().getTarget()); if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) {
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) { errorCode = m_messagesStore.canSendMessageInGroup(fromUser, message.getConversation().getTarget());
return errorCode; if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
return errorCode;
}
} }
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom) { } else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom) {
if(!m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) { if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) {
return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM; if (!m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) {
return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM;
}
} }
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) { } else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) {
if(!m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) { if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) {
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL; if (!m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) {
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
}
} }
} }
} }
@@ -139,6 +139,9 @@ public class MemoryMessagesStore implements IMessagesStore {
private boolean mChatroomRejoinWhenActive = true; private boolean mChatroomRejoinWhenActive = true;
private List<Integer> mForbiddenClientSendTypes = new ArrayList<>(); private List<Integer> mForbiddenClientSendTypes = new ArrayList<>();
private List<Integer> mBlackListExceptionTypes = new ArrayList<>();
private List<Integer> mGroupMuteExceptionTypes = new ArrayList<>();
private List<Integer> mGlobalMuteExceptionTypes = new ArrayList<>();
private long mRecallTimeLimit = 300; private long mRecallTimeLimit = 300;
@@ -275,7 +278,48 @@ public class MemoryMessagesStore implements IMessagesStore {
} catch (Exception e) { } catch (Exception e) {
} }
try {
String strTypes = m_Server.getConfig().getProperty(BrokerConstants.MESSAGES_BLACKLIST_EXCEPTION_TYPES);
if(!StringUtil.isNullOrEmpty(strTypes)) {
for (String strType:strTypes.split(",")) {
try {
int type = Integer.parseInt(strType);
mBlackListExceptionTypes.add(type);
} catch (NumberFormatException e) {
}
}
}
} catch (Exception e) {
}
try {
String strTypes = m_Server.getConfig().getProperty(BrokerConstants.MESSAGES_GROUP_MUTE_EXCEPTION_TYPES);
if(!StringUtil.isNullOrEmpty(strTypes)) {
for (String strType:strTypes.split(",")) {
try {
int type = Integer.parseInt(strType);
mGroupMuteExceptionTypes.add(type);
} catch (NumberFormatException e) {
}
}
}
} catch (Exception e) {
}
try {
String strTypes = m_Server.getConfig().getProperty(BrokerConstants.MESSAGES_GLOBAL_MUTE_EXCEPTION_TYPES);
if(!StringUtil.isNullOrEmpty(strTypes)) {
for (String strType:strTypes.split(",")) {
try {
int type = Integer.parseInt(strType);
mGlobalMuteExceptionTypes.add(type);
} catch (NumberFormatException e) {
}
}
}
} catch (Exception e) {
}
try { try {
mGroupInfoUpdateCallback = server.getConfig().getProperty(GROUP_INFO_UPDATE_CALLBACK); mGroupInfoUpdateCallback = server.getConfig().getProperty(GROUP_INFO_UPDATE_CALLBACK);
@@ -3467,6 +3511,21 @@ public class MemoryMessagesStore implements IMessagesStore {
return mForbiddenClientSendTypes; return mForbiddenClientSendTypes;
} }
@Override
public List<Integer> getBlackListExceptionTypes() {
return mBlackListExceptionTypes;
}
@Override
public List<Integer> getGroupMuteExceptionTypes() {
return mGroupMuteExceptionTypes;
}
@Override
public List<Integer> getGlobalMuteExceptionTypes() {
return mGlobalMuteExceptionTypes;
}
@Override @Override
public long getMessageHead(String user) { public long getMessageHead(String user) {
TreeMap<Long, Long> maps = userMessages.get(user); TreeMap<Long, Long> maps = userMessages.get(user);
@@ -220,6 +220,9 @@ public interface IMessagesStore {
int getVisibleQuitKickoffNotification(); int getVisibleQuitKickoffNotification();
List<Integer> getClientForbiddenSendTypes(); List<Integer> getClientForbiddenSendTypes();
List<Integer> getBlackListExceptionTypes();
List<Integer> getGroupMuteExceptionTypes();
List<Integer> getGlobalMuteExceptionTypes();
long getMessageHead(String user); long getMessageHead(String user);
long getFriendHead(String user); long getFriendHead(String user);
@@ -76,6 +76,14 @@ message.recall_time_limit 120
## 一般用于重要类型消息,比如交易、充值等,禁止客户端发送,仅限于服务器发送,提高安全性。 ## 一般用于重要类型消息,比如交易、充值等,禁止客户端发送,仅限于服务器发送,提高安全性。
message.forbidden_client_send_types 3999,4000,4001 message.forbidden_client_send_types 3999,4000,4001
## 当禁止发送消息时,允许例外发送的消息。这种一般用户需要被动回应的消息。比如群中被禁言的用户,他无法主动发起音视频,但可以接听未被禁言用户的音视频
## 因为音视频使用了消息作为信令,所以就需要允许发送音视频信令。如果开发了其它场景也需要被动回应消息,可以加在这里。
## 黑名单时允许发送的消息类型
message.blacklist_exception_types 401,402,403,404,405,407,408,410,411
## 群禁言或者聊天室或者频道禁言时允许发送的消息类型
message.group_mute_exception_types 401,402,403,404,405,407,408,410,411
## 用户被全局禁言时允许发送的消息类型
message.global_mute_exception_types 401,402,403,404,405,407,408,410,411
##禁止搜索用户 ##禁止搜索用户
friend.disable_search false friend.disable_search false