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

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;
}
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;
}
@@ -61,6 +61,11 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
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 ) {
@@ -129,7 +129,7 @@ public class MemoryMessagesStore implements IMessagesStore {
Constants.MAX_MESSAGE_QUEUE = Integer.parseInt(m_Server.getConfig().getProperty(MESSAGE_Max_Queue));
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) {
e.printStackTrace();
}
@@ -17,6 +17,7 @@
package io.moquette.spi.impl;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import io.moquette.persistence.RPCCenter;
import io.moquette.interception.InterceptHandler;
@@ -265,7 +266,7 @@ public class ProtocolProcessor {
// handle user authentication
if (msg.variableHeader().hasUserName()) {
int status = m_messagesStore.getUserStatus(msg.payload().userName());
if (status == 2) {
if (status == ProtoConstants.UserStatus.Forbidden) {
failedBlocked(channel);
return false;
}