implement DMServiceProvider and Chat.DM models
This commit is contained in:
@@ -13,17 +13,108 @@ namespace Chtn.CSharp.SDK.Models.Chat.DM
|
|||||||
[JsonProperty("files")] public List<Attachment> Files { get; set; }
|
[JsonProperty("files")] public List<Attachment> Files { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DmPinMessageReq
|
public class PinnedMessage : DmMessage { }
|
||||||
|
|
||||||
|
public class GetMessagesReq
|
||||||
{
|
{
|
||||||
[JsonProperty("chatid")] public string ChatId { get; set; }
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
[JsonProperty("messageId")] public string MessageId { get; set; }
|
[JsonProperty("limit")] public string Limit { get; set; }
|
||||||
[JsonProperty("userid")] public string UserId { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DmJoinWsRoomReq
|
public class GetMessagePosReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetPinnedMessagesReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EditMessageReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
[JsonProperty("limit")] public string Limit { get; set; }
|
||||||
|
[JsonProperty("content")] public string Content { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeleteMessageReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FinishMessageReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ReadMessagesReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PinMessageReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UnpinMessageReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeleteMessagesReq
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
[JsonProperty("userId")] public string UserId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class JoinWsRoomReq
|
||||||
{
|
{
|
||||||
[JsonProperty("connId")] public string ConnId { get; set; }
|
[JsonProperty("connId")] public string ConnId { get; set; }
|
||||||
[JsonProperty("chatid")] public string ChatId { get; set; }
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
[JsonProperty("userid")] public string UserId { get; set; }
|
}
|
||||||
|
|
||||||
|
public class GetMessagePosResp
|
||||||
|
{
|
||||||
|
[JsonProperty("pos")] public int Position { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WSMessageDeletedPayload
|
||||||
|
{
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WSMessageEditedPayload
|
||||||
|
{
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
|
[JsonProperty("content")] public string Content { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WSNewMessagePayload
|
||||||
|
{
|
||||||
|
[JsonProperty("message")] public DmMessage Message { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WSMessagePinnedPayload
|
||||||
|
{
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WSMessagesReadPayload
|
||||||
|
{
|
||||||
|
[JsonProperty("chatid")] public string ChatId { get; set; }
|
||||||
|
[JsonProperty("readerId")] public string ReaderId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WSMessageUnpinnedPayload
|
||||||
|
{
|
||||||
|
[JsonProperty("msgid")] public string MessageId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
64
Services/DMServiceMethods.cs
Normal file
64
Services/DMServiceMethods.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Chtn.CSharp.SDK.Core;
|
||||||
|
using Chtn.CSharp.SDK.Models.Chat.DM;
|
||||||
|
|
||||||
|
namespace Chtn.CSharp.SDK.Services
|
||||||
|
{
|
||||||
|
public interface IDMService
|
||||||
|
{
|
||||||
|
Task<List<DmMessage>> Get(GetMessagesReq req);
|
||||||
|
Task<GetMessagePosResp> GetMessagePos(GetMessagePosReq req);
|
||||||
|
Task<List<PinnedMessage>> GetPinnedMessages(GetPinnedMessagesReq req);
|
||||||
|
Task EditMessage(EditMessageReq req);
|
||||||
|
Task DeleteMessage(DeleteMessageReq req);
|
||||||
|
Task FinishMessage(FinishMessageReq req);
|
||||||
|
Task ReadMessages(ReadMessagesReq req);
|
||||||
|
Task PinMessage(PinMessageReq req);
|
||||||
|
Task UnpinMessage(UnpinMessageReq req);
|
||||||
|
Task DeleteMessages(DeleteMessagesReq req);
|
||||||
|
Task JoinWebsocketRoom(JoinWsRoomReq req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DMServiceProvider : IDMService
|
||||||
|
{
|
||||||
|
private readonly ApiClient _apiClient;
|
||||||
|
public DMServiceProvider(ApiClient apiClient)
|
||||||
|
{
|
||||||
|
_apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
|
||||||
|
}
|
||||||
|
public async Task<List<DmMessage>> Get(GetMessagesReq req) =>
|
||||||
|
await _apiClient.PostAsync<GetMessagesReq, List<DmMessage>>("chat/dm/messages", req);
|
||||||
|
|
||||||
|
public async Task<GetMessagePosResp> GetMessagePos(GetMessagePosReq req) =>
|
||||||
|
await _apiClient.PostAsync<GetMessagePosReq, GetMessagePosResp>("chat/dm/getMessagePosition", req);
|
||||||
|
|
||||||
|
public async Task<List<PinnedMessage>> GetPinnedMessages(GetPinnedMessagesReq req) =>
|
||||||
|
await _apiClient.PostAsync<GetPinnedMessagesReq, List<PinnedMessage>>("chat/dm/pinnedMessages", req);
|
||||||
|
|
||||||
|
public async Task EditMessage(EditMessageReq req) =>
|
||||||
|
await _apiClient.PostAsync<EditMessageReq, object>("chat/dm/editMessage", req);
|
||||||
|
|
||||||
|
public async Task DeleteMessage(DeleteMessageReq req) =>
|
||||||
|
await _apiClient.PostAsync<DeleteMessageReq, object>("chat/dm/deleteMessage", req);
|
||||||
|
|
||||||
|
public async Task FinishMessage(FinishMessageReq req) =>
|
||||||
|
await _apiClient.PostAsync<FinishMessageReq, object>("chat/dm/finishMessage", req);
|
||||||
|
|
||||||
|
public async Task ReadMessages(ReadMessagesReq req) =>
|
||||||
|
await _apiClient.PostAsync<ReadMessagesReq, object>("chat/dm/readMessages", req);
|
||||||
|
|
||||||
|
public async Task PinMessage(PinMessageReq req) =>
|
||||||
|
await _apiClient.PostAsync<PinMessageReq, object>("chat/dm/pinMessage", req);
|
||||||
|
|
||||||
|
public async Task UnpinMessage(UnpinMessageReq req) =>
|
||||||
|
await _apiClient.PostAsync<UnpinMessageReq, object>("chat/dm/unpinMessage", req);
|
||||||
|
|
||||||
|
public async Task DeleteMessages(DeleteMessagesReq req) =>
|
||||||
|
await _apiClient.PostAsync<DeleteMessagesReq, object>("chat/dm/deleteMessages", req);
|
||||||
|
|
||||||
|
public async Task JoinWebsocketRoom(JoinWsRoomReq req) =>
|
||||||
|
await _apiClient.PostAsync<JoinWsRoomReq, object>("v2/chat/dm/joinWebSocketRoom", req);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user