public void Operation(MainRequest chatData) { var data = chatData as PrivateChatMessageModel; ChatModule newChat = new PrivateChat(); newChat.AddClient(_userClient); List <IClientModel> clients = new List <IClientModel>(); clients.Add(_userClient); foreach (var clientName in data.lsUsers) { if (_allChatDetails.IsClientExist(clientName)) { IClientModel client = _allChatDetails.GetClientByName(clientName); clients.Add(client); newChat.AddClient(client); } } if (!_allChatDetails.IsExistChatWithSamePeaple(clients, ChatType.Private)) { _allChatDetails.AddChat(newChat); } }
private async Task ValidatePrivateChatAsync(CreatePrivateChatDto chatDto, CancellationToken ct) { User user = await _unitOfWork.UserRepository.GetAsync(chatDto.ContactId, ct); if (user == null) { _logger.LogWarning("User {UserId} not found", chatDto.ContactId); throw new UserNotFoundException(); } PrivateChat dbChat = await _unitOfWork.PrivateChatRepository.GetChatByUserIdAsync(chatDto.UserId, chatDto.ContactId, ct); if (dbChat != null) { _logger.LogWarning( "User {UserId} already has private chat with Contact {ContactId}", chatDto.UserId, chatDto.ContactId); throw new PrivateChatAlreadyExistException(); } }
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { //int index1 = linkLabel1.Tag.ToString().IndexOf(":"); this.Invoke(new DoSomething(delegate() { PrivateChat f = null; if (cfList.Count != 0) { foreach (ChatForm cf in cfList) { if ((cf._ip == this.ip) && (cf._port == this.port)) { f = cf._cform; if (cf._cform.WindowState == FormWindowState.Minimized) { cf._cform.WindowState = FormWindowState.Normal; //如果私聊窗体的当前状态是最小化,则将其调整到正常状态 cf._cform.BringToFront(); //将相应的私聊窗体置顶显示(前提是窗体不能处于最小化状态) } } } if (f == null) { f = new PrivateChat(this.ip, this.port, (MainForm)this.pf); f.Show(); } } else { f = new PrivateChat(this.ip, this.port, (MainForm)this.pf); f.Show(); } cfList = null; this.Close();//关闭消息提示 })); }
public async Task <IActionResult> PrivateChat(int user1Id, int user2Id) { var users = new List <int> { user1Id, user2Id }; var privChat = await _context.PrivateChats .Include(x => x.User1) .Include(x => x.User2) .Include(x => x.Chat) .FirstOrDefaultAsync(x => users.Contains(x.User1.Id) && users.Contains(x.User2.Id)); if (privChat is null) { var chat = new Chat() { ChatName = (await _context.Users.FindAsync(user1Id)).NickName + "-" + (await _context.Users.FindAsync(user2Id)).NickName }; privChat = new PrivateChat() { Chat = chat, User1 = await _context.Users.FindAsync(user1Id), User2 = await _context.Users.FindAsync(user2Id) }; await _context.Chats.AddAsync(chat); await _context.PrivateChats.AddAsync(privChat); await _context.SaveChangesAsync(); } return(RedirectToAction("Chat", "Chat", new { chatId = privChat.Chat.Id })); }
public void printPrivateConversation(object privateConversation) { PrivateChat messageReceived = (PrivateChat)privateConversation; Console.WriteLine("\t\t*** Last conversation ***"); messageReceived.printTheConversations(); //Search for the client of PV Chat while (true) { Message msg = Net.receiveMessage(comm.GetStream()); if (msg.GetType().Name.Equals("MessagePrivate")) { MessagePrivate mp = (MessagePrivate)msg; if (mp.PvChat.UsersChat[0].Id_user == messageReceived.UsersChat[0].Id_user || mp.PvChat.UsersChat[0].Id_user == messageReceived.UsersChat[1].Id_user) { if (mp.PvChat.UsersChat[1].Id_user == messageReceived.UsersChat[0].Id_user || mp.PvChat.UsersChat[1].Id_user == messageReceived.UsersChat[1].Id_user) { Console.WriteLine("------------------------------------------------------"); mp.PvChat.printTheConversations(); Console.WriteLine("Send a message : "); } } } else if (msg.GetType().Name.Equals("MessageNavigation")) { break; } } }
public override void Execute(object parameter) { PrivateChat privateChat = null; if (parameter is ItemClickEventArgs) { privateChat = ((ItemClickEventArgs)parameter).ClickedItem as PrivateChat; } if (privateChat == null) { return; } Loc.PrivateChat.CurrentPrivateChat = privateChat; if (!Loc.Main.Threads.Any()) { Loc.Main.Threads.Add(privateChat); } else { Loc.Main.Threads[0] = privateChat; } Loc.Thread.SelectedThread = 0; Task.Run(async() => await ThreadFetcher.GetPosts(Loc.Thread.CurrentThread)); if (Loc.NavigationService.CurrentView != View.Main) { Loc.NavigationService.Navigate(View.Main); } }
public void displayUserChat(object newPrivateChat) { PrivateChat messageReceived = (PrivateChat)newPrivateChat; messageReceived.printTheConversations(); while (true) { MessagePrivate clientMessage = (MessagePrivate)Net.receiveMessage(comm.GetStream()); Conversation conv = new Conversation(clientMessage.Message, clientMessage.UserSender); messageReceived.Conversation.Add(conv); messageReceived.Number_messages += 1; //Add the client associated with tcpClient foreach (KeyValuePair <User, List <TcpClient> > myClients in userTcps) { foreach (User u in messageReceived.UsersChat) { if (myClients.Key.Login.Equals(u.Login)) { foreach (TcpClient tcp in myClients.Value) { Net.sendMessage(tcp.GetStream(), new MessagePrivate(messageReceived)); Console.WriteLine("\n *** Sending to " + tcp.Client.RemoteEndPoint + " ***"); Console.WriteLine("Message received : " + clientMessage.Message + "\nfrom : " + clientMessage.UserSender.Login); } } } } } }
//To make a PrivateChat //Assuming No chat between User1 and User2 Exist private async Task <PrivateChat> MakePrivateChat(ApplicationUser User1, ApplicationUser User2) { PrivateChat Chat = new PrivateChat { Key = Guid.NewGuid().ToString() }; ChatMap temp = new ChatMap { Key = Guid.NewGuid().ToString(), UserId = User1.Id, UserId_2 = User2.Id, ChatId = Chat.Key }; ChatMap temp2 = new ChatMap { Key = Guid.NewGuid().ToString(), UserId = User2.Id, UserId_2 = User1.Id, ChatId = Chat.Key }; try{ await Context.Chats.AddAsync(Chat); await Context.ChatMaps.AddAsync(temp); await Context.ChatMaps.AddAsync(temp2); await Context.SaveChangesAsync(); return(Chat); } catch (Exception e) { Console.WriteLine(e.Message); // change it to log later return(null); } }
//右键菜单 私聊 private void PrivateChatToolStripMenuItem_Click(object sender, EventArgs e) { PrivateChat f = null; string ipRecv = this.listView1.SelectedItems[0].SubItems[2].Text; int portRecv = Convert.ToInt32(this.listView1.SelectedItems[0].SubItems[3].Text); this.Invoke(new Action(() => { if (this.chatFormList.Count != 0) { foreach (ChatForm cf in chatFormList) { if ((cf._ip == ipRecv) && (cf._port == portRecv)) { f = cf._cform; if (cf._cform.WindowState == FormWindowState.Minimized) { cf._cform.WindowState = FormWindowState.Normal; //如果私聊窗体的当前状态是最小化,则将其调整到正常状态 cf._cform.BringToFront(); //将相应的私聊窗体置顶显示(前提是窗体不能处于最小化状态) } } } if (f == null) { f = new PrivateChat(ipRecv, portRecv, this); f.Show(); } } else { f = new PrivateChat(ipRecv, portRecv, this); f.Show(); } })); }
private void LoadInitMessage() { PrivateChat pObj = new PrivateChat(); pObj.User_id = long.Parse(HiddenUId.Value); pObj.To_user_id = long.Parse(HiddenToid.Value); DataTable dTable = new DataTable(); dTable = pObj.GetInitChat(); if (dTable != null) { object val = null; val = dTable.Rows[0]["msg_id"]; if (val != null) { HiddenMsgid.Value = val.ToString(); } else { HiddenMsgid.Value = "0"; } } else { HiddenMsgid.Value = "0"; } repeatChat.DataSource = dTable; repeatChat.DataBind(); }
public String AddPrivateChat(String message) { String userId = Session.SessionID; PrivateChat prtChat = new PrivateChat(); prtChat.Time = "(" + DateTime.Now.ToString("hh:mm") + ")"; prtChat.Msg = ((Dictionary <String, String>)Application ["UserList"])[userId] + ": " + message.Substring(0, message.LastIndexOf(":;")); prtChat.From = ((Dictionary <String, String>)Application ["UserList"])[userId]; prtChat.To = message.Substring(message.LastIndexOf(":;") + 2); prtChat.CurrentUser = ((Dictionary <String, String>)Application ["UserList"])[userId]; prtChat.Content = message.Substring(0, message.LastIndexOf(":;")); ((List <PrivateChat>)Application["PrivateMsg"]).Add(prtChat); ((List <Object>)Application["PrivateChat"]).Add( new { time = DateTime.Now.ToString("hh:mm"), message = ((Dictionary <String, String>)Application ["UserList"])[userId] + ": " + message.Substring(0, message.LastIndexOf(":;")), sender = ((Dictionary <String, String>)Application ["UserList"])[userId], to = message.Substring(message.LastIndexOf(":;") + 2) }); return("Success"); }
private PrivateChat CreatePrivateChat(Account loggedinAccount, Account otherAccount) { if (!IsLoggedIn()) { return(null); } var newChat = new PrivateChat { FirstUser = loggedinAccount, SecondUser = otherAccount, CreateDate = DateTime.Now, }; newChat = _privateChatRepository.Add(newChat); var message = new PrivateMessage { PrivateChatId = newChat.Id, Content = "No messages have been sent yet!", SendDate = DateTime.Now, }; message = _privateMessageRepository.Add(message); newChat.Messages.Add(message); ViewBag.OtherAccount = newChat.FirstUser == (Account)Session["Loggedin_Account"] ? newChat.SecondUser : newChat.FirstUser; return(newChat); }
public PrivateChatForm(PrivateChat chat) { InitializeComponent(); this.chat = chat; chat.OnClose += OnClose; chat.OnGetMessage += OnGetMessage; }
protected void Page_Load(object sender, EventArgs e) { if (this.User == null || this.User.Identity.IsAuthenticated == false) { Response.Redirect("~/Account/Login.aspx"); } else if (this.User.IsInRole("Administrator")) { currentUser = Administrator.Get(); } else { currentUser = DatabaseUtilities.GetUser(this.User.Identity.Name); } string otherStudentNumber = Request.QueryString["s"]; if (otherStudentNumber != null) { otherUser = DatabaseUtilities.GetUser(otherStudentNumber); //messages = DatabaseUtilities.GetMessagesBetweenUsers(currentUser.StudentNumber, otherUser.StudentNumber); chat = PrivateChatManager.GetChat(currentUser.StudentNumber, otherUser.StudentNumber); // tell the chat that we want to receive its messages chat.RegisterReceiver(this); PopulatePage(); } else { // no other user was supplied so return them to the inbox page Response.Redirect("~/Inbox.aspx"); } }
public async Task <GetPrivateChatDto> GetChatByIdAsync(int id, CancellationToken ct = default) { _logger.LogInformation("Get user private chat by chat id {ChatId}", id); PrivateChat chat = await _unitOfWork.PrivateChatRepository.GetAsync(id, ct); return(_mapper.Map <GetPrivateChatDto>(chat)); }
/// <summary> /// Initializes a new instance of the <see cref="HistoryLoaderTeamsBot"/> class. /// </summary> /// <param name="conversationState">State of the conversation.</param> /// <param name="dialog">The dialog.</param> /// <param name="logger">The logger.</param> /// <param name="extension">The extract history message extension.</param> /// <param name="privateChat">Private chat instance.</param> /// <exception cref="ArgumentNullException">ExtractHistoryMessagingExtension.</exception> public HistoryLoaderTeamsBot(ConversationState conversationState, IHistoryDialog dialog, ILogger <Dialog> logger, ExtractHistoryMessagingExtension extension, PrivateChat privateChat) { ConversationState = conversationState ?? throw new ArgumentNullException(nameof(ConversationState)); Dialog = dialog ?? throw new ArgumentNullException(nameof(Dialog)); Logger = logger ?? throw new ArgumentNullException(nameof(Logger)); extractHistoryMessagingExtension = extension ?? throw new ArgumentNullException(nameof(extractHistoryMessagingExtension)); this.privateChat = privateChat; }
public async Task <IActionResult> ReplyPrivate(MessageForm messageForm) { var message = new Message() { Text = messageForm.Text, User = await _context.Users.FindAsync(messageForm.UserId), MessageToReply = await _context.Messages.FindAsync(messageForm.MessageToReplyId), Time = DateTime.Now }; var detailMessage = (await _context.Messages .Where(x => x.Id == messageForm.MessageToReplyId) .Include(m => m.User).ToListAsync())[0]; var conv = new List <User> { detailMessage.User, message.User }; var privChatList = await _context.PrivateChats .Where(x => conv.Contains(x.User1) && conv.Contains(x.User2)) .Include(c => c.Chat).ToListAsync(); PrivateChat privChat = null; if (privChatList.Count != 0) { privChat = privChatList[0]; } if (privChat is null) { var chat = new Chat() { ChatName = conv[0].NickName + "-" + conv[1].NickName }; privChat = new PrivateChat() { Chat = chat, User1 = conv[0], User2 = conv[1] }; await _context.Chats.AddAsync(chat); await _context.PrivateChats.AddAsync(privChat); } message.Chat = privChat.Chat; await _context.Messages.AddAsync(message); await _context.SaveChangesAsync(); return(Json(new { redirectToUrl = Url.Action("Chat", "Chat", new { chatId = message.Chat.Id }) })); }
public static void ChatSystemUpdate() { Console.WriteLine("----------------ChatSystemUpdate----------------"); new Thread(() => PrivateChat.GetPage().Update()).Start(); new Thread(() => Chat.GetPage().Update()).Start(); new Thread(() => GroupChat.GetPage().Update()).Start(); new Thread(() => GroupSetting.GetPage().Update()).Start(); new Thread(() => Group.getPage().Update()).Start(); }
void StartPrivateChat(PrivateChat chat) { Invoke(new Action(() => { if (chat != null) { PrivateChatForm f = new PrivateChatForm(chat); tabs.AddTabWithControl(chat.Name, f); } })); }
public override IPrivateChat GetPrivateChat() { if (privateChat == null) { privateChat = new PrivateChat(); privateChat.Init(); privateChat.Dispose(); } return(privateChat); }
public static async Task <List <PrivateChat> > Fetch() { var html = await HttpClientHelper.Get(HFRUrl.MessagesUrl + "&page=1"); // TODO : Implement multiple pages if (string.IsNullOrEmpty(html)) { return(null); } var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var messagesArray = ThreadHelper.GetPostNodesFromHtmlDoc(htmlDoc); if (messagesArray == null) { return(null); } var messages = new List <PrivateChat>(); foreach (var msg in messagesArray) { var sujetCase10 = ThreadHelper.GetSujetCase10(msg); var id = ThreadHelper.GetIdFromSujetCase10Node(sujetCase10); var sujetCase9 = ThreadHelper.GetSujetCase9(msg); var threadLastPostDateTime = ThreadHelper.GetDateTimeLastPostFromNode(sujetCase9); var lastPoster = ThreadHelper.ThreadLastPostMemberPseudo(sujetCase9); var isNew = ThreadHelper.NewPost(msg); var subject = ThreadHelper.ThreadName(msg); var nbPage = ThreadHelper.GetNbPageFromNode(msg); var author = ThreadHelper.ThreadAuthor(msg); var threadUrl = msg.Descendants("td").FirstOrDefault(x => x.GetAttributeValue("class", "") == "sujetCase3")?.Descendants("a")?.First()?.GetAttributeValue("href", "")?.CleanFromWeb(); var currentPage = ThreadHelper.GetCurrentPage(threadUrl); var message = new PrivateChat(); message.ThreadId = id; message.ThreadName = subject; message.ThreadUri = threadUrl; message.ThreadAuthor = author; message.ThreadHasNewPost = isNew; message.ThreadLastPostDate = threadLastPostDateTime; message.ThreadLastPostMemberPseudo = lastPoster; message.ThreadNbPage = nbPage; message.ThreadCurrentPage = currentPage; messages.Add(message); } return(messages); }
//"Name<uid><wonid><team>" tell "Name<uid><wonid><team>" message "message" [66] /// <summary> /// Raises the <see cref="PrivateChat"/> event. /// </summary> /// <param name="timestamp">Time at which <see cref="PrivateChat"/> event was fired.</param> /// <param name="info">Information about <see cref="PrivateChat"/> event.</param> protected virtual void OnPrivateChat(DateTime timestamp, string[] info) { var eventArgs = new PrivateChatEventArgs { Timestamp = timestamp, Sender = GetPlayerInfo(info[0]), Receiver = GetPlayerInfo(info[2]), Message = info.Length == 5 ? info[4] : string.Empty }; PrivateChat.Fire(ServerEndPoint, eventArgs); }
public Menu(TcpClient client, IRequests requests) { _consoleSystem = new ConsoleSystem(); _validation = new Validation(); _globalChatOption = new GlobalChatOption(client, requests, _consoleSystem); _privateChat = new PrivateChat(client, requests, _consoleSystem); _createGroupChat = new CreateGroupChat(client, requests, _consoleSystem); _enterGroupChat = new EnterGroupChat(client, requests, _consoleSystem); _managerSettings = new ManagerSettings(client, requests, _consoleSystem); _leaveGroupChat = new LeaveGroupChat(client, requests, _consoleSystem); _menuBuilderInt = new MenuBuilder <int>(_consoleSystem, _validation); _menuBuilderInt = new MenuBuilder <int>(_consoleSystem, _validation); }
private void LoadMessages() { try { PrivateChat pObj = new PrivateChat(); pObj.User_id = long.Parse(HiddenUId.Value); gvUserMessage.DataSource = pObj.GetUserChats(); gvUserMessage.DataBind(); } catch (Exception ex) { } }
public ChatPageViewModel(SavedChats savedChats, UsersInfoModel usersInfoModel) { SelectMessageCommand = new DelegateCommand <PrivateChat>(SelectChat); SendNewMessage = new DelegateCommand(SendMessage); Name = usersInfoModel.FullName; _connectionManager = new ConnectionManager(); WriteManId = usersInfoModel.Id; InitializedChatsPage(savedChats); UserID = savedChats.UserId; CurrentChat = savedChats.SavedPrivateChats.SingleOrDefault(chat => chat.UserIdToWrite.ToString() == usersInfoModel.Id); CurrentChat.Messages = new ObservableCollection <ChatMessage>(); }
public static async Task <List <PrivateChat> > Fetch() { var html = await HttpClientHelper.Get(HFRUrl.MessagesUrl + "&page=1"); // TODO : Implement multiple pages if (string.IsNullOrEmpty(html)) { return(null); } var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var messagesArray = htmlDoc.DocumentNode.Descendants("tr") .Where(x => x.GetAttributeValue("class", "").Contains("sujet ligne_booleen cBackCouleurTab")) .ToArray(); if (messagesArray == null) { return(null); } var messages = new List <PrivateChat>(); foreach (var msg in messagesArray) { var isNewNode = msg.Descendants("td").FirstOrDefault(x => x.GetAttributeValue("class", "").Contains("sujetCase1")); var isMsgNew = false; if (isNewNode.GetAttributeValue("class", "").Contains("cBackCouleurTab2")) { isMsgNew = true; } var subject = msg.Descendants("a").FirstOrDefault(x => x.GetAttributeValue("class", "") == "cCatTopic").InnerText; var lastMsgNode = msg.Descendants("td").FirstOrDefault(x => x.GetAttributeValue("class", "").Contains("sujetCase9")).FirstChild; var dateInnerText = lastMsgNode.FirstChild.InnerText; var dateString = WebUtility.HtmlDecode(dateInnerText).Replace("à", ""); var dateTime = DateTime.Parse(dateString, new CultureInfo("fr-FR")); var lastPoster = msg.Descendants("td").FirstOrDefault(x => x.GetAttributeValue("class", "").Contains("sujetCase6")).FirstChild.InnerText; var message = new PrivateChat(); message.NewMsg = isMsgNew; message.Subject = subject; message.DateTime = dateTime; message.Poster = lastPoster; messages.Add(message); } return(messages); }
public Guid CreatePrivateChat(Guid creatorId, Guid companionId) { var creator = _userRepository.LoadUser(creatorId); var companion = _userRepository.LoadUser(companionId); var newChatId = Guid.NewGuid(); var privateChat = new PrivateChat( newChatId, new Message[0], new ChatMember(creator.Id, creator.Nickname, ChatMemberRole.User), new ChatMember(companion.Id, companion.Nickname, ChatMemberRole.User)); _chatRepository.SaveChat(privateChat); return(newChatId); }
public override IChat CreateChat(ChatType chatType, List <IUser> firstChatUsers, String chatName) { if (firstChatUsers.Count == 2) { IChat privateChat = new PrivateChat(firstChatUsers[0], firstChatUsers[1], chatName); _chatRepository.AddChat(privateChat); return(privateChat); } throw new InvalidDataException("The private chat has to be created with two users!"); }
public PrivateChat CreatePrivateChat(IUser self, IUser peer) { int id = _idProvider.NextId; PrivateChat chat = new PrivateChat( id, new SequentialIdentityProvider(), new FileRepo <IMessage>($".{id}.msg"), self, peer ); _chatRepo.Add(chat); return(chat); }
public async Task <GetPrivateChatDto> CreatePrivateChatAsync(CreatePrivateChatDto chatDto, CancellationToken ct = default) { _logger.LogInformation("Create private chat {PrivateChat}", chatDto); await ValidatePrivateChatAsync(chatDto, ct); PrivateChat chat = _mapper.Map <PrivateChat>(chatDto); chat.CreatedAt = chat.UpdatedAt = DateTime.UtcNow; _unitOfWork.PrivateChatRepository.Create(chat); await _unitOfWork.CommitAsync(ct); return(_mapper.Map <GetPrivateChatDto>(chat)); }