Click or drag to resize

PrivateMessageRequest Class

Sends a private chat message.
Inheritance Hierarchy
SystemObject
  BaseRequest
    GenericMessageRequest
      Sfs2X.RequestsPrivateMessageRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class PrivateMessageRequest : GenericMessageRequest
Constructors
  NameDescription
Public methodPrivateMessageRequest(String, Int32)
See PrivateMessageRequest(string, int, ISFSObject) constructor.
Public methodPrivateMessageRequest(String, Int32, ISFSObject)
Creates a new PrivateMessageRequest instance.
Top
Remarks
The private message is dispatched to a specific user, who can be in any server Room, or even in no Room at all. The message is delivered by means of the PRIVATE_MESSAGE event. It is also returned to the sender: this allows showing the messages in the correct order in the application interface. It is also possible to send an optional object together with the message: it can contain custom parameters useful to transmit, for example, additional informations related to the message, like the text font or color, or other formatting details.
Examples
The following example sends a private message and handles the respective event:
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.PRIVATE_MESSAGE, OnPrivateMessage);

    // Send a private message to Jack
    User messageRecipient = sfs.UserManager.GetUserByName("Jack");
    sfs.Send( new PrivateMessageRequest("Hello Jack!", messageRecipient.Id) );
}

void OnPrivateMessage(BaseEvent evt) {
    // As messages are forwarded to the sender too, I have to check if I am the sender
    User sender = (User)evt.Params["sender"];

    if (sender != sfs.MySelf)
    {
        Console.WriteLine("User " + sender.Name + " sent me this PM: " + (string)evt.Params["message"]);                        // .Net / Unity
        System.Diagnostics.Debug.WriteLine("User " + sender.Name + " sent me this PM: " + (string)evt.Params["message"]);       // UWP
    }
}
See Also