/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="id"></param> /// <param name="checkAccess">if null - do nothing, if false - check if has invite, if true - check if subscribed</param> public void DropChannel(User user, string id, CheckAccessRule checkAccess = CheckAccessRule.None) { var channel = LookupChannel(user, id, checkAccess: checkAccess); if (channel != null) { DropChannel(user, channel); } }
/// <summary> /// Be careful. Check access checking admin-like permissions (means if allow to invite, close and so on), but /// not if you allow to send to channel (it should be checked separately), for example Private allows to recieve /// messages from ANY user on site (Not only subscribers). /// </summary> /// <param name="user"></param> /// <param name="id"></param> /// <param name="type"></param> /// <param name="checkAccess">if None - do not check any permission, /// Otwerwise depends from type (Global - always has access, Room - if in room, Private - only for self private). For Custom: /// if HasInviteOrInWhiteListAndNotInBlackList - check if has invite (or in whiteList) and not in blackList - exception on error, /// if IsSubscribed - check if subscribed and return null if not</param> /// <returns></returns> public ChatChannel LookupChannel(User user, string id = null, ChatChannelType?type = null, CheckAccessRule checkAccess = CheckAccessRule.None) { var channel = Channels.FirstOrDefault(m => (id == null || m.Id == id) && (type == null || type == m.Type)); if (channel != null && checkAccess != CheckAccessRule.None) { if (channel.Type == ChatChannelType.Global) { return(channel); } if (channel.Type == ChatChannelType.Private) { return(user.Id == id ? channel : null); } if (channel.Type == ChatChannelType.Room) { return((user.GameRoomRef == null || user.GameRoomRef.Id != id) ? null : channel); } if (checkAccess == CheckAccessRule.HasInviteOrInWhiteListAndNotInBlackList) { channel.CheckPermissions(user.Id); } else { if (!channel.Subscribers.ContainsKey(user.Id)) { return(null); } } } return(channel); }