From a071e300658fba5f80a6df4244ef1277c140e05c Mon Sep 17 00:00:00 2001 From: GoldenBIOS Date: Sun, 3 May 2026 15:02:39 +0200 Subject: [PATCH] implement ChatsService and expanded Chat models --- Models/ChatModels.cs | 31 ++++++++++++++++++++++++++++++- Services/ChatMethods.cs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Services/ChatMethods.cs diff --git a/Models/ChatModels.cs b/Models/ChatModels.cs index 3d7196b..af40dd3 100644 --- a/Models/ChatModels.cs +++ b/Models/ChatModels.cs @@ -9,6 +9,9 @@ namespace Chtn.CSharp.SDK.Models.Chat [JsonProperty("chatid")] public string ChatId { get; set; } [JsonProperty("displayName")] public string DisplayName { get; set; } [JsonProperty("latestMessage")] public LatestMessage Latest { get; set; } + [JsonProperty("icon")] public string Icon { get; set; } + [JsonProperty("isGroup")] public bool IsGroup { get; set; } + [JsonProperty("unreadCount")] public int UnreadCount { get; set; } } public class Message @@ -20,5 +23,31 @@ namespace Chtn.CSharp.SDK.Models.Chat [JsonProperty("files")] public List Files { get; set; } } - public class LatestMessage { public string Message { get; set; } public string MsgId { get; set; } } + public class LatestMessage + { + [JsonProperty("message")] public string Message { get; set; } + [JsonProperty("msgid")] public string MsgId { get; set; } + } + + public class GetChatsReq { } + + public class StartNewReq + { + [JsonProperty("targetUserId")] public string TargetUserId { get; set; } + } + + public class ToggleChatMuteReq + { + [JsonProperty("chatid")] public string ChatId { get; set; } + } + + public class GetAvailabilityReq + { + [JsonProperty("userIds")] public List UserIds { get; set; } + } + + public class GetAvailabilityResp + { + [JsonProperty("availability")] public Dictionary Availability{ get; set; } + } } \ No newline at end of file diff --git a/Services/ChatMethods.cs b/Services/ChatMethods.cs new file mode 100644 index 0000000..5d78671 --- /dev/null +++ b/Services/ChatMethods.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Chtn.CSharp.SDK.Core; +using Chtn.CSharp.SDK.Models.Chat; + +namespace Chtn.CSharp.SDK.Services +{ + public interface IChatsService + { + Task> Get(GetChatsReq req); + Task GetUserAvailability(GetAvailabilityReq req); + Task ToggleMute(ToggleChatMuteReq req); + Task StartNew(StartNewReq req); + } + + public class ChatsServiceProvider : IChatsService + { + private readonly ApiClient _apiClient; + + public ChatsServiceProvider(ApiClient apiClient) + { + _apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient)); + } + + public async Task> Get(GetChatsReq req) => + await _apiClient.PostAsync>("chat/get", req); + + public async Task GetUserAvailability(GetAvailabilityReq req) => + await _apiClient.PostAsync("chat/availability", req); + + public async Task ToggleMute(ToggleChatMuteReq req) => + await _apiClient.PostAsync("v2/chat/toggleMute", req); + + public async Task StartNew(StartNewReq req) => + await _apiClient.PostAsync("chat/startNew", req); + } +}