I am developing chat application using XMPPFramework
How can i receive history of messages after join existing room?
Now i join to room like this:
XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",systemName,xmppServer]];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomHybridStorage sharedInstance] jid:roomJid];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"100"];
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:history];
Also i read example from documentation
According to this example I also tried to join room this way:
XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",systemName,xmppServer]];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomHybridStorage sharedInstance] jid:roomJid];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
[presence addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"bob@%@",xmppServer]];
[presence addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@@conference.%@/%@",systemName,xmppServer,user.deviceUUID]];
NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"http://jabber.org/protocol/muc"];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"100"];
[x addChild:history];
[presence addChild:x];
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:presence];
I join room successfully, but don't receive history of previous messages.
Btw, if at least one user in the room, i receive all previous messages, even if i join room like:
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:nil];
If all users leave room and then some join again - history is empty=(
What am I doing wrong? Do i need to turn on some settings on the server side to save history (eg, logging)?
And some questions about example from documentation:
What means "from" parameter? Does it mean that I ask for the history of messages in this room only from user bob? And what if i want to receive all history (messages from any users)?
What means "id" parameter? I didn't find any description in the documentation.
When you've created a room and you've joined, you need to configure that room to make persistent, what this means is that:
Persistent Room A room that is not destroyed if the last occupant exits; antonym: Temporary Room. (You want this room's configuration).
Temporary Room A room that is destroyed if the last occupant exits; antonym: Persistent Room.
1. So, you create and join a room.
2. Then, the delegate method
xmppRoomDidJoin:sender;
is called (only if all has gone right), and you have to configure your roomfetchConfigurationForm
method send an IQ to request an initial room configuration form.Example of IQ that has been sent to XMPP Server:
3. When XMPP server answer with the room configuration the
-xmppRoom:sender didFetchConfigurationForm:configForm;
method is called. And here is where you change the default values of the room to make persistent, room name, members only, etc.Example:
Thanks @Moral for explanation. But In my case the solution was very simple.
In the chat server in
ejabberd.yml
just added default options in the module muc configuration:And in the app join room this way:
Thats it!