diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SendMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SendMessageAction.java index bd117761..f332b7e8 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SendMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SendMessageAction.java @@ -11,6 +11,7 @@ package com.xiaoleilu.loServer.action.channel; import cn.wildfirechat.common.APIPath; import cn.wildfirechat.pojos.SendChannelMessageData; +import cn.wildfirechat.proto.ProtoConstants; import com.google.gson.Gson; import com.xiaoleilu.loServer.RestResult; import com.xiaoleilu.loServer.annotation.HttpMethod; @@ -42,6 +43,17 @@ public class SendMessageAction extends ChannelAction { public boolean action(Request request) { if (request.getNettyRequest() instanceof FullHttpRequest) { SendChannelMessageData sendChannelMessageData = getRequestBody(request.getNettyRequest(), SendChannelMessageData.class); + if(sendChannelMessageData.getTargets() != null && !sendChannelMessageData.getTargets().isEmpty()) { + if((channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Message_Unsubscribed) == 0 && (channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Global) == 0) { + for (String target:sendChannelMessageData.getTargets()) { + if(!messagesStore.checkUserInChannel(target, channelInfo.getTargetId())) { + setResponseContent(RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_RIGHT, "User " + target + " not in channel")); + return true; + } + } + } + } + SendMessageData sendMessageData = new SendMessageData(); sendMessageData.setConv(new Conversation()); sendMessageData.getConv().setType(ConversationType_Channel); diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index ef4157cf..71fc9d6f 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -178,7 +178,7 @@ public class MemoryMessagesStore implements IMessagesStore { } catch (Exception e) { e.printStackTrace(); Utility.printExecption(LOG, e); - printMissConfigLog(SERVER_MULTI_PLATFROM_NOTIFICATION, mDisableStrangerChat + ""); + printMissConfigLog(SERVER_MULTI_PLATFROM_NOTIFICATION, mMultiPlatformNotification + ""); } try { @@ -519,19 +519,27 @@ public class MemoryMessagesStore implements IMessagesStore { if (channelInfo != null) { notifyReceivers.add(fromUser); if (channelInfo.getOwner().equals(fromUser)) { - Collection listeners = getChannelListener(message.getConversation().getTarget()); - if (!StringUtil.isNullOrEmpty(message.getToUser())) { - if (listeners.contains(message.getToUser())) { - notifyReceivers.add(message.getToUser()); - } - } else if(message.getToList() != null && !message.getToList().isEmpty()) { - for (String to:message.getToList()) { - if (listeners.contains(to)) { - notifyReceivers.add(to); - } + if((channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Global) > 0) { + if((message.getToList() != null && !message.getToList().isEmpty())) { + notifyReceivers.addAll(message.getToList()); + } else { + notifyReceivers.addAll(getAllEnds()); } } else { - notifyReceivers.addAll(listeners); + Collection listeners = getChannelListener(message.getConversation().getTarget()); + if (!StringUtil.isNullOrEmpty(message.getToUser())) { + if (listeners.contains(message.getToUser()) || (channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Message_Unsubscribed) > 0) { + notifyReceivers.add(message.getToUser()); + } + } else if (message.getToList() != null && !message.getToList().isEmpty()) { + for (String to : message.getToList()) { + if (listeners.contains(to) || (channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Message_Unsubscribed) > 0) { + notifyReceivers.add(to); + } + } + } else { + notifyReceivers.addAll(listeners); + } } } else { if (StringUtil.isNullOrEmpty(channelInfo.getCallback()) || channelInfo.getAutomatic() == 0) { @@ -2458,6 +2466,7 @@ public class MemoryMessagesStore implements IMessagesStore { } } + if (mDisableStrangerChat) { //在禁止私聊时,允许机器人,物联网设备及管理员进行私聊。 IMap mUserMap = hzInstance.getMap(USERS); @@ -3406,6 +3415,11 @@ public class MemoryMessagesStore implements IMessagesStore { public ErrorCode listenChannel(String operator, String channelId, boolean listen) { HazelcastInstance hzInstance = m_Server.getHazelcastInstance(); MultiMap listeners = hzInstance.getMultiMap(CHANNEL_LISTENERS); + IMap mIMap = hzInstance.getMap(CHANNELS); + WFCMessage.ChannelInfo channelInfo = mIMap.get(channelId); + if(channelInfo != null && (channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Private) > 0) { + return ErrorCode.ERROR_CODE_NOT_RIGHT; + } getChannelListener(channelId); @@ -3441,12 +3455,12 @@ public class MemoryMessagesStore implements IMessagesStore { @Override public boolean checkUserInChannel(String user, String channelId) { - Collection chatroomMembers = getChannelListener(channelId); - if (chatroomMembers == null) { + Collection channelMembers = getChannelListener(channelId); + if (channelMembers == null) { return false; } - if(!chatroomMembers.contains(user)) { + if(!channelMembers.contains(user)) { IMap mIMap = m_Server.getHazelcastInstance().getMap(CHANNELS); WFCMessage.ChannelInfo info = mIMap.get(channelId); if (info == null || !info.getOwner().equals(user)) { diff --git a/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java b/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java index 14267387..757e57c3 100644 --- a/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java +++ b/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java @@ -121,8 +121,9 @@ public class ProtoConstants { //第1位表示是否允许查看非订阅用户信息 //第2位表示是否允许主动添加用户订阅关系 //第3位表示是否允许给非订阅用户发送消息 - //第4位表示是否私有 + //第4位表示是否私有,不可以被用户搜索和主动订阅 //第6位表示是否删除 + //第8位表示是否是全局频道,全局频道没有订阅关系,会发送给系统内所有成员。 public interface ChannelState { int Channel_State_Mask_FullInfo = 0x01; int Channel_State_Mask_Unsubscribed_User_Access = 0x02; @@ -130,6 +131,7 @@ public class ProtoConstants { int Channel_State_Mask_Message_Unsubscribed = 0x08; int Channel_State_Mask_Private = 0x10; int Channel_State_Mask_Deleted = 0x40; + int Channel_State_Mask_Global = 0x80; }