public RoomChatViewModel GetData(string userName, Guid idUserLogin)
        {
            var user      = _userManager.FindByNameAsync(userName).Result;
            var userLogin = _userManager.FindByIdAsync(idUserLogin.ToString()).Result;
            var query     = _roomChatRepository.FindSingle(x => (x.Code.Contains(idUserLogin.ToString())) && (x.Code.Contains(user.Id.ToString())));
            var result    = Mapper.Map <RoomChat, RoomChatViewModel>(query);

            //
            if (result == null)
            {
                string   code = user.Id.ToString() + userLogin.Id.ToString();
                RoomChat room = new RoomChat();
                room.Paticipants.Add(new AppUserChat(user.Id, room.Id));
                room.Paticipants.Add(new AppUserChat(idUserLogin, room.Id));
                room.Code = code;
                _roomChatRepository.Add(room);
                _unitOfWork.Commit();
                result = Mapper.Map <RoomChat, RoomChatViewModel>(room);
            }
            var listMess = _messageRepository.FindAll(x => x.RomChat_Id == result.Id).ProjectTo <MessageViewModel>().ToList();

            foreach (var item in listMess)
            {
                result.Messages.Add(item);
            }

            if (result.Messages.Count() == 0)
            {
                result.Messages.Add(new MessageViewModel(user.FullName, query.Id, user.Id, "text", "Gui loi chao di"));
            }
            return(result);
        }
Пример #2
0
 //CallBack->房间连接断开触发
 private void RoomChat_OnClosed(RoomChat sender)
 {
     this.RoomWebsok = null;
     if (RoomSokDisconnect != null)
     {
         RoomSokDisconnect(this);
     }
 }
Пример #3
0
 public override void Init()
 {
     base.Init();
     this.mgs = new object[]
     {
         ClientV2C.chatviewInitRoom,
         ClientV2C.chatviewOpenEmotion,
         ClientV2C.chatviewCloseEmotion,
         ClientC2V.ReceiveHallChatMessage,
         ClientC2C.WaitServerResponseTimeOut
     };
     this.Anchor                         = this.transform.Find("Anchor");
     this.hallToggle                     = this.Anchor.Find("Panel/Lounge").GetComponent <UIToggle>();
     this.friendToggle                   = this.Anchor.Find("Panel/Friend").GetComponent <UIToggle>();
     this.lobbyToggle                    = this.Anchor.Find("Panel/Room").GetComponent <UIToggle>();
     this.hallLabel                      = this.hallToggle.transform.Find("Label").GetComponent <UILabel>();
     this.friendLabel                    = this.friendToggle.transform.Find("Label").GetComponent <UILabel>();
     this.lobbyLabel                     = this.lobbyToggle.transform.Find("Label").GetComponent <UILabel>();
     this.BG                             = this.Anchor.Find("BG");
     this.emojiBG                        = this.Anchor.Find("Panel/EmojiBG");
     this.CloseBtn                       = this.Anchor.Find("BG/CloseBtn");
     this.FriendLst                      = this.Anchor.Find("FriendChat/FriendLst");
     this.FriendChat                     = this.Anchor.Find("FriendChat/Chat");
     this._friendChat                    = this.Anchor.GetComponent <FriendChat>();
     this.emojiList                      = this.Anchor.Find("EmojiLst");
     this.emoGrid                        = this.emojiList.Find("Scroll View/Grid").GetComponent <UIGrid>();
     this.friendNewsPoint                = this.Anchor.Find("Panel/Friend/Point");
     this._roomChat                      = this.Anchor.GetComponent <RoomChat>();
     this.playerInfoController           = this.Anchor.GetComponent <ChatPlayerInfoController>();
     this.tween_position                 = this.transform.GetComponent <TweenPosition>();
     this.markPoint                      = this.Anchor.Find("Panel/Lounge/Mark");
     this.hallEmojiField                 = this.Anchor.Find("HallChat/LoudSpeaker/InputField").GetComponent <UIInput>();
     this.friendEmojiField               = this.Anchor.Find("FriendChat/Chat/InputField").GetComponent <UIInput>();
     this.lobbyEmojiField                = this.Anchor.Find("RoomChat/Chat/InputField").GetComponent <UIInput>();
     this.emojiItem                      = Resources.Load <EmojiItem>("Prefab/UI/HomeChat/emojiItem");
     this.dsv                            = this.Anchor.Find("BG").GetComponent <UIDragScrollView>();
     this.hallScrollView                 = this.Anchor.Find("HallChat/MessageBox").GetComponent <UIScrollView>();
     this.friendScrollView               = this.Anchor.Find("FriendChat/Chat/MessageBox").GetComponent <UIScrollView>();
     this.roomScrollView                 = this.Anchor.Find("RoomChat/MessageBox").GetComponent <UIScrollView>();
     this.dicToggle[ChitchatType.Hall]   = this.hallToggle;
     this.dicToggle[ChitchatType.Friend] = this.friendToggle;
     this.dicToggle[ChitchatType.Lobby]  = this.lobbyToggle;
     EventDelegate.Add(this.hallToggle.onChange, new EventDelegate.Callback(this.ChangeToggle));
     EventDelegate.Add(this.friendToggle.onChange, new EventDelegate.Callback(this.ChangeToggle));
     EventDelegate.Add(this.lobbyToggle.onChange, new EventDelegate.Callback(this.ChangeToggle));
     UIEventListener.Get(this.CloseBtn.gameObject).onClick = new UIEventListener.VoidDelegate(this.CloseChatView);
     this.userID    = long.Parse(ModelManager.Instance.Get_userData_X().UserId);
     this.coroutine = new CoroutineManager();
 }
