sstrigler / JSJaC

JavaScript Jabber Client Library
Other
295 stars 86 forks source link

Added stanzas for adding and removing groups and users from roster #65

Closed spicajames closed 8 years ago

spicajames commented 10 years ago

SetPresenceSubscription

This allows to accept subscriptions in HandleIQ you could check each contact

.
.
.
$jQuery('item',xmlDoc).each(function(i){
                    var contact =$jQuery(this)[0].getAttribute("jid");
                    var name =$jQuery(this)[0].getAttribute("name");
                    var subscription =$jQuery(this)[0].getAttribute("subscription");
                    if(subscription == "to"){
                        var roster = new JSJaCPresence();
                        var randomnumber=Math.floor(Math.random()*100001)
                        roster.setPresenceSubscription(null,contact,'subscribed','ps'+randomnumber);
                        con.send(roster, {result_handler: function(aIq, arg) {
                                var node = aIq.getQuery();
                            }});
.
.
.

SetGroup

You can add a member to a new group using something like this

//type can be 'subscribed' most of the times
            functionaddGroup(grups, contact, nick, type){
                var roster = new JSJaCIQ();
                var randomnumber=Math.floor(Math.random()*100001)
                roster.setIQ(null, 'set', 'rs'+randomnumber);
                roster.setGroup(grups,contact,nick);
                con.sendIQ(roster, {result_handler: function(aIq, arg) {
                        var roster = new JSJaCPresence();
                        var randomnumber=Math.floor(Math.random()*100001)
                        roster.setPresenceSubscription(null,contact,type,'ps'+randomnumber);
                        con.send(roster, {result_handler: function(aIq, arg) {
                                var node = aIq.getQuery();
                                alert("Result: " +aIq.xml().htmlEnc());
                            }});
                    }});
            }

RemoveRoster

You can delete a contact from a group using:

                var roster = new JSJaCIQ();
                var randomnumber=Math.floor(Math.random()*100001)
                roster.setIQ(null, 'set', 'rs'+randomnumber);
                roster.removeRoster(contact);
sstrigler commented 10 years ago

I don't want to have this in JSJaCPacket.js. This could go into some 'plugin' or 'extras' subdirectory as it's own file. But still I'd rather see such functionality as part of a whole roster management implementation than instead of just a selective part of it. It's nice to have it as a snippet though or at least as a good starting point for some higher level stuff. JSJaC itself should be kept minimalistic though.