Exemplo n.º 1
0
        public async Task <Models.Chat> Update(Models.Chat chat)
        {
            _context.Entry(chat).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(chat);
        }
Exemplo n.º 2
0
 public async Task AddUser(Models.Chat chat)
 {
     using (var db = new DbNorthwind())
     {
         await db.InsertWithInt32IdentityAsync(chat);
     }
 }
Exemplo n.º 3
0
 public ChatWindow(Models.Chat chat)
 {
     InitializeComponent();
     chatWindowVM     = new ChatWindowVM(chat);
     this.DataContext = chatWindowVM;
     this.chat        = chat;
 }
Exemplo n.º 4
0
        public ChatResponse Create(Guid groupId, string username)
        {
            var chat = new Models.Chat
            {
                Id      = Guid.NewGuid(),
                GroupId = groupId
            };

            var chatUserAuthorized = new ChatUser(_authorizedUser, chat);

            _chatUserRepository.Add(chatUserAuthorized);

            var user     = _userRepository.GetUserByUsername(username);
            var chatUser = new ChatUser(user, chat);

            _chatUserRepository.Add(chatUser);

            var chatUserAuthorizedDocument = new Documents.ChatUser(_authorizedUser.Id, chat.Id);
            var chatUserDocument           = new Documents.ChatUser(user.Id, chat.Id);

            _chatUserStore.AddToBus(chatUserAuthorizedDocument);
            _chatUserStore.AddToBus(chatUserDocument);

            var group = _groupRepository.Get(groupId);

            _chatEventService.AddChatCreatedEvent(group, _authorizedUser, chat);
            _chatEventService.AddUserAddedToChatEvent(group, _authorizedUser, _authorizedUser, chat);
            _chatEventService.AddUserAddedToChatEvent(group, _authorizedUser, user, chat);

            return(_mapper.Map <ChatResponse>(chat));
        }
