Subject: Adding to and fetching Privacy Lists
I'm trying to add privacy functionality to my client, but it doesn't seem to be creating the entries in the server's database. After searching the forums I see that I first need to have an active list. To accomplish this I get the lists after connecting to the server. If the list of lists is null I attempt to add a list called IgnoreList (the _ignoreList variable's const string)
This doesn't seem to be working. Do I need actual entries in the list to successfully create it? If so then why does my function to add/remove a person from the privacy list not seem to work either?
//initialize connection settings
private void setXMPPClient(string jid, string pass)
{
_friends = new HashSet<string>();
_friends.Clear();
_username = new Jid(jid);
_password = pass;
_xmppCon = new XmppClientConnection();
_xmppCon.Server = _domain;
_xmppCon.ConnectServer = _connectServer;
_xmppCon.Username = _username.User;
_xmppCon.Password = _password;
_xmppCon.Resource = null;
_xmppCon.Port = 5222;
_xmppCon.UseSSL = false;
_xmppCon.AutoResolveConnectServer = true;
_xmppCon.UseCompression = false;
_xmppCon.KeepAliveInterval = 60;
_xmppCon.AutoPresence = true;
_xmppCon.AutoRoster = true;
_privacyMan = new agsXMPP.protocol.iq.privacy.PrivacyManager(_xmppCon);
}
//called to actually connect after setting the settings
public void Connect(onConnect connectDelegate)
{
_onConnect = connectDelegate;
if (!_connected)
{
_xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage);
_xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
_xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
_xmppCon.OnAuthError += new XmppElementHandler(xmppCon_OnAuthError);
_xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence);
_xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
_xmppCon.Open();
}
}
//called after logged in
private void xmppCon_OnLogin(object sender)
{
_connected = true;
_privacyMan.GetLists(new IqCB(getListsCallback),null);
_onConnect();
}
//see if we have any privacy lists for this user
private void getListsCallback(object sender, IQ iq, object data)
{
agsXMPP.protocol.iq.privacy.List lists = iq.Query as agsXMPP.protocol.iq.privacy.List;
if (lists == null)
{
agsXMPP.protocol.iq.privacy.List l = new agsXMPP.protocol.iq.privacy.List();
_privacyMan.AddList(_ignoreList, l.GetItems(), getListsCallbackCallback, null);
}
else
{
_privacyMan.ChangeDefaultList(_ignoreList);
_privacyMan.ChangeActiveList(_ignoreList);
}
}
//IgnoreList created, now set it as default and active
private void getListsCallbackCallback(object sender, IQ iq, object data)
{
_privacyMan.ChangeDefaultList(_ignoreList);
_privacyMan.ChangeActiveList(_ignoreList);
}
private void setXMPPClient(string jid, string pass)
{
_friends = new HashSet<string>();
_friends.Clear();
_username = new Jid(jid);
_password = pass;
_xmppCon = new XmppClientConnection();
_xmppCon.Server = _domain;
_xmppCon.ConnectServer = _connectServer;
_xmppCon.Username = _username.User;
_xmppCon.Password = _password;
_xmppCon.Resource = null;
_xmppCon.Port = 5222;
_xmppCon.UseSSL = false;
_xmppCon.AutoResolveConnectServer = true;
_xmppCon.UseCompression = false;
_xmppCon.KeepAliveInterval = 60;
_xmppCon.AutoPresence = true;
_xmppCon.AutoRoster = true;
_privacyMan = new agsXMPP.protocol.iq.privacy.PrivacyManager(_xmppCon);
}
//called to actually connect after setting the settings
public void Connect(onConnect connectDelegate)
{
_onConnect = connectDelegate;
if (!_connected)
{
_xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage);
_xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
_xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
_xmppCon.OnAuthError += new XmppElementHandler(xmppCon_OnAuthError);
_xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence);
_xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
_xmppCon.Open();
}
}
//called after logged in
private void xmppCon_OnLogin(object sender)
{
_connected = true;
_privacyMan.GetLists(new IqCB(getListsCallback),null);
_onConnect();
}
//see if we have any privacy lists for this user
private void getListsCallback(object sender, IQ iq, object data)
{
agsXMPP.protocol.iq.privacy.List lists = iq.Query as agsXMPP.protocol.iq.privacy.List;
if (lists == null)
{
agsXMPP.protocol.iq.privacy.List l = new agsXMPP.protocol.iq.privacy.List();
_privacyMan.AddList(_ignoreList, l.GetItems(), getListsCallbackCallback, null);
}
else
{
_privacyMan.ChangeDefaultList(_ignoreList);
_privacyMan.ChangeActiveList(_ignoreList);
}
}
//IgnoreList created, now set it as default and active
private void getListsCallbackCallback(object sender, IQ iq, object data)
{
_privacyMan.ChangeDefaultList(_ignoreList);
_privacyMan.ChangeActiveList(_ignoreList);
}
This doesn't seem to be working. Do I need actual entries in the list to successfully create it? If so then why does my function to add/remove a person from the privacy list not seem to work either?
public void ignore(string username, bool ignore)
{
_ignore = ignore;
_ignoree = username;
_privacyMan.GetList(_ignoreList, new IqCB(ignoreCallback), null);
}
private void ignoreCallback(object sender, IQ iq, object data)
{
bool createit = false;
agsXMPP.protocol.iq.privacy.List list = iq.Query as agsXMPP.protocol.iq.privacy.List;
if (list == null)
{
createit = true;
list = new agsXMPP.protocol.iq.privacy.List(_ignoreList);
}
agsXMPP.protocol.iq.privacy.Item item = new agsXMPP.protocol.iq.privacy.Item();
item.Type = agsXMPP.protocol.iq.privacy.Type.jid;
item.Val = createJid(_ignoree);
item.Order = 1;
item.Action = (_ignore) ? agsXMPP.protocol.iq.privacy.Action.deny : agsXMPP.protocol.iq.privacy.Action.allow;
item.Stanza = agsXMPP.protocol.iq.privacy.Stanza.Message | agsXMPP.protocol.iq.privacy.Stanza.IncomingPresence | agsXMPP.protocol.iq.privacy.Stanza.OutgoingPresence;
list.AddItem(item);
if (createit)
{
_privacyMan.AddList(_ignoreList, list.GetItems());
_privacyMan.ChangeActiveList(_ignoreList);
_privacyMan.ChangeDefaultList(_ignoreList);
}
else
{
_privacyMan.UpdateList(_ignoreList, list.GetItems());
}
}
{
_ignore = ignore;
_ignoree = username;
_privacyMan.GetList(_ignoreList, new IqCB(ignoreCallback), null);
}
private void ignoreCallback(object sender, IQ iq, object data)
{
bool createit = false;
agsXMPP.protocol.iq.privacy.List list = iq.Query as agsXMPP.protocol.iq.privacy.List;
if (list == null)
{
createit = true;
list = new agsXMPP.protocol.iq.privacy.List(_ignoreList);
}
agsXMPP.protocol.iq.privacy.Item item = new agsXMPP.protocol.iq.privacy.Item();
item.Type = agsXMPP.protocol.iq.privacy.Type.jid;
item.Val = createJid(_ignoree);
item.Order = 1;
item.Action = (_ignore) ? agsXMPP.protocol.iq.privacy.Action.deny : agsXMPP.protocol.iq.privacy.Action.allow;
item.Stanza = agsXMPP.protocol.iq.privacy.Stanza.Message | agsXMPP.protocol.iq.privacy.Stanza.IncomingPresence | agsXMPP.protocol.iq.privacy.Stanza.OutgoingPresence;
list.AddItem(item);
if (createit)
{
_privacyMan.AddList(_ignoreList, list.GetItems());
_privacyMan.ChangeActiveList(_ignoreList);
_privacyMan.ChangeDefaultList(_ignoreList);
}
else
{
_privacyMan.UpdateList(_ignoreList, list.GetItems());
}
}
AndyGear
Show profile
Link to this post
