2

I have created a XMPP Swift Messenger with the eJabbered, but it doesn't save the history.

I searched a lot and could found just answers written in ObjC, in Stack.

For instance:

- (void)loadChatHistoryWithUserName:(NSString *)userName {
    NSString *userJid = [NSString stringWithFormat:@"%@@%@",userName,self.hostName];
    NSManagedObjectContext *moc = [_xmppMsgStorage mainThreadManagedObjectContext];
    NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject"
                                                     inManagedObjectContext:moc];
    NSFetchRequest *request = [[NSFetchRequest alloc]init];
[request setEntity:entityDescription];
    NSError *error;
    NSString *predicateFrmt = @"bareJidStr == %@";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFrmt, userJid];
request.predicate = predicate;
    NSArray *messages = [moc executeFetchRequest:request error:&error];
}

But I use XMPP Swift Framework with the XMPP ObjC Framework inside. Look at this Git: GitHub

How can I use those snippet in Swift for getting chat history?

1 Answers1

0

If your'e not saving the history locally (i.e. a cache of some sort), then you should probably look into a server plugin that logs the chats and allows you to retrieve them upon connection and login (and entering the relevant room, etc.), if my memory serves me correctly, ejabbered doesn't have that built in (or maybe the payed version does), from my experience Prosody IM server has that plugin and it's pretty easy to setup.

After that, make sure your client side retrieves the history (using a listener, etc.)

Hope this helps.

TommySM
  • 3,793
  • 3
  • 24
  • 36