示例#1
0
 public static void HandleEvent(FriendRequestEvent e, MainViewModel dataContext)
 {
   dataContext.MessageText += $"Friend request was receieved from {e.SenderAccountName}!\n";
 }
示例#2
0
    /// <summary>
    /// <see cref="IChatService.SendFriendRequest"/>
    /// </summary>
    public string SendFriendRequest(string senderName, string recipientName)
    {
      // Verify the recipient name provided is a valid username.
      if (!Validation.IsValidUserName(recipientName))
      {
        var response = new SendFriendRequestResponse { Result = SendFriendRequestResult.InvalidUsername };
        return JsonConvert.SerializeObject(response);
      }

      // Get the recipient's IP/Port.
      var recipient = DatabaseProcedures.GetAccountByName(recipientName);
      if (recipient == null)
      {
        var response = new SendFriendRequestResponse { Result = SendFriendRequestResult.UserNotFound };
        return JsonConvert.SerializeObject(response);
      }
      
      // TODO: Verify there is not already a pending request.
      // DatabaseProcedures.DoesFriendRequestExist(senderId, recipient.Id);

      // TODO: Verify the sender isn't blocked by the recipient.


      // Send the friend request event to the recipient.
      if (ServiceHelpers.GetPresence(recipient) == PresenceStatus.Online)
      {
        var evnt = new FriendRequestEvent
        {
          Timestamp = DateTime.Now,
          Type = EventType.FriendRequest,
          SenderAccountName = senderName
        };

        EventManager.SendEventToClient(recipient.IpAddress, recipient.Port.Value, evnt);
      }

      return "good";
    }