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
Conversation
It adds some example code to fetch the message archive. It also discusses the general policy to be followed.
All the messages are now in the chatbox. Lot of work is still needed Make the use of rsm is still not made. Bower.json file is changed to so that the file is taken from strophe library. getHistory function is run when the GUI file in initWindow function
Also, the message structure in the comments which shows the structure of the message that we recieve when request is sent to the server
@@ -2360,6 +2360,7 @@ jsxc.gui.window = { | |||
*/ | |||
open: function(bid) { | |||
var win = jsxc.gui.window.init(bid); | |||
jsxc.xmpp.mam.getHistory(bid); |
There was a problem hiding this comment.
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
.
/* | ||
To include the whole functionality of strophe-plugin we used self | ||
*/ | ||
var self = jsxc.xmpp.conn.mam; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
/* | ||
To include the whole functionality of strophe-plugin we used self | ||
*/ | ||
var self = jsxc.xmpp.conn.mam; |
There was a problem hiding this comment.
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
/* | ||
Check the direction of the message i.e. In which direction messages are exchanged. | ||
*/ | ||
if(bid === $(message).find("forwarded message").attr("to")){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/jsxc.lib.xmpp.mam.js
Outdated
//console.log(message); | ||
//console.log(mamUid); | ||
|
||
jsxc.storage.setUserItem('msg', mamUid, msg); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
local storage removed extra comments removed
I can't get anything on the sorting of the messages. Please help! |
If there is no sorting you have to implement it. |
I have a doubt up here. I know the postMessage function can handle a single message at a time. So, how can I sort a single message?( Please tell me if I am wrong) Also, used a logic like this.... I tweaked the code of getHistory function such that it can whenever a user clicked on the someone from the roster list, all the messages are stored in a list and at the end, they are transferred to the postMessage function. I wasn't able to get the required output but I want to ask is it the right way of solving the problem? Another way is to create a function for sorting and when all the messages are stored in a data structure by the function getHistory they can be passed to that sorting function and finally they can be passed one by one to the postMessage. Also if someone can use the code written by me and see if the messages of MUC were retrieved or not it would be great. |
I would tweak the |
Quick feature question: Are there plans to add an option either in settings (global) or on a per conversation/chat basis to set history (On | Off | Server Default | Recipient Setting)? This is a very nice feature, not sure the difficulty required to implement, just thought I would ask. Thanks! |
@skyfox675 Thanks for your request. We will keep this in mind. |
A function named sortMessages is made to sort the messages. A empty list is used for the purpose
The data structure is again emptied so that the place is made for new messages to come in.
@sualko Can you check the sortMessages function. Have I done it correctly? |
}, | ||
|
||
sortMessages: function(message){ | ||
var messageArray = jsxc.options.allMessages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you save messages in the options object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to do it in some other ways. For that, I initialized an empty data structure in a function. So whenever the function ran it again got initialized to empty.
For example: say I am declaring a variable in sortMessage function.
sortMessages: function(message) { var messageArray = [] }
So whenever the function ran it again got initialized to empty deleting all the messages.
If you have any other idea please share.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There has to be another solution, because this is 👎.
firstMessage = true; | ||
} | ||
if (isNaN(message.stamp)) { | ||
length = messageArray.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when I working with the messages I found that the last incoming message is not a real message it is just a system message which says that all messages have been encountered. I also found that the stamp of the last message returns NaN. So I am using that to check few things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, length was defined a couple of lines above and I think it is never changed.
* Declare empty list to be used for sorting the messages | ||
* | ||
*/ | ||
allMessages: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options object is only for options and not arbitrary data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please suggest something.
I don't think so. It would be probably more elegant if you would handle the sorting at jsxc.lib.gui.js#L2803. We also have to think about delayed messages, because with the new sorting function these will be maybe not visible to the user. |
Maybe you should start with some simpler tasks, like our new starter issues, to get familiar with the code. |
How about #341...? |
I think we close this pr. Thanks for your effort. |
fix #150
Ref: http://xmpp.org/extensions/xep-0313.html