librelist archives

« back to archive

offline message

offline message

From:
Ankit Bhootra
Date:
2014-05-29 @ 06:13
Hi JC,

 

I want to show counter of offline message when user come online, just after
the name of roster appears in main control box. i put that issue on github
and you replied there is no method there in library.

 

I made a function to show number of offline message for each user and to
show the counter just after the roster name

 

Now, the problem is, from where I have to call that function, I am trying to
call that function inside onconnected method but failed.

 

This method is working very fine if put some alert inside that, but then
contact are not updating to online, so please help me from where should I
have to call that method. so that offline message counter can be appear.

 

 

Thanks

 

offline message

From:
Ankit Bhootra
Date:
2014-05-29 @ 06:16
Hi JC,

 

I want to show counter of offline message when user come online, just after
the name of roster appears in main control box. i put that issue on github
and you replied there is no method there in library.

 

I made a function to show number of offline message for each user and to
show the counter just after the roster name

 

Now, the problem is, from where I have to call that function, I am trying to
call that function inside onconnected method but failed.

 

This method is working very fine if put some alert inside that, but then
contact are not updating to online, so please help me from where should I
have to call that method. so that offline message counter can be appear.

Below is my function code, don't be confused as I made necessary template to
show counter after roster name inside 'dd' tag.

 

this.offlinealert=function(){

            alert();

          var iq=$iq({type: 'get',from:this.connection.jid}).c('query',
{xmlns:
'http://jabber.org/protocol/disco#items'},{node:'http://jabber.org/protocol/
offline'});

            converse.connection.sendIQ(iq,function(stanza){

               var test=new XMLSerializer().serializeToString(stanza);

               var count = stanza.getElementsByTagName('item').length;

               var id=stanza.getAttribute('id');

               for(var i=0;i<count;i++){

                    //alert(i);

                    var node =
stanza.getElementsByTagName('item')[i].getAttribute('node');

                    var name_id =
"user_"+stanza.getElementsByTagName('item')[i].getAttribute('name').split("@
")[0].split("-")[1];

                    //alert(name_id);

                    var offline=$iq({type: 'get',id:'view1'}).c('offline',
{xmlns:
'http://jabber.org/protocol/offline'}).c('item',{action:'view'},{node:node})
;

                    converse.connection.sendIQ(offline);

                    var counter=$("#"+name_id).text();

                    counter++;

                    //alert('counter-'+counter);

                    $("#"+name_id).text(counter);

 
$("#"+name_id).parent('.offline-message-alert').css('display','inline-block'
);                     

                          

                        

                    /*var offline_remove=$iq({type:
'set',id:'remove1'}).c('offline', {xmlns:
'http://jabber.org/protocol/offline'}).c('item',{action:'remove'},{node:node
});

 
converse.connection.sendIQ(offline_remove,function(reply){

                        //var temp=new
XMLSerializer().serializeToString(reply);

                            //alert(temp);

                        });*/  

               }

            });      

        };

 

 

Thanks

Re: [conversejs] offline message

From:
Jc Brand
Date:
2014-05-30 @ 12:45
Hi Ankit

To do this properly you have to conform to the way Converse.js does things.

Converse.js models its data in an object orientated way using Backbone.js.

For example, each message you receive is a distinct object, as is each roster
contact and each chat box.

The objects are of type Backbone.Model.

Then we have "views" of type Backbone.View which are responsible for
representing these objects in the user interface.

So usually each object has a corresponding view. The view keeps track of any
changes made to the object and will then automatically update the HTML that it
is responsible for, to display the new state.

For example, if a roster contact changes his name, the Backbone.Model's
"fullname" attribute is changed.

The corresponding view immediately knows about this through its event listener
and will update its HTML to show the new full name in the contacts roster.

So, if you want to show offline messages next to a contact's name in your
roster, you have to:

1. Add a new attribute to the RosterItem backbone.Model.
2. Update the view to be aware of this attribute and change the HTML if the
attribute changes.
3. Do the service discovery request to get offline messages.
4. For each roster contact, store the offline messages in his Backbone.Model.

Now about #3. That corresponds roughly to the code that you posted, but that
code doesn't follow the above explained paradigm and is therefore out of place
and wrong.

Converse.js already does service discovery.
See here: https://github.com/jcbrand/converse.js/blob/master/converse.js#L3316

So you must extend that Backbone.Model to also check for offline messages.
And then when you get the offline messages, modify the RosterItem models and
then let their views update accordingly.

That's the right way to do it.

I hope once you've done this you'll make a pull request and contribute the code
back to the rest of the us.

Regards
JC


On Thu, May 29, 2014 at 11:46:58AM +0530, Ankit Bhootra wrote:
>    Hi JC,
> 
>    I want to show counter of offline message when user come online, just
>    after the name of roster appears in main control box. i put that issue on
>    github and you replied there is no method there in library.
> 
>    I made a function to show number of offline message for each user and to
>    show the counter just after the roster name
> 
>    Now, the problem is, from where I have to call that function, I am trying
>    to call that function inside onconnected method but failed.
> 
>    This method is working very fine if put some alert inside that, but then
>    contact are not updating to online, so please help me from where should I
>    have to call that method. so that offline message counter can be appear.
> 
>    Below is my function code, don’t be confused as I made necessary template
>    to show counter after roster name inside ‘dd’ tag.
> 
> 
>    this.offlinealert=function(){
> 
>                alert();
> 
>              var iq=$iq({type: 'get',from:this.connection.jid}).c('query',
>    {xmlns:
>    
'http://jabber.org/protocol/disco#items'},{node:'http://jabber.org/protocol/offline'});
> 
>                converse.connection.sendIQ(iq,function(stanza){
> 
>                   var test=new XMLSerializer().serializeToString(stanza);
> 
>                   var count = stanza.getElementsByTagName('item').length;
> 
>                   var id=stanza.getAttribute('id');
> 
>                   for(var i=0;i<count;i++){
> 
>                        //alert(i);
> 
>                        var node =
>    stanza.getElementsByTagName('item')[i].getAttribute('node');
> 
>                        var name_id =
>    
"user_"+stanza.getElementsByTagName('item')[i].getAttribute('name').split("@")[0].split("-")[1];
> 
>                        //alert(name_id);
> 
>                        var offline=$iq({type: 'get',id:'view1'}).c('offline',
>    {xmlns:
>    'http://jabber.org/protocol/offline'}).c('item',{action:'view'},{node:node});
> 
>                        converse.connection.sendIQ(offline);
> 
>                        var counter=$("#"+name_id).text();
> 
>                        counter++;
> 
>                        //alert('counter-'+counter);
> 
>                        $("#"+name_id).text(counter);
> 
>                        
>    
$("#"+name_id).parent('.offline-message-alert').css('display','inline-block');                    
> 
>                              
> 
>                           
> 
>                        /*var offline_remove=$iq({type:
>    'set',id:'remove1'}).c('offline', {xmlns:
>    
'http://jabber.org/protocol/offline'}).c('item',{action:'remove'},{node:node});
> 
>                       
>    converse.connection.sendIQ(offline_remove,function(reply){
> 
>                            //var temp=new
>    XMLSerializer().serializeToString(reply);
> 
>                                //alert(temp);
> 
>                            });*/ 
> 
>                   }
> 
>                });     
> 
>            };
> 
>    Thanks