How do I get the message from the message id in smack.

丶灬走出姿态 提交于 2019-12-04 05:01:41

问题


I am trying to fetch the chat history using below function:

    var mamManager:MamManager= MamManager.getInstanceFor(connection)
    var prevMsg=mamManager.queryArchive(JidCreate.entityBareFrom(jid)).forwardedMessages

        println(msg.forwardedStanza)

But I am getting the output as

04-19 14:17:58.414 7964-7964/com.example.itstym.smackchat I/System.out: Message Stanza [to=user2@replica3377.cloudapp.net,from=user1@replica3377.cloudapp.net/307135084148417199024926,id=qQ73x-27,]

I can also get stanza id using msg.forwardedStanza.stanzaId but how will i get the msg text.


回答1:


Cast the forwarded Stanza to Message and call getBody().




回答2:


The getBody() is for Message and the ForwardedStanza extends Stanza so it can be Message, IQ or Presence.

Try this:

    if (forwarded.getForwardedStanza() instanceof Message) {
        String body = ((Message) forwarded.getForwardedStanza()).getBody();
    }


来源:https://stackoverflow.com/questions/43491831/how-do-i-get-the-message-from-the-message-id-in-smack

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