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

[WIP] Message Archive Management (XEP-0313) #432

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"strophe.vcard": "https://raw.githubusercontent.com/strophe/strophejs-plugins/2f07137ad2cbeaed41650ee46373c2f44e0f263a/vcard/strophe.vcard.js",
"strophe.x": "https://raw.githubusercontent.com/strophe/strophejs-plugins/master/dataforms/src/strophe.x.js",
"strophe.mam": "https://raw.githubusercontent.com/strophe/strophejs-plugins/master/mam/strophe.mam.v0.3.js",
"strophe.rsm": "https://raw.githubusercontent.com/metajack/strophejs-plugins/master/rsm/strophe.rsm.js",
"strophe.rsm": "https://raw.githubusercontent.com/strophe/strophejs-plugins/master/rsm/strophe.rsm.js",
"strophe.chatstates": "https://raw.githubusercontent.com/strophe/strophejs-plugins/master/chatstates/strophe.chatstates.js",
"jquery-i18next": "^1.2.0",
"i18next": "^5.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/jsxc.lib.gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,7 @@ jsxc.gui.window = {
*/
open: function(bid) {
var win = jsxc.gui.window.init(bid);
jsxc.xmpp.mam.getHistory(bid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an event handler for this. I think the appropriate event would be init.window.jsxc.


jsxc.gui.window.show(bid);
jsxc.gui.window.highlight(bid);
Expand Down
2 changes: 1 addition & 1 deletion src/jsxc.lib.storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jsxc.storage = {
/**
* Prefix for localstorage
*
* @privat
* @private
*/
PREFIX: 'jsxc',

Expand Down
108 changes: 102 additions & 6 deletions src/jsxc.lib.xmpp.mam.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,111 @@
*
*/

/*jsxc.xmpp.mam = {
jsxc.xmpp.mam = {
conn: jsxc.xmpp.conn
};

jsxc.xmpp.mam.init = function(){
var self = jsxc.xmpp.mam;
self.getHistory(userid, count, before);
};*/
var self = jsxc.xmpp.conn.mam;
console.log(self);

//self has now the object of the strophe.mam
// make a call to the get history function.


//self.getHistory(userid, count, before);
};


jsxc.xmpp.mam.getHistory = function(bid) {
/*
To include the whole functionality of strophe-plugin we used self
*/
var self = jsxc.xmpp.conn.mam;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self usually points to the home namespace. In this case it would be jsxc.xmpp.mam.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I use 'this' than?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to make sure, that the connection has already be established. See e.g. jsxc.lib.xmpp.chatState.js#L17

/*
ownjid is the jid of the person who is logged in
*/
var ownjid = jsxc.xmpp.conn.jid;

// Now we are converting the jid into bid
var ownbid = jsxc.jidToBid(ownjid);


// We are calling the strophe plugin as specified by them
self.query(ownbid, {
with: bid,
before: "",
onMessage: function(message) {
/*
The message looks like this:
<message xmlns="jabber:client" from="ownbid" to="bid">
<result xmlns="urn:xmpp:mam:0" id="1485155123866746">
<forwarded xmlns="urn:xmpp:forward:0">
<message xmlns="jabber:client" from="jid from which message is sent" to="bid who recived the message" type="chat" id="1485141093744:msg">
<body>gdhjcb</body>
<request xmlns="urn:xmpp:receipts"></request>
<delay xmlns="urn:xmpp:delay" from="serverAddress" stamp="2017-01-23T03:11:43.446Z">Offline Storage</delay>
</message>
<delay xmlns="urn:xmpp:delay" from="serverAddress" stamp="2017-01-23T07:05:23.867Z"></delay>
</forwarded>
</result>
<no-store xmlns="urn:xmpp:hints"></no-store>
</message>

*/
var direction;

/*
Check the direction of the message i.e. In which direction messages are exchanged.
*/
if(bid === $(message).find("forwarded message").attr("to")){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use also the xml namespace to identify the forwarded element. See jsxc.lib.xmpp.js#L789.

Copy link
Author

@singh1114 singh1114 Jan 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always equal to "forwarded xmlns="urn:xmpp:forward:0"". What do we need to check here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future there could be an element with the same name, but different behavior.

direction = "out";
}
else{
direction = "in";
}
var timeOfMessage = $(message).find("forwarded delay").attr("stamp");
var stamp = new Date(timeOfMessage).getTime();
var msgBody = $(message).find("forwarded message body").text();
var mamUid = stamp + ":msg";
var msg = {
"_uid": mamUid,
"_received": false,
"encrypted": false,

/*
forwarded is true becuase we don't want the user to get notifications
of the old messages
*/
"forwarded": true,
/*
For stamp we pass the number of milliseconds that have been passed since
05 January, 1975
*/
"stamp": stamp,

"type": "plain",
"bid": bid,
"direction": direction,
"msg": msgBody
};

//console.log(message);
//console.log(mamUid);

jsxc.storage.setUserItem('msg', mamUid, msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. This will be removed.

//This line is not working
jsxc.gui.window.postMessage(msg);

//console.log("Message from ", $(message).find("forwarded message").attr("from"), " on ", $(message).find("forwarded delay").attr("stamp"),": ", $(message).find("forwarded message body").text() );
return true;
},
onComplete: function(response) {
console.log("Got all the messages");
console.log(response);
}
});
};

//example code to query an personal archive for conversations with
//juliet@capulet.com
Expand Down Expand Up @@ -93,5 +190,4 @@ connection.mam.query("you@example.com", {
jsxc.xmpp.conn.mam.query(jsxc.bid, q);
}
};
*/

*/