Exemple #1
0
        public Chat GetOrCreateChatWithUser(User sender, User receiver, Include <Chat> include = null)
        {
            var chat = ChatProvider.All(include)
                       .Include(c => c.UserChats)
                       .ThenInclude(uc => uc.User)
                       .FirstOrDefault(c => c.UserChats.Select(uc => uc.User.UserId).Contains(receiver.UserId));

            if (chat == null)
            {
                chat = new Chat {
                    Type = ChatType.Personal
                };
                ChatProvider.Add(chat);
                AddUserToChat(sender, chat);
                AddUserToChat(receiver, chat);
            }

            return(chat);
        }