Esempio n. 1
0
        public ActionResult Conversation(string otherUser = "")
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(otherUser))
            {
                throw new System.Exception("Did not supply all required arguments.");
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            GetChatHistory getCommand = new GetChatHistory()
            {
                history = new ChatHistory()
                {
                    user1 = Globals.getUser(),
                    user2 = otherUser
                }
            };

            GetChatHistoryRequest request = new GetChatHistoryRequest(getCommand);

            GetChatHistoryResponse response = connection.getChatHistory(request);

            string newConvoHtml = "";

            foreach (ChatMessage msg in response.responseData.history.messages)
            {
                if (msg.sender.Equals(Globals.getUser()))
                {
                    newConvoHtml +=
                        "<p class=\"message\">" +
                        "<span class=\"username\">You: </span>" +
                        msg.messageContents +
                        "</p>";
                }
                else
                {
                    newConvoHtml +=
                        "<p class=\"message\">" +
                        "<span class=\"username\" style=\"color:aqua;\">" + msg.sender + ": </span>" +
                        msg.messageContents +
                        "</p>";
                }
            }

            return(Content(newConvoHtml));
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            GetChatContacts getContactsCommand = new GetChatContacts
            {
                usersname    = Globals.getUser(),
                contactNames = null
            };

            GetChatContactsRequest  contactsRequest  = new GetChatContactsRequest(getContactsCommand);
            GetChatContactsResponse contactsResponse = connection.getAllChatContacts(contactsRequest);

            ChatHistory firstDisplayedChatHistory = null;

            if (contactsResponse.responseData.contactNames.Count != 0)
            {
                GetChatHistory getHistoryCommand = new GetChatHistory()
                {
                    history = new ChatHistory
                    {
                        user1 = Globals.getUser(),
                        user2 = contactsResponse.responseData.contactNames[0]
                    }
                };

                GetChatHistoryRequest historyRequest = new GetChatHistoryRequest(getHistoryCommand);
                firstDisplayedChatHistory = connection.getChatHistory(historyRequest).responseData.history;
            }
            else
            {
                firstDisplayedChatHistory = new ChatHistory();
            }

            ViewBag.ChatInstances        = contactsResponse.responseData.contactNames;
            ViewBag.DisplayedChatHistory = firstDisplayedChatHistory;

            return(View());
        }