在 `ChatDataModel.cs` 中添加 `TimeFormatConverter` 类,用于格式化本地时间,并在 `MainWindow.xaml` 中应用该转换器。 在 `chatapi.cs` 中新增 `HistoryRequest` 和 `HistoryResponse` 类以处理历史记录请求和响应。 修改 `LoginWindow.xaml.cs` 中的数据发送方式,使用 `SendWithPrefix` 方法以支持数据压缩和长度前缀。 在 `MainWindow.xaml.cs` 中添加 `LoadHistoryMessages` 方法以加载历史消息,并在接收到响应时更新消息列表。 在 `Program.cs` 中实现数据压缩和解压缩方法,提升网络传输效率。 新增消息表和索引以支持消息存储和查询。 更新日志记录以提供更详细的操作信息和错误处理。
82 lines
2.8 KiB
C#
82 lines
2.8 KiB
C#
using System.Security.RightsManagement;
|
|
|
|
namespace chatclient.Data
|
|
{
|
|
internal class Server
|
|
{
|
|
public const string ServerUrl = "http://127.0.0.1:5001";
|
|
public const string ServerIP = "175.24.191.172";
|
|
//public const string ServerIP = "127.0.0.1";
|
|
public const int ServerPort = 52006;
|
|
}
|
|
internal class LoginData
|
|
{
|
|
public string? type { get; set; } = null;
|
|
public string? username { get; set; } = null;
|
|
public string? password { get; set; } = null;
|
|
public string? token { get; set; } = null;
|
|
}
|
|
internal class LoginResultData
|
|
{
|
|
public string? status { get; set; }
|
|
public string? message { get; set; }
|
|
public string? token { get; set; }
|
|
public string? username { get; set; }
|
|
public string? userid { get; set; } = "Unid";
|
|
}
|
|
internal class SignData
|
|
{
|
|
public string? type { get; set; } = null;
|
|
public string? username { get; set; } = null;
|
|
public string? password { get; set; } = null;
|
|
}
|
|
internal class SignResultData
|
|
{
|
|
public string? status { get; set; } = null;
|
|
public string? message { get; set; } = null;
|
|
}
|
|
internal class RegisterData
|
|
{
|
|
public string? type { get; set; }
|
|
}
|
|
internal class ChatRegisterData
|
|
{
|
|
public string? user { get; set; } = "Unnamed";
|
|
public required string userid { get; set; } = "Unid";
|
|
public string? status { get; set; } = null;
|
|
public string? message { get; set; } = null;
|
|
public string? avatar { get; set; } = null;
|
|
public MessageType? msgtype { get; set; } = MessageType.Text;
|
|
public DateTime? timestamp { get; set; } = DateTime.Now;
|
|
}
|
|
internal class ChatData
|
|
{
|
|
public required string type { get; set; } = "chat";
|
|
public required string message { get; set; } = "message";
|
|
public MessageType? msgtype { get; set; } = MessageType.Text;
|
|
public required string userid { get; set; } = "Unid";
|
|
public string? token { get; set; } = null; // 添加token字段
|
|
}
|
|
/// <summary>
|
|
/// 历史记录请求类
|
|
/// </summary>
|
|
internal class HistoryRequest
|
|
{
|
|
public string type { get; set; } = "history";
|
|
public int offset { get; set; } = 0; // 分页偏移量
|
|
public int count { get; set; } = 10; // 请求数量
|
|
public string? chat_type { get; set; } = "group"; // group/private
|
|
public string? room_id { get; set; } = "global"; // 群聊房间ID
|
|
public string? receiver_id { get; set; } = null; // 私聊接收者ID
|
|
}
|
|
|
|
/// <summary>
|
|
/// 历史记录响应类
|
|
/// </summary>
|
|
internal class HistoryResponse
|
|
{
|
|
public List<ChatRegisterData> history { get; set; } = new List<ChatRegisterData>();
|
|
public int total_count { get; set; } // 总消息数
|
|
}
|
|
}
|