Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
johnm60 #1
Member since Jun 2010 · 32 posts
Group memberships: Members
Show profile · Link to this post
Subject: Roster versioning support
Hi

Is there any Matrix inbuilt support for versioned rosters? Or do I have to set AutoRoster to false and construct my own jabber:iq:roster with a version attribute and handle it all manually from then onwards (including the persistence of the response)?

Thanks
John
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
There is a version property in the roster class. I made also some more improvements for roster versioning since the latest release. I will upload a new binary later today.
You have to set AutoRoster to false. Then start the roster request with your cached version on your own.

Alex
Avatar
johnm60 #3
Member since Jun 2010 · 32 posts
Group memberships: Members
Show profile · Link to this post
Thanks for the prompt reply Alex.

One more question (sorry). How do I find out the version of the roster so that I can persist this? To clarify, if I set AutoRoster to False, I can request a roster with:

            Matrix.Xmpp.Client.RosterIq riq = new Matrix.Xmpp.Client.RosterIq();
            riq.Type = Matrix.Xmpp.IqType.get;
            xmppClient.Send(riq);

This will trigger off a series of OnRosterItem events that I can then use to build up a roster locally.

void xmppClient_OnRosterItem(object sender, Matrix.Xmpp.Roster.RosterEventArgs e)
{
            roster.AddRosterItem(e.RosterItem);
}

I can then persist this for later with:

            System.Xml.XmlTextWriter wr = new System.Xml.XmlTextWriter("roster.xml",Encoding.UTF8);
            roster.WriteTo(wr);
            wr.Close();

The problem is that I now do not know the roster version from the events I have received (I know that the XML stanza from the server has this as an attribute). So how can I glean the version number, so that I can set it before I persist the roster? Or am I looking at this in completely the wrong way?

Thanks
John
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
with the current version you can't get it in the OnRosterItem event.

For now i think the best is not to use the events and use an IqFilter to send the packet. This gives you the complete stanza in your callback then.
If it helps you I can add a version property to the RosterEventArgs.
Let me know what you think?

Alex
Avatar
johnm60 #5
Member since Jun 2010 · 32 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex

I think I got there:
private void requestRosterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Matrix.Xmpp.Client.RosterIq riq = new Matrix.Xmpp.Client.RosterIq();
            riq.Type = Matrix.Xmpp.IqType.get;
            xmppClient.IqFilter.SendIq(riq, RosterResponse);
        }

        private void RosterResponse(object sender, IqEventArgs e)
        {
            var iq = e.Iq;

            if (iq.Type == Matrix.Xmpp.IqType.result)
            {
                var ros = iq.Element<Matrix.Xmpp.Roster.Roster>();
                System.Xml.XmlTextWriter wr = new System.Xml.XmlTextWriter("roster2.xml", Encoding.UTF8);
                ros.WriteTo(wr);
                wr.Close();
               
            }
            else if (iq.Type == IqType.error)
            {
                System.Diagnostics.Debug.WriteLine("RosterResponse ERROR: " + e);
            }
        }

Thanks
John
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
yes, and ros.Version should give you the version number of your roster. You have to include this version number also in your request when you want to use versioning.

  1. /// <summary>
  2. /// Request the roster fro the server when using roster versioning
  3. /// </summary>
  4. /// <param name="version"></param>
  5. public void RequestRoster(string version)
  6. {
  7.     var riq = new RosterIq(IqType.get) {Roster = {Version = version}};
  8.     Send(riq);
  9. }
Avatar
Alex #7
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
just uploaded a new version. The RosterEventsArgs have now a version property. And you have to members in XmppClient to Request the roster. One of them accepts your version as string.

Alex
Avatar
johnm60 #8
Member since Jun 2010 · 32 posts
Group memberships: Members
Show profile · Link to this post
Thanks. I will pick that up and try it.

On a similar vein, I cannot work out how to load a roster object from a file I previously persisted to disc. I have looked at the CreateReader() method, but I cannot work out how to use it.

As you may have guessed, my .net skills are a little shaky.

Regards
John
Avatar
Alex #9
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you have to use the MatriX classes to load it. Otherwise you are not able to cast it to a Roster object.
  1. var el = XmppXElement.LoadXml(xml);
  2. if (el is Roster)
  3.    Roster rost = el as Roster;
Alex
Avatar
johnm60 #10
Member since Jun 2010 · 32 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex

Just tried this and tried the new client method and it now works.


Thanks
John
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: