Once I have a roster I can loop through all members and query with the MamManager mamManager.mostRecentPage(jid, QUERY_META_DATA_PAGE_SIZE)
However, this only lets me get data for one jid at a time which means if a user has 1000 connections I have to make 1000 network calls. Is there any way to get the most recent message for multiple jids?
EDIT
So I've updated from 4.2.3 to 4.3 of smack to get the latest api and I still can find a way to perform the query I want without looping through the jids
for (int i = 0; i < jidList.size(); i++) {
MamQueryArgs mamQueryArgs = MamQueryArgs.builder()
.setResultPageSize(1)
.limitResultsToJid(jidList.get(i))
.queryLastPage().build();
MamQuery mamQuery = mamManager.queryArchive(mamQueryArgs);
}
So on first login for a new user I'll hit the server 1000 times
Edit 2
Actually for first login that query above returns nothing, probably because the local archive is empty so I have to do the following:
for (Jid : jidList) {
MamQuery mamQuery = mamManager.queryMostRecentPage(jid, 1);
}
Is there any way to get the most recent message for multiple jids?
This is a different question then the question in your posts title "Get the most recent message for all roster members", isn't it? But I believe the answer is the same for both questions. Message Archive Management (XEP-0313) queries query an archive. The 'jid' argument only limits the results to only contain messages with that JID.
If you query your local user archive (the common case), then you can query simply the last X messages using Smack with
MamQueryArgs mamQueryArgs = MamQueryArgs.builder()
.setResultPageSize(<X>)
.queryLastPage()
.build();
MamQuery mamQuery = mamManager.queryArchive(mamQueryArgs);
For more information, look at MamManager
's javadoc .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.