How to use MucEnterConfiguration in android smack 4.2.0-beta1?

匆匆过客 提交于 2020-01-04 14:16:43

问题


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);


来源:https://stackoverflow.com/questions/42442735/how-to-use-mucenterconfiguration-in-android-smack-4-2-0-beta1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!