📄 rostermanager.cs
字号:
using System;
using System.IO;
using System.Xml;
using System.Threading;
using gowk.core.packets;
using gowk.core.packets.querys;
using gowk.net.Sockets;
using gowk.net;
namespace gowk.core.managers
{
/// <summary>
/// unavailable -- Signals that the entity is no longer available for communication.
/// subscribe -- The sender wishes to subscribe to the recipient's presence.
/// subscribed -- The sender has allowed the recipient to receive their presence.
/// unsubscribe -- The sender is unsubscribing from another entity's presence.
/// unsubscribed -- The subscription request has been denied or a previously-granted subscription has been cancelled.
/// probe -- A request for an entity's current presence; SHOULD be generated only by a server on behalf of a user.
/// error -- An error has occurred regarding processing or delivery of a previously-sent presence stanza.
/// </summary>
// public enum SubscribeType{unavailable,subscribe,subscribed,unsubscribe,unsubscribed,probe,error}
/// <summary>
/// away -- The entity or resource is temporarily away.
///chat -- The entity or resource is actively interested in chatting.
///dnd -- The entity or resource is busy (dnd = "Do Not Disturb").
///xa -- The entity or resource is away for an extended period (xa = "eXtended Away").
/// </summary>
/// <summary>
/// MessageManager 的摘要说明。
/// </summary>
public class RosterManager:ManagerBase
{
public event JabberEventHandler
RosterReceived,GetRosterResult;
public RosterGroupCollection groups=new RosterGroupCollection();
public RosterManager():base()
{
}
public RosterManager(JabberClient jc):base(jc)
{
}
protected internal override bool OnMessage(Packet pack)
{
if(!(pack is IQ))return false;
IQ iq=(IQ)pack;
if(!(iq.Query is RosterQuery))return false;
RosterQuery q=(RosterQuery)iq.Query;
if(iq.Type==PacketType.result)
{
if(this.RosterReceived!=null)
{
this.Invoke(this.RosterReceived,new object[]{new JabberEventArgs(pack)});
}
}
return true;
}
public void AddContact(string jid,string name,JabberCallBack dlgt,int timeout)
{
this.ChangeGroup(jid,name,null,dlgt,timeout);
}
public void AddContact(string jid,string name,string group,JabberCallBack dlgt,int timeout)
{
this.ChangeGroup(jid,name,group,dlgt,timeout);
}
public void ChangeGroup(string jid,string name,string group,JabberCallBack dlgt,int timeout)
{
IQ iq=new IQ();
iq.Type=PacketType.set;
iq.ID=IDGenerator.NewID;
Item item=new Item();
item.Name=name;
item.Jid=jid;
item.Group=group;
RosterQuery query=new RosterQuery();
query.Items=new Item[]{item};
iq.Query=query;
this.Send(iq,dlgt,timeout);
}
public void RemoveContact(string jid,JabberCallBack dlgt,int timeout)
{
Item item=new Item();
item.Jid=jid;
item.Subscription=Subscription.remove;
RosterQuery query=new RosterQuery();
query.Items=new Item[]{item};
IQ iq=new IQ();
iq.Type=PacketType.set;
iq.ID=IDGenerator.NewID;
iq.Query=query;
this.Send(iq,dlgt,timeout);
}
public void GetRoster()
{
RosterQuery query=new RosterQuery();
IQ iq=new IQ();
iq.Type=PacketType.get;
iq.ID=IDGenerator.NewID;
iq.Query=query;
this.Send(iq,new JabberCallBack(this.OnGetRoster),20000);
}
private void OnGetRoster(JabberEventArgs a)
{/*
if(e.ReplyPacket==null)return;//time out
IQ iq=(IQ)e.ReplyPacket;
// if(iq.Type==PacketType.error){return;}//error handing
if(iq.Type!=PacketType.result)return;
if(iq.Query==null)return;//error???
RosterQuery rq=(RosterQuery)iq.Query;
if(rq.Items==null)return;
foreach(Item itm in rq.Items)
{
string groupname=itm.Group;
if(groupname==null||groupname.Trim()==string.Empty)
{
groupname="未分组";
}
else
{
groupname=groupname.Trim();
}
RosterGroup group=null;
if(this.groups.ContainsKey(itm.tr))
{
group=this.groups[groupname];
}
else
{
group=new RosterGroup(group);
this.groups.Add(group.Name,group);
}
if(group.Items.ContainsKey(itm.Jid.Trim()))
{
group
}
}
*/
if(this.GetRosterResult!=null)
this.Invoke(this.GetRosterResult,new object[]{a});
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -