示例#1
0
        /// <summary>
        /// Persists a given message to the database and its corresponding notification
        /// </summary>
        /// <param name="actualRequest">the client request to be handled</param>
        /// <returns>the response to the given request</returns>
        private async Task <ActualRequest> AddMessageAsync(ActualRequest actualRequest)
        {
            Request             request = actualRequest.Request;
            MessageSocketsModel message = JsonSerializer.Deserialize <MessageSocketsModel>(request.Argument.ToString());
            List <int>          ints    = await chatRepo.AddMessageAsync(message);

            int     messageId       = ints[0];
            Request requestResponse = new Request
            {
                ActionType = ActionType.MESSAGE_CREATE.ToString(),
                Argument   = JsonSerializer.Serialize(ints)
            };

            if (messageId > 0)
            {
                if (message.HasImage && actualRequest.Images != null)
                {
                    try {
                        ImagesUtil.WriteImageToPath(actualRequest.Images[0], $"{FILE_PATH}/Messages", $"/{messageId}.jpg");
                    }
                    catch (Exception e) {
                        Console.WriteLine("Could not add image to created message " + messageId);
                    }
                }
            }

            return(new ActualRequest
            {
                Request = requestResponse,
                Images = null
            });
        }