禁止发送消息给被封禁用户

This commit is contained in:
imhao183
2019-12-26 21:18:34 +08:00
parent 91b209d0fa
commit 11375133ba
4 changed files with 15 additions and 3 deletions
@@ -52,7 +52,7 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
return ErrorCode.INVALID_PARAMETER; return ErrorCode.INVALID_PARAMETER;
} }
int userStatus = m_messagesStore.getUserStatus(fromUser); int userStatus = m_messagesStore.getUserStatus(fromUser);
if (userStatus == 1 || userStatus == 2) { if (userStatus == ProtoConstants.UserStatus.Muted || userStatus == ProtoConstants.UserStatus.Forbidden) {
return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG; return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG;
} }
@@ -61,6 +61,11 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) { if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
return errorCode; return errorCode;
} }
userStatus = m_messagesStore.getUserStatus(message.getConversation().getTarget());
if (userStatus == ProtoConstants.UserStatus.Forbidden) {
return ErrorCode.ERROR_CODE_USER_FORBIDDEN;
}
} }
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group ) { if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group ) {
@@ -129,7 +129,7 @@ public class MemoryMessagesStore implements IMessagesStore {
Constants.MAX_MESSAGE_QUEUE = Integer.parseInt(m_Server.getConfig().getProperty(MESSAGE_Max_Queue)); Constants.MAX_MESSAGE_QUEUE = Integer.parseInt(m_Server.getConfig().getProperty(MESSAGE_Max_Queue));
try { try {
mDisableStrangerChat = Boolean.parseBoolean(Server.getConfig().getProperty(BrokerConstants.MESSAGE_Disable_Stranger_Chat)); mDisableStrangerChat = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.MESSAGE_Disable_Stranger_Chat));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -17,6 +17,7 @@
package io.moquette.spi.impl; package io.moquette.spi.impl;
import cn.wildfirechat.common.ErrorCode; import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage; import cn.wildfirechat.proto.WFCMessage;
import io.moquette.persistence.RPCCenter; import io.moquette.persistence.RPCCenter;
import io.moquette.interception.InterceptHandler; import io.moquette.interception.InterceptHandler;
@@ -265,7 +266,7 @@ public class ProtocolProcessor {
// handle user authentication // handle user authentication
if (msg.variableHeader().hasUserName()) { if (msg.variableHeader().hasUserName()) {
int status = m_messagesStore.getUserStatus(msg.payload().userName()); int status = m_messagesStore.getUserStatus(msg.payload().userName());
if (status == 2) { if (status == ProtoConstants.UserStatus.Forbidden) {
failedBlocked(channel); failedBlocked(channel);
return false; return false;
} }
@@ -139,6 +139,12 @@ public class ProtoConstants {
int SearchUserType_Mobile = 3; int SearchUserType_Mobile = 3;
} }
public interface UserStatus {
int Normal = 0;
int Muted = 1;
int Forbidden = 2;
}
public static final int MESSAGE_CONTENT_TYPE_CREATE_GROUP = 104; public static final int MESSAGE_CONTENT_TYPE_CREATE_GROUP = 104;