Class SFS2X.Requests.BuddyList.BuddyMessageRequest
Sends a message to a buddy in the current user's buddy list.
Constructor Attributes | Constructor Name and Description |
---|---|
SFS2X.Requests.BuddyList.BuddyMessageRequest(message, targetBuddy, params)
Creates a new BuddyMessageRequest instance.
|
Class Detail
Messages sent to buddies using the BuddyMessageRequest request are similar to the standard private messages (see the PrivateMessageRequest request) but are specifically designed for the Buddy List system: they don't require any Room parameter, nor they require that users joined a Room. Additionally, buddy messages are subject to specific validation, such as making sure that the recipient is in the sender's buddies list and the sender is not blocked by the recipient.
If the operation is successful, a buddyMessage event is dispatched in both the sender and recipient clients.
NOTE: this request can be sent if the Buddy List system was previously initialized only (see the InitBuddyListRequest request description).
The following example sends a message to a buddy and handles the related event:
function someMethod() { sfs.addEventListener(SFS2X.SFSBuddyEvent.BUDDY_MESSAGE, onBuddyMessage, this); // Get the recipient of the message, in this case my buddy Jack var buddy = sfs.buddyManager.getBuddyByName("Jack"); // Send a message to Jack sfs.send(new SFS2X.Requests.BuddyList.BuddyMessageRequest("Hello Jack!", buddy)); } function onBuddyMessage(evtParams) { // As messages are forwarded to the sender too, // I have to check if I am the sender var isItMe = evtParams.isItMe; var sender = evtParams.buddy; if (isItMe) console.log("I said: " + evtParams.message); else console.log("My buddy " + sender.name + " said: " + evtParams.message); }
- Parameters:
- {String} message
- The message to be sent to a buddy.
- {SFSBuddy} targetBuddy
- The SFSBuddy object corresponding to the message recipient.
- {Object} params Optional, Default: null
- An object containing additional custom parameters (e.g. the message color, an emoticon id, etc).