Пример #4
0
        public object AddChatRoom(string roomName)
        {
            int roomCount = context.RoomChats.Where(cr => cr.RoomName == roomName).Count();

            if (roomCount > 0)
            {
                return("Room already exists.");
            }
            else
            {
                RoomChat chatRoom = new RoomChat(roomName, DateTime.Now);
                context.RoomChats.Add(chatRoom);
                context.SaveChanges();
                var chatRooms = context.RoomChats.Select(cr => new { cr.RoomName, cr.RoomCreationDate }).ToArray();
                return(chatRooms);
            }
        }
Пример #5
0
 /// <summary>
 /// 设置游戏连接对象
 /// </summary>
 /// <param name="chat"></param>
 public void SetRoomWebSok(RoomChat chat)
 {
     this.RoomWebsok    = chat;
     chat.OnDisconnetc += RoomChat_OnClosed;
     chat.OnGameData   += (s, e) => { if (this.OnGameData != null)
                                      {
                                          this.OnGameData(this, e);
                                      }
     };
     if (chat.IsConnect)
     {
         if (this.RoomSokConnect != null)
         {
             this.RoomSokConnect(this);
         }
     }
 }
Пример #6
0
        public async void ChatCreateSuccessfully(int roomid)
        {
            //Arrange
            var chat = new RoomChat()
            {
                Id      = 1,
                RoomId  = roomid,
                UserId  = "testUser",
                Date    = DateTime.Now,
                Content = "testChat",
                Type    = 1,
            };
            // Act
            var result = await RoomChatDAO.Create(roomContext, chat);

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);
        }
Пример #7
0
 public static async Task <IActionResult> Create(RoomDBContext context, RoomChat roomChat)
 {
     try
     {
         context.RoomChat.Add(roomChat);
         context.SaveChanges();
         return(new ObjectResult(new { message = "Add success!" })
         {
             StatusCode = 200,
         });
     }
     catch (Exception e)
     {
         return(new ObjectResult(new { message = e.Message })
         {
             StatusCode = 500,
         });
     }
 }
Пример #8
0
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool Check(GameObject target)
        {
            return(RoomChat.IsOpen() == isOpen);
        }
Пример #9
0
        public static async Task <IActionResult> CreateRoomChat(RoomDBContext context, HttpRequest request, IWebHostEnvironment env)
        {
            var type   = (ChatType)Convert.ToInt32(request.Form["chatType"]);
            var roomId = Convert.ToInt32(request.Form["roomId"]);

            switch (type)
            {
            case ChatType.Text:
            {
                var roomChat = new RoomChat
                {
                    RoomId  = roomId,
                    UserId  = request.Form["userId"],
                    Content = request.Form["content"],
                    Date    = DateTime.Now,
                    Type    = (int)ChatType.Text
                };
                return(await RoomChatDAO.Create(context, roomChat));
            }

            case ChatType.Image:
            {
                var img       = request.Form.Files[0];
                var extension = Path.GetExtension(img.FileName);

                var imgName = Convert.ToBase64String(
                    System.Text.Encoding.UTF8.GetBytes(DateTime.Now.ToString())
                    );
                var path = Path.Combine(env.ContentRootPath, $"Files/{roomId}/Chat/Images");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                var imgPath = Path.Combine(path, imgName + extension);
                if (img.Length > 0)
                {
                    using var fileStream = new FileStream(imgPath, FileMode.Create);
                    img.CopyTo(fileStream);
                }
                var roomChat = new RoomChat
                {
                    RoomId   = roomId,
                    UserId   = request.Form["userId"],
                    Content  = $"api/rooms/chat/getFile?fileName={imgName + extension}&roomId={roomId}&type={(int)ChatType.Image}&realName={Path.GetFileName(img.FileName)}",
                    Date     = DateTime.Now,
                    Type     = (int)ChatType.Image,
                    FileName = Path.GetFileName(img.FileName)
                };
                return(await RoomChatDAO.Create(context, roomChat));
            }

            case ChatType.File:
            {
                var file      = request.Form.Files[0];
                var extension = Path.GetExtension(file.FileName);
                var fileName  = Convert.ToBase64String(
                    System.Text.Encoding.UTF8.GetBytes(DateTime.Now.ToString())
                    );
                var path = Path.Combine(env.ContentRootPath, $"Files/{roomId}/Chat/Files");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                var filePath = Path.Combine(path, fileName + extension);
                if (file.Length > 0)
                {
                    using var fileStream = new FileStream(filePath, FileMode.Create);
                    file.CopyTo(fileStream);
                }
                var roomChat = new RoomChat
                {
                    RoomId   = roomId,
                    UserId   = request.Form["userId"],
                    Content  = $"api/rooms/chat/getFile?fileName={fileName + extension}&roomId={roomId}&type={(int)ChatType.File}&realName={Path.GetFileName(file.FileName)}",
                    Date     = DateTime.Now,
                    Type     = (int)ChatType.File,
                    FileName = Path.GetFileName(file.FileName)
                };
                return(await RoomChatDAO.Create(context, roomChat));
            }

            default:
                return(new ObjectResult(new { message = "wrong chat type" })
                {
                    StatusCode = 500,
                });
            }
        }
Пример #10
0
 //Save room/ chat between pepole
 public async Task SaveRoom(RoomChat _roomName)
 {
     await _firebaseClient
     .Child("ChatApp")
     .PostAsync(_roomName);
 }