mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Initial commit
This commit is contained in:
12
KfChatDotNetWsClient/Models/ChatClientConfigModel.cs
Normal file
12
KfChatDotNetWsClient/Models/ChatClientConfigModel.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace KfChatDotNetWsClient.Models;
|
||||
|
||||
public class ChatClientConfigModel
|
||||
{
|
||||
// XF session token. Sent as a cookie to auth the user
|
||||
public string? XfSessionToken { get; set; }
|
||||
// Currently wss://kiwifarms.net/chat.ws
|
||||
public Uri WsUri { get; set; }
|
||||
public int ReconnectTimeout { get; set; } = 30;
|
||||
public string CookieDomain { get; set; } = "kiwifarms.net";
|
||||
public string? Proxy { get; set; }
|
||||
}
|
||||
28
KfChatDotNetWsClient/Models/Events/EventHandlers.cs
Normal file
28
KfChatDotNetWsClient/Models/Events/EventHandlers.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using KfChatDotNetWsClient.Models.Json;
|
||||
using Websocket.Client;
|
||||
|
||||
namespace KfChatDotNetWsClient.Models.Events;
|
||||
|
||||
public class EventHandlers
|
||||
{
|
||||
public delegate void OnMessagesEventHandler(object sender, List<MessageModel> messages,
|
||||
MessagesJsonModel jsonPayload);
|
||||
|
||||
// When a user first joins the chat, this event will fire with the entire user list (which may be massive)
|
||||
// But when users join in the course of a regular chat, it'll be one at a time
|
||||
public delegate void OnUsersJoinedEventHandler(object sender, List<UserModel> users, UsersJsonModel jsonPayload);
|
||||
|
||||
// Usually only one user parts at a time, but theoretically the model could support more than one at a time
|
||||
public delegate void OnUsersPartedEventHandler(object sender, List<int> userIds);
|
||||
|
||||
public delegate void OnWsReconnectEventHandler(object sender, ReconnectionInfo reconnectionInfo);
|
||||
|
||||
// Usually only one is sent at a time but it is a list hence the pluralization
|
||||
public delegate void OnDeleteMessagesEventHandler(object sender, List<int> messageIds);
|
||||
|
||||
public delegate void OnWsDisconnectionEventHandler(object sender, DisconnectionInfo disconnectionInfo);
|
||||
|
||||
public delegate void OnFailedToJoinRoom(object sender, string message);
|
||||
|
||||
public delegate void OnUnknownCommand(object sender, string message);
|
||||
}
|
||||
12
KfChatDotNetWsClient/Models/Events/MessageModel.cs
Normal file
12
KfChatDotNetWsClient/Models/Events/MessageModel.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace KfChatDotNetWsClient.Models.Events;
|
||||
|
||||
public class MessageModel
|
||||
{
|
||||
public UserModel Author { get; set; }
|
||||
public string Message { get; set; }
|
||||
public int MessageId { get; set; }
|
||||
public DateTimeOffset? MessageEditDate { get; set; }
|
||||
public DateTimeOffset MessageDate { get; set; }
|
||||
public string MessageRaw { get; set; }
|
||||
public int RoomId { get; set; }
|
||||
}
|
||||
10
KfChatDotNetWsClient/Models/Events/UserModel.cs
Normal file
10
KfChatDotNetWsClient/Models/Events/UserModel.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace KfChatDotNetWsClient.Models.Events;
|
||||
|
||||
public class UserModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Username { get; set; }
|
||||
public Uri AvatarUrl { get; set; }
|
||||
// Unset if it's related to a chat message
|
||||
public DateTimeOffset? LastActivity { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace KfChatDotNetWsClient.Models.Json;
|
||||
|
||||
public class DeleteMessagesJsonModel
|
||||
{
|
||||
[JsonProperty("delete")]
|
||||
public List<int> MessageIdsToDelete { get; set; }
|
||||
}
|
||||
12
KfChatDotNetWsClient/Models/Json/EditMessageJsonModel.cs
Normal file
12
KfChatDotNetWsClient/Models/Json/EditMessageJsonModel.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace KfChatDotNetWsClient.Models.Json;
|
||||
|
||||
public class EditMessageJsonModel
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("message")]
|
||||
public string Message { get; set; }
|
||||
}
|
||||
59
KfChatDotNetWsClient/Models/Json/MessagesJsonModel.cs
Normal file
59
KfChatDotNetWsClient/Models/Json/MessagesJsonModel.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace KfChatDotNetWsClient.Models.Json;
|
||||
|
||||
// {
|
||||
// "messages": [
|
||||
// {
|
||||
// "author": {
|
||||
// "id": 110635,
|
||||
// "username": "felted",
|
||||
// "avatar_url": "https://kiwifarms.net/data/avatars/m/110/110635.jpg?1657300618"
|
||||
// },
|
||||
// "message": "Nigger.",
|
||||
// "message_id": 4390866,
|
||||
// "message_edit_date": 0,
|
||||
// "message_date": 1657317093,
|
||||
// "message_raw": "Nigger.",
|
||||
// "room_id": 10
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
|
||||
// message_raw contains the original bbcode for the message
|
||||
// message is the HTML-version the web client renders with emotes transformed into images, etc.
|
||||
|
||||
public class MessagesJsonModel
|
||||
{
|
||||
public class AuthorModel
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
[JsonProperty("avatar_url")]
|
||||
public Uri AvatarUrl { get; set; }
|
||||
}
|
||||
|
||||
public class MessageModel
|
||||
{
|
||||
[JsonProperty("author")]
|
||||
public AuthorModel Author { get; set; }
|
||||
[JsonProperty("message")]
|
||||
public string Message { get; set; }
|
||||
[JsonProperty("message_id")]
|
||||
public int MessageId { get; set; }
|
||||
[JsonProperty("message_edit_date")]
|
||||
public int MessageEditDate { get; set; }
|
||||
[JsonProperty("message_date")]
|
||||
public int MessageDate { get; set; }
|
||||
[JsonProperty("message_raw")]
|
||||
public string MessageRaw { get; set; }
|
||||
[JsonProperty("room_id")]
|
||||
public int RoomId { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("messages")]
|
||||
public List<MessageModel> Messages { get; set; }
|
||||
}
|
||||
32
KfChatDotNetWsClient/Models/Json/UsersJsonModel.cs
Normal file
32
KfChatDotNetWsClient/Models/Json/UsersJsonModel.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace KfChatDotNetWsClient.Models.Json;
|
||||
|
||||
// {
|
||||
// "users": {
|
||||
// "1337": {
|
||||
// "id": 1337,
|
||||
// "username": "Example User",
|
||||
// "avatar_url": "https://kiwifarms.net/data/avatars/m/13/1337.jpg?1648885311",
|
||||
// "last_activity": 1657316000
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public class UsersJsonModel
|
||||
{
|
||||
public class UserModel
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
[JsonProperty("avatar_url")]
|
||||
public Uri AvatarUrl { get; set; }
|
||||
[JsonProperty("last_activity")]
|
||||
public int LastActivity { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("users")]
|
||||
public Dictionary<string, UserModel> Users { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user