首页 > 解决方案 > How to identify delivered and undelivered messages while retreiving chat history from ejabberd?

问题描述

I'm retrieving the chat history with the code below. In the view I need to show ticks for the messages whether they are delivered or not. But the message stanza structure is same for both delivered and undelivered messages. So how do I distinguish between the delivered and non-delivered messages without setting up an external database.

This is my code in my service.ts file:

this.Connection.mam.query(from, {
    with: to,
    before: '',
    max: '10',
    onMessage: (message) = > {
        console.log(message);
    },
    onComplete: (response) = > {
        console.log('Got all the messages');
    }
});

The output what I am getting is:

<message
    xmlns=​"jabber:​client" to=​"sashank@localhost/​9158846669251631426100" from=​"sashank@localhost">​

    <result
        xmlns=​"urn:​xmpp:​mam:​2" id=​"1546597812368545">​

        <forwarded
            xmlns=​"urn:​xmpp:​forward:​0">​

            <message
                xmlns=​"jabber:​client" xml:lang=​"en" 
         to="murali@localhost" from=​"sashank@localhost/​18846625227131105454610" type=​"chat" id=​"0777d27e-7238-42ba-9063-78185c05e76d">​

                <archived
                    xmlns=​"urn:​xmpp:​mam:​tmp" by=​"sashank@localhost" id=​"1546597812368545">​

                </archived>​

                <stanza-id
                    xmlns=​"urn:​xmpp:​sid:​0" by=​"sashank@localhost" id=​"1546597812368545">​

                </stanza-id>​

                <request
                    xmlns=​"urn:​xmpp:​receipts">​

                </request>​

                <body>​Hello buddy! How are you</body>​

            </message>​

            <delay
                xmlns=​"urn:​xmpp:​delay" from=​"localhost" stamp=​"2019-01-04T10:​30:​12.368545Z">​

            </delay>​

        </forwarded>​

    </result>​

</message>​

This is the delivered message and undelivered messages also looks the same in stanza structure with no extra attributes.Thanks in advance.

标签: xmppejabberdstrophe.js

解决方案


这是正确的。它们看起来一样。MAM 存储仅存储“消息”节的提要,包括带有正文的消息、状态消息等。因此,您需要获取此提要,然后在客户端进行后处理-获取带有正文的消息,然后获取状态并将状态映射到他们的消息。然后才向最终用户显示处理后的数据。

不是一个非常干净的方法,但这就是 MAM 的工作方式


推荐阅读