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

Conversation

singh1114
Copy link

@singh1114 singh1114 commented Jan 9, 2017

@sualko sualko added the WIP label Jan 9, 2017
singh1114 and others added 12 commits January 11, 2017 17:09
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);
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.

/*
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.

???

/*
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.

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")){
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.

//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.

local storage removed

extra comments removed
@singh1114
Copy link
Author

I can't get anything on the sorting of the messages. Please help!

@sualko
Copy link
Member

sualko commented Feb 6, 2017

If there is no sorting you have to implement it.

@singh1114
Copy link
Author

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.

@sualko
Copy link
Member

sualko commented Feb 8, 2017

I would tweak the _postMessage function to work in a similar fashion than jsxc.gui.roster.insert.

@skyfox675
Copy link

skyfox675 commented Feb 8, 2017

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!

@sualko
Copy link
Member

sualko commented Feb 8, 2017

@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.
@singh1114
Copy link
Author

@sualko Can you check the sortMessages function. Have I done it correctly?

},

sortMessages: function(message){
var messageArray = jsxc.options.allMessages;
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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;
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
Author

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.

Copy link
Member

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: [],
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

Please suggest something.

@sualko
Copy link
Member

sualko commented Feb 20, 2017

Have I done it correctly?

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.

@sualko
Copy link
Member

sualko commented Feb 20, 2017

Maybe you should start with some simpler tasks, like our new starter issues, to get familiar with the code.

@singh1114
Copy link
Author

singh1114 commented Feb 20, 2017

How about #341...?

@sualko
Copy link
Member

sualko commented Mar 16, 2017

I think we close this pr. Thanks for your effort.

@sualko sualko closed this Mar 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

See complete history (XEP-0313)
4 participants