Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get archived messages using StropheJs #278

Closed
Veerbhadra277 opened this issue Dec 20, 2017 · 1 comment
Closed

Get archived messages using StropheJs #278

Veerbhadra277 opened this issue Dec 20, 2017 · 1 comment

Comments

@Veerbhadra277
Copy link

I am trying to show the conversation between the two users even after the users logout and login. I mean when user1 logged out and again logged in, he should see the conversations made with the user2. I am using Ejabberd XMPP server and Strophe Js to retrive the messages.

I am using ejabberd source code version 16.2, and using following lines of code to retrieve archived messages.

    ```
                   var toJid = 'toJid' + '@' + xmpp_ServerConnection.domain;
			var fromJid = 'fromJid' + '@' + xmpp_ServerConnection.domain;
			var iq = $iq({ type: 'get', id: fromJid })
					.c('query', { xmlns: 'urn:xmpp:mam:1' })
					.c('field', { 'var': 'with' })
					.c('value')
					.t(toJid);

			xmpp_ServerConnection.sendIQ(iq, function (message) {
try {
									var id = message.querySelector('result').getAttribute('id');
									var fwd = message.querySelector('forwarded');
									var d = fwd.querySelector('delay').getAttribute('stamp');
									var msg = fwd.querySelector('message');
									var msg_data = {
										id: id,
										with:Strophe.getBareJidFromJid(msg.getAttribute('to')),
										timestamp: (new Date(d)),
										timestamp_orig: d,										
                                                                           from:Strophe.getBareJidFromJid(msg.getAttribute('from')),
										to: Strophe.getBareJidFromJid(msg.getAttribute('to')),
										type: msg.getAttribute('type'),
										body: msg.getAttribute('body'),										
                                                               message:Strophe.getText(msg.getElementsByTagName('body')[0])
									};
									archive.val(archive.val() + msg_data.from + ":" + 
                                               msg_data.message + "\n" + msg_data.to + ":" + msg_data.message + "\n");
									archive.scrollTop(archive[0].scrollHeight - archive.height());
									console.log('xmpp.history.message', msg_data.message);
								} catch (err) {
									if (typeof (err) == 'TypeError') {
										try {
											console.log(err.stack)
										} catch (err2) {
											console.log(err, err2);
										}
									}
								}
					console.log(iq);
				}
                                        },function (error) {

});

but doesn't get anything on message i got following object in the response success callback.

<iq
	xmlns="jabber:client" from="fromJid" to="fromJid" id="fromJid" type="result">
	<fin
		xmlns="urn:xmpp:mam:1" complete="false">
		<set
			xmlns="http://jabber.org/protocol/rsm">
			<first>1509351242923055</first>
			<last>1510224166687524</last>
			<count>96</count>
		</set>
	</fin>
</iq>

Can anyone help me.

@jcbrand
Copy link
Contributor

jcbrand commented Dec 20, 2017

Duplicate of strophe/strophejs-plugin-mam#7

And not relevant to core strophe.

@jcbrand jcbrand marked this as a duplicate of strophe/strophejs-plugin-mam#7 Dec 20, 2017
@jcbrand jcbrand closed this as completed Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants