Exemple #1
0
        public void UpdateColor(int color, ChatUser sender)
        {
            //Check change condition
            if (true)
            {
                this.Color = color;
                store.Save(this);

                ChangeBubbleChatColor packet = new ChangeBubbleChatColor()
                {
                    ConversationID = this.ID.ToString(),
                    Color          = color
                };

                foreach (Guid memberID in Members)
                {
                    if (!ChatUserManager.IsOnline(memberID))
                    {
                        continue;
                    }
                    ChatUser user = ChatUserManager.LoadUser(memberID);
                    user.Send(packet);
                }
            }
            else
            {
                ChangeBubbleChatColor packet = new ChangeBubbleChatColor()
                {
                    ConversationID = this.ID.ToString(),
                    Color          = this.Color
                };
                sender.Send(packet);
            }
        }
        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);
        }