1
votes

I am using ejabberd 15.06 version with Strophe.js. Retrieving the one-to-one chat from my backend database works fine. But how can I retrieve the groupchat history from the database??

For example, if I have a "strophe" group. When new users joins in the strophe group, then the chat history done in the group by other users should be displayed.

I am using this code

var pres = $pres({ to:  room + "/" + nickname, from: connection.jid });
connection.send( msg.c('x', {xmlns: NS_MUC}));

if(chat_history != null){
    var msg_history = msg.c('x', { "xmlns": "http://jabber.org/protocol/muc"}).c("history", chat_history, {maxstanzas: 50});
    debugger;   
    console.log(msg_history);           
}

In my console it looks like

h.Builder {nodeTree: presence, node: x}

I am stuck how to fetch the history of groupchat. Please help

1

1 Answers

5
votes

Usually, unless the room has been configured not to send any history, send the join presence should be enough to let you receive the latest chat room messages. Please, note that old messages have a delay tag on them to provide the time at which the original message was send, so make sure your client is not discarding those messages.

If you want control about the history size, you can use the Strophe MUC plugin to join the room and send the max stanzas and time limit as the history_attrs variable. Your server and room must also be configured to provide the history.

conn.muc.join(room, nick, msg_handler_cb, pres_handler_cb, roster_cb, password,{ maxstanzas: 10, seconds: 3600 });