How to use MucEnterConfiguration in android smack

2019-07-14 12:13发布

问题:

I want to rejoin room and don’t want any history, but DiscussionHistory is deprecated. So I found class MucEnterConfiguration. But I am unable to create object of MucEnterConfiguration.

  1. MucEnterConfiguration is a final class so it can’t be extends and
    don’t have a public constructor.

  2. MucEnterConfiguration.Builder is also final class so it can’t be
    extends and don’t have a public constructor.

How I can create object of it.

Thanks

回答1:

EntityBareJid mucJid =  JidCreate.entityBareFrom(roomJid);
Resourcepart nickname = Resourcepart.from(nickname);
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);

MultiUserChat muc = manager.getMultiUserChat(mucJid);
MucEnterConfiguration.Builder mec = muc.getEnterConfigurationBuilder(nickname);

String lastDate = "yourLastDate";
if(lastDate!=null)
{
    try {
        Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(lastDate);
        int secondsBetween = (int) ((new Date().getTime() - date.getTime()) / 1000);
        mec.requestHistorySince(secondsBetween - 1);
    } catch (Exception e) {
        mec.requestNoHistory();
    }
} else {
      mec.requestNoHistory();
}
MucEnterConfiguration mucEnterConfig = mec.build();
muc.join(mucEnterConfig);