前端实现接收发送文本消息
This commit is contained in:
+50
-44
@@ -12,26 +12,63 @@ namespace StormChatWPF
|
||||
class Chat
|
||||
{
|
||||
public static List<User> ContactsList;//联系人集合
|
||||
public static Chat chat = new Chat();
|
||||
public static Chat chat=new Chat();
|
||||
private Chat()
|
||||
{
|
||||
StormClient.OnLoginDone += HaveLogin;
|
||||
StormClient.OnGetUserListDone += GetContactsList;
|
||||
StormClient.OnMessage +=ReciveMessage;
|
||||
StormClient.OnLoginDone += OnHaveLogin;
|
||||
StormClient.OnGetUserListDone += OnGetContactsList;
|
||||
StormClient.OnMessage +=OnMessage;
|
||||
}
|
||||
internal User SetContact { get; set; }//设置当前联系人对象
|
||||
|
||||
internal static void GetContactsList(ResultHead head, User[] users)
|
||||
internal static User CurrentContact { get; set; }//设置当前联系人对象
|
||||
/// <summary>
|
||||
/// 获取联系人列表(完成后打开主窗体)
|
||||
/// </summary>
|
||||
private void OnGetContactsList(ResultHead head, User[] users)
|
||||
{
|
||||
if (head.Error != "")
|
||||
{
|
||||
MessageBox.Show("无法获取联系人列表");
|
||||
}
|
||||
else
|
||||
ContactsList =new List<User>( users);
|
||||
return;
|
||||
}//获取联系人列表
|
||||
internal void Log(string user,string password)
|
||||
}
|
||||
App.Current.Dispatcher.Invoke(
|
||||
(Action)delegate ()
|
||||
{
|
||||
ContactsList = new List<User>(users);
|
||||
MainWindow mainWindow = new MainWindow();
|
||||
mainWindow.Show();
|
||||
LogWindow.Instence.Close();
|
||||
});
|
||||
}
|
||||
private void OnHaveLogin(ResultHead head, User user)
|
||||
{
|
||||
if (head.Error == "")
|
||||
{
|
||||
User.Me = user;
|
||||
StormClient.QueueGetUserList();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请核对账号密码!");
|
||||
}
|
||||
}//登录完成
|
||||
private void OnMessage(Message message)
|
||||
{
|
||||
if (MainWindow.Instence != null)
|
||||
{
|
||||
MainWindow.Instence.ShowMessage(message);
|
||||
}
|
||||
}//接受到新消息
|
||||
|
||||
internal void SendMessage(string text,User target)
|
||||
{
|
||||
Message msg = new Message(text,target);
|
||||
Action<ResultHead> f = delegate (ResultHead head)
|
||||
{
|
||||
MainWindow.Instence.ShowMessage(msg);
|
||||
};
|
||||
StormClient.QueueSendMessage(msg,f);
|
||||
}//发送消息
|
||||
internal static void Log(string user, string password)
|
||||
{
|
||||
if (StormClient.Initialize())
|
||||
{
|
||||
@@ -45,37 +82,6 @@ namespace StormChatWPF
|
||||
MessageBox.Show("连接服务器失败!");
|
||||
}
|
||||
}//登录
|
||||
internal static void HaveLogin(ResultHead head, User user)
|
||||
{
|
||||
App.Current.Dispatcher.Invoke(
|
||||
(Action)delegate ()
|
||||
{
|
||||
if (head.Error == "")
|
||||
{
|
||||
User.Me = user;
|
||||
MainWindow userWindow = new MainWindow();
|
||||
userWindow.Show();
|
||||
LogWindow.Instence.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请核对账号密码!");
|
||||
}
|
||||
});
|
||||
}//登录完成
|
||||
internal static void ReciveMessage(Message message)
|
||||
{
|
||||
LogWindow.Instence.ShowMessage(message);
|
||||
}//接受到新消息的时候
|
||||
internal static void SendMessage(string text,User target)
|
||||
{
|
||||
// Message msg = new Message(text);
|
||||
// Action<BaseHead> f = delegate(BaseHead head)
|
||||
// {
|
||||
|
||||
// };
|
||||
// StormClient.QueueSendMessage(msg, target, f);
|
||||
// LogWindow.Instence.ShowUserMessage();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user