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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }