//.......................................................................................................................... public void RejectFriendRequest(string inFriendName) { //Debug.Log("RejectFriendRequest " + inFriendName); // check preconditions... if (CloudUser.instance.isUserAuthenticated == false) { Debug.LogError("user is not authenticated, can't Accept Friend Request"); return; } PendingFriendInfo fInfo = m_PendingFriends.Find(f => f.PrimaryKey == inFriendName); if (fInfo == null || fInfo.IsItRequest == false) { Debug.LogError("Can't reject friend which is not in pending list"); return; } // create message object... CloudMailbox.FriendRequestReject msg = new CloudMailbox.FriendRequestReject(); msg.m_TargetSystem = "Game.FriendList"; msg.m_Mailbox = CloudMailbox.E_Mailbox.Global; msg.m_Sender = CloudUser.instance.primaryKey; msg.m_NickName = CloudUser.instance.nickName; msg.m_Message = "FriendShip rejected"; // this will not be shown... GameCloudManager.mailbox.SendMessage(inFriendName, msg); m_PendingFriends.Remove(fInfo); OnPendingFriendListChanged(); Save(); }
//.......................................................................................................................... public void ProcessMessage(CloudMailbox.BaseMessage inMessage) { // add into pending friends.. CloudMailbox.FriendRequest req = inMessage as CloudMailbox.FriendRequest; if (req != null) { FriendInfo fInfo = m_Friends.Find(f => f.PrimaryKey == inMessage.m_Sender); if (fInfo != null) { //Debug.Log("User with name " + inMessage.m_Sender + " is already your friend"); return; } List <PendingFriendInfo> pfInfo = m_PendingFriends.FindAll(f => f.PrimaryKey == inMessage.m_Sender); if (pfInfo != null && pfInfo.Count > 0) { foreach (PendingFriendInfo p in pfInfo) { if (p != null && p.IsItRequest == true) { //Debug.Log("Request from this person is already in pending list"); return; } } } PendingFriendInfo friend = new PendingFriendInfo(); friend.PrimaryKey = req.m_Sender; friend.Nickname = req.m_NickName; friend.Username_New = req.m_Username; friend.AddedDate = GuiBaseUtils.DateToEpoch(inMessage.m_SendTime); friend.Message = inMessage.m_Message; friend.CloudCommand = req.m_ConfirmCommand; m_PendingFriends.Add(friend); OnPendingFriendListChanged(); Save(); return; } CloudMailbox.FriendRequestReject reject = inMessage as CloudMailbox.FriendRequestReject; if (reject != null) { // remove this friend from pending list if it is still there. List <PendingFriendInfo> pfInfo = m_PendingFriends.FindAll(friend => friend.PrimaryKey == inMessage.m_Sender); if (pfInfo != null && pfInfo.Count > 0) { foreach (PendingFriendInfo p in pfInfo) { m_PendingFriends.Remove(p); } } OnPendingFriendListChanged(); Save(); return; } Debug.LogError("Unknown message " + inMessage + " " + inMessage.msgType); }
public static string GetSender(this Message message) { if (message is FriendMessage) { FriendMessage friendMessage = (FriendMessage)message; if (string.IsNullOrEmpty(friendMessage.m_NickName) == false) { return(friendMessage.m_NickName); } var friend = GameCloudManager.friendList.friends.Find(obj => obj.PrimaryKey == message.m_Sender); if (friend != null) { return(friend.Nickname); } } else if (message is FriendRequest) { FriendRequest friendRequest = (FriendRequest)message; if (string.IsNullOrEmpty(friendRequest.m_NickName) == false) { return(friendRequest.m_NickName); } if (string.IsNullOrEmpty(friendRequest.m_Username) == false) { return(friendRequest.m_Username); } } else if (message is FriendRequestReject) { FriendRequestReject friendRequest = (FriendRequestReject)message; if (string.IsNullOrEmpty(friendRequest.m_NickName) == false) { return(friendRequest.m_NickName); } } return(message != null && string.IsNullOrEmpty(message.m_Sender) == false ? message.m_Sender : message.msgType); }