public void Handle(ISession session) { if (TargetID.Equals(Guid.Empty)) { return; } ChatUser targetUser = ChatUserManager.LoadUser(TargetID); if (targetUser == null) { return; } ChatSession chatSession = session as ChatSession; ConversationStore store = new ConversationStore(); Guid resultID = Guid.NewGuid(); bool flag = true; var CommonConversation = targetUser.ConversationID.Intersect(chatSession.Owner.ConversationID); foreach (Guid conversationID in CommonConversation) { AbstractConversation conversation = store.Load(conversationID); if (conversation is SingleConversation) { resultID = conversation.ID; flag = false; break; } } if (flag) { chatSession.Owner.ConversationID.Add(resultID); targetUser.ConversationID.Add(resultID); store.Save(new SingleConversation() { ID = resultID, Members = new HashSet <Guid>() { chatSession.Owner.ID, targetUser.ID }, ConversationName = "~" }); chatSession.Owner.Save(); targetUser.Save(); } SingleConversationFrUserIDResponse response = new SingleConversationFrUserIDResponse(); response.UserID = TargetID; response.ResponseID = resultID; chatSession.Send(response); }
private AbstractConversation GrabCurrentConversation() { AbstractConversation c = ((AbstractConversation)CurrentConversation); if (c == null) { throw new ConversationUnavailableException(); } return(c); }
public void Handle(ISession session) { Guid converID = Guid.Parse(ConversationID); AbstractConversation conversation = ConversationManager.GetConversation(converID); if (conversation == null) { return; } conversation.UpdateColor(Color, (session as ChatSession).Owner); }
public void Save(AbstractConversation conversation) { lock (_lock) { Mongo.Instance.Set <AbstractConversation>(conversation.ID.ToString(), (collection) => { var condition = Builders <AbstractConversation> .Filter.Eq(p => p.ID, conversation.ID); collection.ReplaceOneAsync(condition, conversation, new UpdateOptions() { IsUpsert = true }); }); } }
public void Handle(ISession session) { ChatSession chatSession = session as ChatSession; if (!chatSession.Owner.ConversationID.Contains(ConversationID)) { return; } AbstractConversation conversation = ConversationManager.GetConversation(ConversationID); if (conversation == null || conversation is GroupConversation) { return; } if (chatSession.Owner.LastBuzz.ContainsKey(ConversationID)) { chatSession.Owner.LastBuzz.TryGetValue(ConversationID, out var lastBuzz); if (DateTime.Now.Ticks - lastBuzz < 10000000 * 10) { return; } } chatSession.Owner.LastBuzz.TryRemove(ConversationID, out var lastz); chatSession.Owner.LastBuzz.TryAdd(ConversationID, DateTime.Now.Ticks); BuzzResponse message = new BuzzResponse() { SenderID = chatSession.Owner.ID.ToString(), ConversationID = this.ConversationID.ToString() }; foreach (Guid guid in conversation.Members) { if (ChatUserManager.IsOnline(guid) && guid != chatSession.Owner.ID) { chatSession.Owner.Relationship.TryGetValue(guid, out var relationID); Relation relation = Relation.Get(relationID); if (relation == null || relation.RelationType != Relation.Type.Friend) { continue; } ChatUserManager.LoadUser(guid).Send(message); } } }
public void UpdateMessagesList(AbstractConversation conversation) { lock (_lock) { Mongo.Instance.Set <AbstractConversation>(conversation.ID.ToString(), collection => { var condition = Builders <AbstractConversation> .Filter.Eq(p => p.ID, conversation.ID); var update = Builders <AbstractConversation> .Update .Set(p => p.MessagesID, conversation.MessagesID) .Set(p => p.MediaID, conversation.MediaID) .Set(p => p.AttachmentID, conversation.AttachmentID); collection.UpdateOneAsync(condition, update, new UpdateOptions() { IsUpsert = true }); }); } }
public void Handle(ISession session) { if (MessagePosition == -1) { return; } ChatSession chatSession = session as ChatSession; ConversationStore store = new ConversationStore(); AbstractConversation conversation = store.Load(ConversationID); MessageFromConversationResponse packet = new MessageFromConversationResponse(); var messages = conversation.MessagesID; if (messages.Count == 0) { return; } MessageStore messageStore = new MessageStore(); for (int i = MessagePosition; i >= Math.Max(0, MessagePosition - Quantity + 1); --i) { AbstractMessage mess = new MessageStore().Load(messages[i], ConversationID); if (mess != null) { packet.SenderID.Add(mess.Author.ToString()); packet.Content.Add(mess); } } packet.LoadConversation = LoadConversation; chatSession.Owner.SendOnly(packet, chatSession); }
/// <summary> /// Send our message. /// </summary> private async Task SendMessage() { //If we have tried to send a zero length string we just return if (string.IsNullOrWhiteSpace(messageText.Text) || messageText.IsReadOnly) { return; } messageText.IsReadOnly = true; //We write our own message to the chatBox AppendLineToChatBox($"[You] - " + messageText.Text); try { _conversationState = await _conversationState.HandleUserInput(messageText.Text); } catch (FaceAPIException ex) when("RateLimitExceeded".Equals(ex.ErrorCode)) { ReplyAsBot($"My brain is overloaded with your questions."); ReplyAsBot("Please hold on for a while because I can only do a limited amount of requests per minute.."); Thread.Sleep(3000); } //We clear the text within the messageText box. messageText.Text = ""; messageText.IsReadOnly = false; }
public void Handle(ISession session) { ChatSession chatSession = session as ChatSession; AbstractConversation conversation = ConversationManager.GetConversation(ConversationID); if (conversation == null) { return; } conversation.SendMessage(Message, chatSession); /* * if (ChatUserManager.OnlineUsers.TryGetValue(Guid.Parse(ReceiverID), out user)) * { * SendMessageResponse packet = new SendMessageResponse(); * packet.ConversationID = ConversationID; * packet.Message = Message; * packet.SenderID = chatSession.Owner.ID.ToString(); * user.Send(packet); * } */ }
public AbstractConversation Load(Guid id) { AbstractConversation conversation = null; try { conversation = Mongo.Instance.Get <AbstractConversation>(id.ToString(), (collection) => { var condition = Builders <AbstractConversation> .Filter.Eq(p => p.ID, id); var result = collection.Find(condition).Limit(1).ToList(); if (result.Count > 0) { return(result[0]); } return(null); }); } catch (Exception e) { PacChatServer.GetServer().Logger.Error(e); } return(conversation); }
public MainWindow(IFaceApiHelper faceApiHelper) { InitializeComponent(); FaceApiHelper = faceApiHelper; _conversationState = new StartConversation(this); }
public void Handle(ISession session) { ChatSession chatSession = session as ChatSession; UserSearchResponse response = new UserSearchResponse(); List <String> UserIDs = new ChatUserStore().SearchUserIDByEmail(Email, (session as ChatSession).Owner); ConversationStore store = new ConversationStore(); foreach (var item in UserIDs) { Guid userId = Guid.Parse(item); ChatUser targetUser = ChatUserManager.LoadUser(userId); SearchResult result = new SearchResult(); result.ID = targetUser.ID.ToString(); result.FirstName = targetUser.FirstName; result.LastName = targetUser.LastName; result.IsOnline = targetUser.IsOnline(); result.LastLogout = targetUser.LastLogoff; result.PreviewCode = -1; result.ConversationID = "~"; var CommonConversation = targetUser.ConversationID.Intersect(chatSession.Owner.ConversationID); foreach (Guid id in CommonConversation) { AbstractConversation conversation = store.Load(id); if (conversation is SingleConversation) { result.ConversationID = conversation.ID.ToString(); AbstractMessage message = conversation.MessagesID.Count > 0 ? new MessageStore().Load(conversation.MessagesID.Last(), conversation.ID) : null; if (message == null) { break; } if (!message.Showable(chatSession.Owner.ID)) { result.PreviewCode = 0; break; } result.PreviewCode = message.GetPreviewCode(); if (message.GetPreviewCode() == 4) { result.LastMessage = (message as TextMessage).Message; } break; } } if (chatSession.Owner.Relationship.ContainsKey(targetUser.ID)) { result.Relationship = (int)Relation.Get(chatSession.Owner.Relationship[targetUser.ID]).RelationType; } else { result.Relationship = (int)Relation.Type.None; } response.Results.Add(result); } session.Send(response); }
public void Handle(ISession session) { ChatSession chatSession = session as ChatSession; ChatUser targetUser = ChatUserManager.LoadUser(TargetID); if (targetUser == null) { return; } ShortProfileResponse response = new ShortProfileResponse(); response.ID = targetUser.ID.ToString(); response.FirstName = targetUser.FirstName; response.LastName = targetUser.LastName; response.IsOnline = targetUser.IsOnline(); response.LastLogout = targetUser.LastLogoff; ConversationStore store = new ConversationStore(); response.PreviewCode = -1; response.ConversationID = "~"; var CommonConversation = targetUser.ConversationID.Intersect(chatSession.Owner.ConversationID); foreach (Guid id in CommonConversation) { AbstractConversation conversation = store.Load(id); if (conversation is SingleConversation) { response.ConversationID = conversation.ID.ToString(); AbstractMessage message = conversation.MessagesID.Count > 0 ? new MessageStore().Load(conversation.MessagesID.Last(), conversation.ID) : null; if (message == null) { break; } if (!message.Showable(chatSession.Owner.ID)) { response.PreviewCode = 0; break; } response.PreviewCode = message.GetPreviewCode(); if (message.GetPreviewCode() == 4) { response.LastMess = (message as TextMessage).Message; } break; } } if (chatSession.Owner.Relationship.ContainsKey(targetUser.ID)) { response.RelationshipType = (int)Relation.Get(chatSession.Owner.Relationship[targetUser.ID]).RelationType; } else { response.RelationshipType = (int)Relation.Type.None; } chatSession.Send(response); }