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.
This is right. They will look the same. MAM storage just stores a feed of ‘messages’ stanzas including messages with body, status messages etc. So you need to get this feed and then post-process in on the client side - get messages with body, then get statuses and map statuses to their messages. And only then show processed data to end user.
Not a very clean approach, but this is how MAM works