📄 conversationmanager.cs
字号:
namespace Imps.Client.Core
{
using Imps.Base.Sipc;
using Imps.Client;
using Imps.Client.Base;
using Imps.Client.Base.Comm;
using Imps.Client.Resource;
using Imps.Client.Utils;
using Imps.Common;
using Imps.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Xml;
public class ConversationManager : UserItemBase
{
private List<Imps.Client.Core.Conversation> _conversations;
private static string _scOptionString = null;
public static string[] ConversationNeedProperty = new string[] { "name", "nickname", "Portrait", "mobile-no" };
public static object MessageSyncObject = new object();
public event EventHandler<FindConversationFormEventArgs> FindConversationForm;
public event EventHandler<ImpsNotifyEventArgs> ReceiveSystemMessage;
public ConversationManager(Imps.Client.Core.User owner) : base(owner)
{
this._conversations = new List<Imps.Client.Core.Conversation>();
owner.SipRequestReceived += new EventHandler<SipRequestReceivedEventArgs>(this, (IntPtr) this.Owner_MessageReceived);
owner.StatusChanged += new EventHandler<UserSatusChangedEventArgs>(this, (IntPtr) this.owner_StatusChanged);
}
internal void AsyncDoLogout(AsyncBizOperation op)
{
this.Clear();
Imps.Client.Core.User.TryCallReceiveMessageOnOp(op);
}
private void AsyncSendKeepAlive(object sender, EventArgs e)
{
try
{
bool flag = false;
List<Imps.Client.Core.Conversation>.Enumerator enumerator = this._conversations.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
using (IEnumerator<Dialog> enumerator2 = enumerator.get_Current().Dialogs.GetEnumerator())
{
while (enumerator2.MoveNext())
{
Dialog dialog = enumerator2.get_Current();
bool flag2 = false;
using (IEnumerator<ShareContent> enumerator3 = dialog.ShareContents.GetEnumerator())
{
while (enumerator3.MoveNext())
{
ShareContent content = enumerator3.get_Current();
if ((content.Transmittype == ShareContentTransmitType.Relay) || (content.Transmittype == ShareContentTransmitType.P2P))
{
flag = true;
flag2 = true;
goto Label_007E;
}
}
}
Label_007E:
if (flag2)
{
dialog.AsyncKeepAlive();
}
}
continue;
}
}
}
finally
{
enumerator.Dispose();
}
if (!flag)
{
GlobalTimer.Unregister(new EventHandler(this.AsyncSendKeepAlive));
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
}
private void CancelInvite(SipRequest req)
{
SipRequest msg = base.Owner.CreateSipRequest("C", req.Message.CallId.CallId, req.Message.CSeq.Number);
msg.Message.AddHeader(new SipcToHeader(req.Message.From.Value));
base.SendSipMessage(msg);
}
public void Clear()
{
this.CloseAllConversation();
}
private void CloseAllConversation()
{
for (int i = this.Conversations.get_Count() - 1; i >= 0; i--)
{
this.Conversations.get_Item(i).Close();
}
}
internal void DoReceiveInvite(SipRequest req)
{
if (req.Message.Body.IndexOf("m=message ") != -1)
{
string to = req.Message.From.Value;
Imps.Client.Core.Conversation conv = null;
bool flag = to.ToUpper().StartsWith("SIP:TG");
for (int i = this._conversations.get_Count() - 1; i >= 0; i--)
{
Imps.Client.Core.Conversation conversation2 = this._conversations.get_Item(i);
if (conversation2.CallId == req.Message.CallId.CallId)
{
if (flag)
{
conv = conversation2;
}
else
{
this._conversations.Remove(conversation2);
}
}
}
Dialog item = null;
if (conv == null)
{
if (flag)
{
conv = this.OpenConversation(to, new long?(req.Message.CallId.CallId), false, new List<Imps.Client.Core.Contact>());
}
else
{
Imps.Client.Core.Contact contact = base.Owner.ContactList.FindOrCreateContact(req.Message.From.Value, new AsyncBizOperation());
conv = this.OpenConversation(to, new long?(req.Message.CallId.CallId), false, contact);
}
item = conv.CurrentDialog;
}
else if (((conv.CurrentDialog != null) && (conv.CurrentDialog.CallId == req.Message.CallId.CallId)) && ((conv.CurrentDialog.To == null) || (conv.CurrentDialog.To == to)))
{
item = conv.CurrentDialog;
if (item.To == null)
{
item.To = to;
}
}
else
{
item = new Dialog(conv);
item.To = to;
conv.Dialogs.Add(item);
}
item.IsMulitiConversation = flag;
item.DoReceiveInite(req);
}
}
private void DoReceiveMessage(SipRequest req)
{
string text2;
if (((req.Message.Event != null) && ((text2 = req.Message.Event.Value) != null)) && ((text2 != "be-matched") && (text2 == "system-message")))
{
this.DoReceiveSystemMessage(req);
}
else if (this.FindConversationByCallId(req) == null)
{
Imps.Client.Core.Conversation conversation = this.FindConversationByUri(req);
if ((conversation != null) && (conversation.CurrentDialog != null))
{
conversation.CurrentDialog.DoReceiveMessage(req);
}
else
{
string uriString = req.Message.From.Value;
IicUri uri = new IicUri(uriString);
if ((((uri.Type != IicUriType.TempGroup) && (uri.Type != IicUriType.Unknown)) && (uri.Type != IicUriType.PersonalGroup)) && (uriString != base.Owner.Uri.Raw))
{
Imps.Client.Core.Contact contact = base.Owner.ContactList.FindOrCreateContact(uriString, new AsyncBizOperation());
if (contact != null)
{
bool invite = contact.Presence.IsOnline;
this.OpenConversation(contact.Uri.Raw, new long?(req.Message.CallId.CallId), invite, contact).CurrentDialog.DoReceiveMessage(req);
}
}
}
}
}
private void DoReceiveSystemMessage(SipRequest req)
{
try
{
if (req.Message.ContentType.Value == "text/xml")
{
string body = req.Message.Body;
FuncDispatcher.InvokeEventHandlerInUiThread<ImpsNotifyEventArgs>(this, this.ReceiveSystemMessage, new ImpsNotifyEventArgs("系统消息", body));
}
SipcRequest message = req.Message;
SipcResponse sipcResponse = new SipcResponse(200, "OK");
if (message.From != null)
{
sipcResponse.AddHeader(req.Message.From);
}
sipcResponse.AddHeader(message.CallId);
sipcResponse.AddHeader(message.CSeq);
SipResponse msg = new SipResponse(sipcResponse, req);
ISipConnection sipConnection = base.Owner.SipConnection;
if (sipConnection != null)
{
sipConnection.Send(msg);
}
else
{
SipMessageHelper.RaiseSendMessageFailed(msg, null, StringTable.ClientCommLayerString.ConnectionClosed, null);
}
}
catch
{
}
}
private Imps.Client.Core.Conversation FindConversationByCallId(SipRequest req)
{
lock (this._conversations)
{
List<Imps.Client.Core.Conversation>.Enumerator enumerator = this._conversations.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
Imps.Client.Core.Conversation conversation = enumerator.get_Current();
if (((conversation.CallId == req.Message.CallId.CallId) && (conversation.CurrentDialog != null)) && (req.Message.From.RawValue == conversation.CurrentDialog.To))
{
return conversation;
}
}
}
finally
{
enumerator.Dispose();
}
return null;
}
}
private Imps.Client.Core.Conversation FindConversationByUri(SipRequest req)
{
lock (this._conversations)
{
List<Imps.Client.Core.Conversation>.Enumerator enumerator = this._conversations.GetEnumerator();
try
{
while (enumerator.MoveNext())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -