如何在 android smack 4.2.0-beta1 中使用 MucEnterConfiguration? [英] How to use MucEnterConfiguration in android smack 4.2.0-beta1?

查看:30
本文介绍了如何在 android smack 4.2.0-beta1 中使用 MucEnterConfiguration?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重新加入聊天室并且不想要任何历史记录,但是 DiscussionHistory 已被弃用.所以我找到了 MucEnterConfiguration 类.但我无法创建 MucEnterConfiguration 的对象.

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 是 final 类,因此它不能被扩展和
    没有公共构造函数.

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

MucEnterConfiguration.Builder 也是 final 类,所以它不能
extends 并且没有公共构造函数.

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

我如何创建它的对象.

谢谢

推荐答案

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

这篇关于如何在 android smack 4.2.0-beta1 中使用 MucEnterConfiguration?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