添加配置,是否允许发送消息给黑名单用户
This commit is contained in:
@@ -98,6 +98,9 @@ message.allow_stranger_chat_list admin,FireRobot,wfc_file_transfer
|
||||
##黑名单策略,0 发送失败,返回被拉黑的错误码;1 发送成功但消息被服务器直接丢弃
|
||||
message.blacklist.strategy 0
|
||||
|
||||
##拉黑对方后,对方不能发送消息给你。这个开关确定拉黑对方后你还能不能给对方发送消息。
|
||||
message.blacklist.allow_send_to_black false
|
||||
|
||||
##是否禁止服务器端消息搜索,该功能暂未实现。目前的影响是如果打开,则存储消息时不单独保存_searchable_content字段
|
||||
message.disable_remote_search false
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ public final class BrokerConstants {
|
||||
public static final String MESSAGE_Allow_Stranger_Chat_List = "message.allow_stranger_chat_list";
|
||||
|
||||
public static final String MESSAGE_Blacklist_Strategy = "message.blacklist.strategy";
|
||||
public static final String MESSAGE_Blacklist_Allow_Send = "message.blacklist.allow_send_to_black";
|
||||
|
||||
public static final String MESSAGE_NO_Forward_Admin_Message = "message.no_forward_admin_message";
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
private Set<Integer> mForwardExcludeMessageTypes = new HashSet<>();
|
||||
private String mMentionForwardUrl = null;
|
||||
private int mBlacklistStrategy = 0; //黑名单中时,0失败,1吞掉。
|
||||
private boolean mBlacklistAllowSend2Black = true;
|
||||
private boolean mNoForwardAdminMessage = false;
|
||||
|
||||
private String mRemoteSensitiveServerUrl = null;
|
||||
@@ -69,6 +70,12 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
}
|
||||
|
||||
try {
|
||||
mBlacklistAllowSend2Black = Boolean.parseBoolean(mServer.getConfig().getProperty(BrokerConstants.MESSAGE_Blacklist_Allow_Send, "true"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
mRemoteSensitiveServerUrl = mServer.getConfig().getProperty(BrokerConstants.SENSITIVE_Remote_Server_URL);
|
||||
if(!StringUtil.isNullOrEmpty(mRemoteSensitiveServerUrl)) {
|
||||
@@ -154,6 +161,13 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
if(!mBlacklistAllowSend2Black) {
|
||||
errorCode = m_messagesStore.isBlacked(fromUser, message.getConversation().getTarget());
|
||||
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userStatus = m_messagesStore.getUserStatus(message.getConversation().getTarget());
|
||||
|
||||
@@ -3244,6 +3244,30 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode isBlacked(String fromUser, String userId) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
Collection<FriendData> friendDatas = friendsMap.get(fromUser);
|
||||
|
||||
if (friendDatas == null || friendDatas.size() == 0) {
|
||||
friendDatas = loadFriend(friendsMap, fromUser);
|
||||
}
|
||||
|
||||
for (FriendData friendData : friendDatas) {
|
||||
if (friendData.getFriendUid().equals(userId)) {
|
||||
if (friendData.getBlacked() == 1) {
|
||||
return ErrorCode.ERROR_CODE_IN_BLACK_LIST;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
synchronized Collection<FriendData> loadFriend(MultiMap<String, FriendData> friendsMap, String userId) {
|
||||
Collection<FriendData> friends = databaseStore.getPersistFriends(userId);
|
||||
if (friends != null) {
|
||||
|
||||
@@ -186,6 +186,7 @@ public interface IMessagesStore {
|
||||
FriendData getFriendData(String fromUser, String targetUserId);
|
||||
ErrorCode SyncFriendRequestUnread(String userId, long unreadDt, long[] head);
|
||||
ErrorCode isAllowUserMessage(String fromUser, String userId);
|
||||
ErrorCode isBlacked(String fromUser, String userId);
|
||||
ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] head);
|
||||
ErrorCode setFriendExtraRequest(String fromUser, String targetUserId, String extra, long[] head);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user