Beispiel #1
0
        protected override void Handle(FetchChannelsRequestPacket packet, Socket sender)
        {
            var data = packet.Data;

            if (data == null)
            {
                return;
            }

            // check whether request is valid
            ActiveUser activeUser = ActiveUsers.GetUser(sender);

            if (activeUser == null)
            {
                SendError(HttpStatusCode.Unauthorized, sender);
                return;
            }

            User user = userCrud.ReadOneById(activeUser.userId);

            // fetch channels that match search
            List <BaseChannelData> channels = channelCrud.ReadManyBase(x =>
                                                                       x.members.Contains(user._id) &&
                                                                       x.name.ToLower().Contains(data.search.ToLower())
                                                                       );

            var response = new FetchChannelsResponsePacket(new FetchChannelsResponsePacketData(
                                                               (int)HttpStatusCode.OK,
                                                               channels
                                                               ));

            Zephy.serverSocket.SendPacket(response, sender);
        }
Beispiel #2
0
        private void SendError(HttpStatusCode code, Socket socket)
        {
            var errResponse = new FetchChannelsResponsePacket(new FetchChannelsResponsePacketData(
                                                                  (int)code,
                                                                  null
                                                                  ));

            Zephy.serverSocket.SendPacket(errResponse, socket);
        }