频道权限问题,非订阅用户可以给全局频道和可以给非订阅用户发消息的频道回复消息

This commit is contained in:
heavyrain2012
2021-12-24 22:14:04 +08:00
parent cb09026408
commit 7ca3abe12d
6 changed files with 32 additions and 9 deletions
@@ -14,16 +14,12 @@ import cn.wildfirechat.pojos.InputGetUserInfo;
import cn.wildfirechat.pojos.InputOutputUserInfo; import cn.wildfirechat.pojos.InputOutputUserInfo;
import cn.wildfirechat.proto.ProtoConstants; import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage; import cn.wildfirechat.proto.WFCMessage;
import com.google.gson.Gson;
import com.xiaoleilu.loServer.RestResult; import com.xiaoleilu.loServer.RestResult;
import com.xiaoleilu.loServer.action.admin.AdminAction;
import com.xiaoleilu.loServer.action.robot.RobotAction;
import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.HttpMethod;
import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.annotation.Route;
import com.xiaoleilu.loServer.handler.Request; import com.xiaoleilu.loServer.handler.Request;
import com.xiaoleilu.loServer.handler.Response; import com.xiaoleilu.loServer.handler.Response;
import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
@Route(APIPath.Channel_User_Info) @Route(APIPath.Channel_User_Info)
@@ -12,7 +12,6 @@ package com.xiaoleilu.loServer.action.channel;
import cn.wildfirechat.common.APIPath; import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.pojos.SendChannelMessageData; import cn.wildfirechat.pojos.SendChannelMessageData;
import cn.wildfirechat.proto.ProtoConstants; import cn.wildfirechat.proto.ProtoConstants;
import com.google.gson.Gson;
import com.xiaoleilu.loServer.RestResult; import com.xiaoleilu.loServer.RestResult;
import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.HttpMethod;
import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.annotation.Route;
@@ -24,7 +23,6 @@ import cn.wildfirechat.pojos.SendMessageResult;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import cn.wildfirechat.common.ErrorCode; import cn.wildfirechat.common.ErrorCode;
import win.liyufan.im.IMTopic; import win.liyufan.im.IMTopic;
@@ -33,7 +33,7 @@ public class LoadRemoteMessagesHandler extends IMHandler<WFCMessage.LoadRemoteMe
} }
if (request.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) { if (request.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) {
if (!m_messagesStore.checkUserInChannel(fromUser, request.getConversation().getTarget())) { if (!m_messagesStore.canSendMessageInChannel(fromUser, request.getConversation().getTarget())) {
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL; return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
} }
} }
@@ -154,7 +154,7 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
} }
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) { } else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) {
if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) { if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) {
if (!m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) { if (!m_messagesStore.canSendMessageInChannel(fromUser, message.getConversation().getTarget())) {
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL; return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
} }
} }
@@ -48,7 +48,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Consumer; import java.util.function.Consumer;
import static cn.wildfirechat.common.IMExceptionEvent.EventType.EVENT_CALLBACK_Exception; import static cn.wildfirechat.common.IMExceptionEvent.EventType.EVENT_CALLBACK_Exception;
import static cn.wildfirechat.proto.ProtoConstants.ChannelState.Channel_State_Mask_Deleted; import static cn.wildfirechat.proto.ProtoConstants.ChannelState.*;
import static cn.wildfirechat.proto.ProtoConstants.ChannelUpdateEventType.*; import static cn.wildfirechat.proto.ProtoConstants.ChannelUpdateEventType.*;
import static cn.wildfirechat.proto.ProtoConstants.ChatroomMemberUpdateEventType.Chatroom_Member_Event_Join; import static cn.wildfirechat.proto.ProtoConstants.ChatroomMemberUpdateEventType.Chatroom_Member_Event_Join;
import static cn.wildfirechat.proto.ProtoConstants.ChatroomMemberUpdateEventType.Chatroom_Member_Event_Leave; import static cn.wildfirechat.proto.ProtoConstants.ChatroomMemberUpdateEventType.Chatroom_Member_Event_Leave;
@@ -3751,6 +3751,34 @@ public class MemoryMessagesStore implements IMessagesStore {
return mIMap.get(channelId); return mIMap.get(channelId);
} }
@Override
public boolean canSendMessageInChannel(String user, String channelId) {
IMap<String, WFCMessage.ChannelInfo> mIMap = m_Server.getHazelcastInstance().getMap(CHANNELS);
WFCMessage.ChannelInfo info = mIMap.get(channelId);
if(info == null || info.getStatus() == Channel_State_Mask_Deleted) {
return false;
}
if(user.equals(info.getOwner())) {
return true;
}
if((info.getStatus() & Channel_State_Mask_Global) > 0 || (info.getStatus() & Channel_State_Mask_Message_Unsubscribed) > 0) {
return true;
}
Collection<String> channelMembers = getChannelListener(channelId);
if (channelMembers == null) {
return false;
}
Collection<String> chatroomMembers = getChannelListener(channelId);
if (chatroomMembers == null || !chatroomMembers.contains(user)) {
return false;
}
return true;
}
@Override @Override
public boolean checkUserInChannel(String user, String channelId) { public boolean checkUserInChannel(String user, String channelId) {
Collection<String> channelMembers = getChannelListener(channelId); Collection<String> channelMembers = getChannelListener(channelId);
@@ -211,6 +211,7 @@ public interface IMessagesStore {
List<WFCMessage.ChannelInfo> searchChannel(String keyword, boolean buzzy, int page); List<WFCMessage.ChannelInfo> searchChannel(String keyword, boolean buzzy, int page);
ErrorCode listenChannel(String operator, String channelId, boolean listen); ErrorCode listenChannel(String operator, String channelId, boolean listen);
WFCMessage.ChannelInfo getChannelInfo(String channelId); WFCMessage.ChannelInfo getChannelInfo(String channelId);
boolean canSendMessageInChannel(String user, String channelId);
boolean checkUserInChannel(String user, String channelId); boolean checkUserInChannel(String user, String channelId);
Collection<String> getChannelSubscriber(String channelId); Collection<String> getChannelSubscriber(String channelId);