// CALLBACKS // Sending Chat request public void ChatRequestConfirmationCallback(XmlDocument messageDoc) { var rootEl = messageDoc.DocumentElement; // If passes, it has all the required attributes for this callback if (!rootEl.HasAttribute("userToChatWith") || !rootEl.HasAttribute("command") || !rootEl.HasAttribute("value")) { return; } var username = messageDoc.DocumentElement.GetAttribute("userToChatWith"); var cmd = messageDoc.DocumentElement.GetAttribute("command"); var value = messageDoc.DocumentElement.GetAttribute("value"); if (value == "true") { CurrentChatPal = username; OnInitiateChatWithUser.Invoke(); } else { OnFailedChatRequest.Invoke(); } }
// Receiving chat request public void ReceiveChatRequest(XmlDocument messageDoc) { // TODO: add confirmation popup var rootEl = messageDoc.DocumentElement; CurrentChatPal = rootEl.GetAttribute("sender"); OnInitiateChatWithUser.Invoke(); // Inform the server that request has been granted var msg = $"<msg acceptedUser=\"{CurrentChatPal}\" command=\"requestConfirmationFromClient\" value=\"true\"></msg>"; SendMessage(msg); }