Exemplo n.º 5
0
        public HttpResponseMessage GetChats([FromUri] long me, [FromUri] long you)
        {
            var result = new Models.Chat().GetChats(me, you);

            new Models.Chat().MarkAsRead(me, you);
            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handle event when user clicks 'Send' button
        /// Send the message to other user
        /// </summary>
        protected void btnSend_Click(object sender, EventArgs e)
        {
            user         = (User)Session["user"];
            receiverUser = (User)Session["receiverUser"];

            string content = txtMessage.InnerText;

            Models.Chat chat = new Models.Chat(user.Id, receiverUser.Id);

            if (ChatADO.FindChat(user.Id, receiverUser.Id) == null)
            {
                if (ChatADO.InsertChat(chat))
                {
                    chat = ChatADO.FindChat(user.Id, receiverUser.Id);
                }
            }
            else
            {
                chat = ChatADO.FindChat(user.Id, receiverUser.Id);
            }

            Message message = new Message(chat.Id, user.Id, receiverUser.Id, content);

            if (MessageADO.InsertMessage(message))
            {
                LoadPage();
                lbtnUserName.Text    = receiverUser.UserName;
                txtMessage.InnerText = "";
            }
            else
            {
                lblMessage.Text = "Cannot sent message. Try again!";
            }
        }
Exemplo n.º 7
0
        public ActionResult Dialog(string userId)
        {
            string currentUserId = User.Identity.GetUserId();
            var    ser           = userManager.Users.Where(m => m.Id == userId).FirstOrDefault();

            if (userId != null)
            {
                var currentChat = messageContext.Chats.Where(m => (m.UserFirstId == userId && m.UserSecondId == currentUserId) || (m.UserFirstId == currentUserId && m.UserSecondId == userId)).FirstOrDefault();
                if (currentChat == null)
                {
                    Models.Chat chat = new Models.Chat {
                        UserFirstId = currentUserId, UserSecondId = userId
                    };
                    currentChat = chat;
                    messageContext.Chats.Add(currentChat);
                    messageContext.SaveChanges();
                    dbContext.SaveChanges();
                }
                currentChat = messageContext.Chats.Where(m => (m.UserFirstId == userId && m.UserSecondId == currentUserId) || (m.UserFirstId == currentUserId && m.UserSecondId == userId)).FirstOrDefault();
                var messages = messageContext.Messages.Where(m => (m.UserSenderId == currentUserId && m.UserToSendId == userId) || (m.UserToSendId == currentUserId && m.UserSenderId == userId)).ToList();
                ViewData["senderId"]      = currentUserId;
                ViewData["recipientId"]   = userId;
                ViewData["recipientName"] = ser.UserName;

                return(View(messages));
            }



            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Load the chat
        /// </summary>
        protected void LoadPage()
        {
            user         = (User)Session["user"];
            receiverUser = (User)Session["receiverUser"];

            if (receiverUser.ProfilePicture == null)
            {
                receiverAva = "/Content/Images/default.jpg";
            }
            else
            {
                receiverAva = "data:image/jpg;base64," + Convert.ToBase64String(receiverUser.ProfilePicture);
            }

            user = (User)Session["user"];
            if (user.ProfilePicture == null)
            {
                userAva = "/Content/Images/default.jpg";
            }
            else
            {
                userAva = "data:image/jpg;base64," + Convert.ToBase64String(user.ProfilePicture);
            }

            List <Message> messages = new List <Message>();

            if (user.FindChat(user.Id, receiverUser.Id) != null)
            {
                Models.Chat chat = user.FindChat(user.Id, receiverUser.Id);
                messages = chat.Messages;
            }
            dtMesssages.DataSource = messages;
            dtMesssages.DataBind();
        }
Exemplo n.º 9
0
        public Chat(Models.Chat chat, string userAddress, bool includeUsers = true)
        {
            Id   = chat.Id;
            Type = chat.GetType();

            MessageCount = chat.Messages.Count;

            if (Type == Constants.Chat.Type.Normal)
            {
                var chatPartner = chat.GetPartner(userAddress);
                if (chatPartner != null)
                {
                    ChatUser = new Models.View.ChatUser(chatPartner);
                }
            }
            else if (Type == Constants.Chat.Type.Group)
            {
                if (chat.Setting != null)
                {
                    ChatSetting = new Models.View.ChatSetting(chat.Setting, userAddress, chat.Users, includeUsers);
                }
            }

            if (chat.Messages.Count > 0)
            {
                ChatMessage = new Models.View.ChatMessage(chat.Messages.OrderBy(m => m.InternalId).Last());
            }
        }
Exemplo n.º 10
0
        public ResponseModel <Models.Chat> sendMessage([FromBody] SendMessageRequestModel chat)
        {
            try
            {
                var newMessage = new Models.Chat
                {
                    message    = chat.message,
                    receiverId = chat.receiverId,
                    senderId   = chat.senderId,
                    timeSent   = DateTimeOffset.Now
                };

                dbcontext.chats.Add(newMessage);
                dbcontext.SaveChanges();

                return(new ResponseModel <Models.Chat>
                {
                    data = newMessage,
                    message = "message sent ",
                    status = true
                });
            }
            catch (Exception ex)
            {
                return(new ResponseModel <Models.Chat>
                {
                    data = null,
                    message = "unable send " + ex.Message,
                    status = true
                });
            }
        }
Exemplo n.º 11
0
        public void AddUserToGroup(Models.Chat chat, Models.ChatUser chatUser)
        {
            if (!chat.IsGroup || chat.Setting == null)
            {
                return;
            }

            var chatUserData = new Models.View.ChatUser(chatUser);

            chatUser.User?.DeviceIds?.ForEach(deviceId =>
            {
                SendMessage(
                    deviceId.DeviceId,
                    chat.Id.ToString(),
                    chat.Setting.Name,
                    "user_added",
                    chatUserData,
                    true,
                    MessagePriority.high
                    ).ConfigureAwait(false);
            });

            SendMessage(
                "/topics/group_" + chat.Setting.Address,
                chat.Id.ToString(),
                chat.Setting.Name,
                "user_added",
                chatUserData,
                true,
                MessagePriority.high
                ).ConfigureAwait(false);
        }
Exemplo n.º 12
0
 public static ChatReturnModel MakeReturnChat(Models.Chat dbMessage)
 {
     return(new ChatReturnModel
     {
         message = dbMessage.message,
         timeSent = dbMessage.timeSent
     });
 }
Exemplo n.º 13
0
        public void AddChatRemovedEvent(Models.Group @group, Models.User authorUser, Models.Chat chat)
        {
            var @event = new Event(EventType.ChatRemoved, authorUser, group);

            @event.AttachChat(chat);

            _eventStore.AddToBus(@event);
        }
Exemplo n.º 14
0
        public async Task <Models.Chat> Create(Models.Chat chat)
        {
            var createdChat = await _context.Chats.AddAsync(chat);

            await _context.SaveChangesAsync();

            return(createdChat.Entity);
        }
Exemplo n.º 15
0
 public Chat(List <Lobby> lobbies, ILoggerServer logger, Api api)
 {
     _chat          = new Models.Chat();
     _chat.Messages = new List <ChatMessage>();
     _logger        = logger;
     _api           = api;
     _lobbies       = lobbies;
 }
Exemplo n.º 16
0
 internal static void SavePending(Models.Chat new_send)
 {
     try
     {
         Local.Chat.Insert(new_send);
     }
     catch (System.Exception ex)
     {
         Crashes.TrackError(ex, Logic.GetErrorProperties(ex));
     }
 }
Exemplo n.º 17
0
        private void RemoveAllChatUsers(Models.Chat chat, Models.Group group)
        {
            var chatUsers = _chatUserRepository.GetAllByChatId(chat.Id);

            _chatUserRepository.RemoveAllByChatId(chat.Id);
            _chatUserStore.RemoveAllByChatId(chat.Id);

            foreach (var chatUser in chatUsers)
            {
                _chatEventService.AddUserRemovedFromChatEvent(group, _authorizedUser, chatUser.User, chat);
            }
        }
Exemplo n.º 18
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         Models.Chat chat = chats.Where(c => c.Id == id).FirstOrDefault();
         chats.Remove(chat);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 19
0
        public void GroupCreated(List <Models.UserDeviceId> deviceIds, Models.Chat chat)
        {
            var chatView = new Models.View.Chat(chat, null);

            deviceIds.ForEach(deviceId => SendMessage(
                                  deviceId.DeviceId,
                                  chat.Id.ToString(),
                                  chat.Setting.Name,
                                  "group_created",
                                  chatView,
                                  true,
                                  MessagePriority.high
                                  ).ConfigureAwait(false));
        }
Exemplo n.º 20
0
        public void Send(string name, string msg)
        {
            DateTime Time    = DateTime.Now;
            string   Name    = name;
            string   Message = msg;

            Clients.All.message(Time, Name, Message, Context.ConnectionId);
            Chat c = new Models.Chat();

            c.Time    = Time;
            c.Name    = Name;
            c.Message = Message;
            db.Chats.Add(c);
            db.SaveChanges();
        }
Exemplo n.º 21
0
        public void Create(Models.Chat model)
        {
            if (model == null)
            {
                return;
            }

            var dbMessage = context.mdl_chat.Create();

            dbMessage.receiver_id   = model.Reciever.Id;
            dbMessage.sender_id     = model.Sender.Id;
            dbMessage.message       = model.Message;
            dbMessage.creation_date = DateTime.UtcNow;

            context.mdl_chat.Add(dbMessage);
            context.SaveChanges();
        }
Exemplo n.º 22
0
        private void EnsureChat(Message message)
        {
            _chat = _dbContext.Chats.FirstOrDefault(x => x.Id == message.Chat.Id);
            if (_chat != null)
            {
                return;
            }

            _chat = new Models.Chat()
            {
                Id              = message.Chat.Id,
                Title           = message.Chat.Title,
                AllMembersAdmin = message.Chat.AllMembersAreAdministrators,
                ChatType        = message.Chat.Type
            };
            _dbContext.Chats.Add(_chat);
        }
Exemplo n.º 23
0
        public void NotifyGroupMessage(Models.Chat chat, Models.ChatMessage chatMessage)
        {
            if (!chat.IsGroup || chat.Setting == null)
            {
                return;
            }

            SendMessage(
                "/topics/group_" + chat.Setting.Address,
                chat.Id.ToString(),
                chat.Setting.Name,
                "grp_msg",
                new Models.View.ChatMessage(chatMessage),
                false,
                MessagePriority.high
                ).ConfigureAwait(false);
        }
Exemplo n.º 24
0
        public void UpdateGroupAddress(Models.Chat chat)
        {
            if (!chat.IsGroup || chat.Setting == null)
            {
                return;
            }

            SendMessage(
                "/topics/group_" + chat.Setting.Address,
                chat.Id.ToString(),
                chat.Setting.Name,
                "update_info",
                new Models.View.ChatSetting(chat.Setting),
                true,
                MessagePriority.high
                ).ConfigureAwait(false);
        }
Exemplo n.º 25
0
        public void SetUserGroupRank(Models.Chat chat, Models.ChatUser chatUser)
        {
            if (!chat.IsGroup || chat.Setting == null)
            {
                return;
            }

            SendMessage(
                "/topics/group_" + chat.Setting.Address,
                chat.Id.ToString(),
                chat.Setting.Name,
                "user_rank",
                new Models.View.ChatUser(chatUser),
                true,
                MessagePriority.high
                ).ConfigureAwait(false);
        }
        private void ChatItemsControlMouseDoubleClicked(object listViewService, MouseButtonEventArgs mouseButtonEventArgs)
        {
            int itemSelect = ((ListView)listViewService).SelectedIndex;

            if (itemSelect >= Number.NumberValue(NumberValues.ZERO) && itemSelect < chats.Count)
            {
                Models.Chat chatSelect = chats[itemSelect];
                if (chatSelect != null)
                {
                    Chat chat = new Chat();
                    chat.ChatSelect = chatSelect;
                    chat.InitializeMenu();
                    chat.Show();
                    Close();
                }
            }
        }
Exemplo n.º 27
0
        public async Task <IActionResult> CreateRoomPrivate(string userId)
        {
            var chat = new Models.Chat
            {
                Type = ChatType.Private,
            };

            chat.Users.Add(new ChatUser {
                UserId = userId
            });
            chat.Users.Add(new ChatUser {
                UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value
            });

            _ctx.Chats.Add(chat);
            await _ctx.SaveChangesAsync();

            return(RedirectToAction("Chat", new { id = chat.Id }));
        }
Exemplo n.º 28
0
        public HttpResponseMessage Send([FromBody] Models.Chat chat)
        {
            if (chat != null)
            {
                chat.Save_Completed += (sender, e) =>
                {
                    IHubContext hubcontext = GlobalHost.ConnectionManager.GetHubContext <WebApplication2.Hubs.ChatHub>();

                    foreach (var con in Hubs.Connections.GetConnections(chat.ToId))
                    {
                        hubcontext.Clients.Client(con).newMessage(sender.FromId, sender.Message, sender.From.ProfileImagePath, sender.RelativeTime);
                    }
                };
                return(Request.CreateResponse(HttpStatusCode.OK, chat.Send()));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad Request"));
            }
        }
Exemplo n.º 29
0
        public async Task <IActionResult> CreateRoom(string name)

        {
            var chat = new Models.Chat
            {
                Name = name,
                Type = ChatType.Room
            };

            chat.Users.Add(new ChatUser
            {
                Role   = UserRole.Admin,
                UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value
            });

            _ctx.Chats.Add(chat);

            await _ctx.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 30
0
        protected Message GetLastMessage(int chatId)
        {
            User user = (User)Session["user"];

            Models.Chat chat        = null;
            Message     lastMessage = null;

            foreach (Models.Chat ch in user.Chats)
            {
                if (chatId == ch.Id)
                {
                    chat = ch;
                    break;
                }
            }

            if (chat != null)
            {
                lastMessage = chat.Messages[chat.Messages.Count - 1];
            }

            return(lastMessage);
        }