chat history

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

sasha281215
Posts: 6
Joined: 24 Dec 2017, 15:51

chat history

Postby sasha281215 » 25 Dec 2017, 11:51

How to make avatar chat, I can view the message history, which will shows the last five messages? How to view a log of messages sent from users in control panel?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: chat history

Postby Lapo » 26 Dec 2017, 18:35

Hi,
user's messages are not stored by default, but you can create a storage system via server side code.
In your Extension code you can listen for any public/private message being sent by adding an event handler for SFSEvent.PUBLIC_MESSAGE and SFSEvent.PRIVATE_MESSAGE.

From there you can simply accumulate those messages in a list/queue and then flush them to the database when the user leaves / disconnects.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
tanvan
Posts: 5
Joined: 05 Jul 2021, 10:42

Re: chat history

Postby tanvan » 08 Jul 2021, 07:44

Lapo wrote:Hi,
user's messages are not stored by default, but you can create a storage system via server side code.
In your Extension code you can listen for any public/private message being sent by adding an event handler for SFSEvent.PUBLIC_MESSAGE and SFSEvent.PRIVATE_MESSAGE.

From there you can simply accumulate those messages in a list/queue and then flush them to the database when the user leaves / disconnects.

Hope it helps

Hi

I've register

this.addEventListener(SFSEventType.PRIVATE_MESSAGE, ReceivePrivateMessage.class);

But ReceivePrivateMessage.class base on class ????

public class ReceivePrivateMessage extends BaseSFSEventListener ??? correct
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: chat history

Postby Lapo » 08 Jul 2021, 10:22

Hi,
the method to listen for a server-side event is addEventHandler()
For example:

Code: Select all

addEventHandler(SFSEventType.PRIVATE_MESSAGE, PrivMessageHandler.class);


The event sends a number of objects which are documented in the javadoc:
http://docs2x.smartfoxserver.com/api-do ... TE_MESSAGE

Which you can extract like this:

Code: Select all

@Override
public void handleServerEvent(ISFSEvent event) throws SFSException
{
   User user = (User) event.getParameter(SFSEventParam.USER);
   // etc...
}

More on this here:
http://docs2x.smartfoxserver.com/Extens ... a/overview

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
tanvan
Posts: 5
Joined: 05 Jul 2021, 10:42

Re: chat history

Postby tanvan » 16 Jul 2021, 13:42

Thanks so much

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 22 guests