mirror of
https://github.com/ION606/Discord-Client.git
synced 2026-05-14 21:06:55 +00:00
added typing presence - OUTGOING
This commit is contained in:
+30
-1
@@ -4,6 +4,7 @@ using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Nodes;
|
||||
using static Discord_Client_Custom.client_internals.Client;
|
||||
@@ -48,6 +49,7 @@ namespace Discord_Client_Custom.Channels
|
||||
private static string? cicon;
|
||||
private static string? cownerId;
|
||||
private string lastSent;
|
||||
private static System.Threading.Timer typingTimer;
|
||||
|
||||
|
||||
public ChannelObj() { }
|
||||
@@ -191,21 +193,48 @@ namespace Discord_Client_Custom.Channels
|
||||
}
|
||||
|
||||
var response = await MsgRequests.sendMessage(txtbx.Text, ep);
|
||||
if (response == null)
|
||||
{
|
||||
MessageBox.Show(response.ToJsonString(), "Message failed with the following reason");
|
||||
return;
|
||||
}
|
||||
|
||||
//JsonNode[] arr = new JsonNode[1];
|
||||
//arr[0] = response;
|
||||
|
||||
//Add the message to chat in the app
|
||||
groupedMsgs.Add(new ChannelMsgGroup(response, dmFlowContent, uMainIcon, i + 1));
|
||||
txtbx.Clear();
|
||||
typingTimer.Dispose();
|
||||
|
||||
i++;
|
||||
dmFlowContent.Controls.Remove(txtbx);
|
||||
dmFlowContent.Controls.Add(txtbx, 1, i + 1);
|
||||
dmFlowContent.SetColumnSpan(txtbx, 2);
|
||||
dmFlowContent.ScrollControlIntoView(txtbx);
|
||||
} else
|
||||
{
|
||||
//Do typing intent stuff here
|
||||
//Connection
|
||||
string ep;
|
||||
if (ctype == 1)
|
||||
{
|
||||
ep = "https://discord.com/api/channels/" + cid2 + "/typing";
|
||||
if (txtbx.Text.Length == 0)
|
||||
{
|
||||
typingTimer = new System.Threading.Timer((object state) => {
|
||||
Debug.WriteLine("TYPING....");
|
||||
MsgRequests.sendTyping(ep);
|
||||
});
|
||||
|
||||
typingTimer.Change(0, 10000);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Deal with group message stuff here.....
|
||||
Debug.WriteLine("Message Sending has not been implemented for group DMs (yet)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ namespace Discord_Client_Custom.Connections
|
||||
|
||||
public async static Task<JsonNode> sendMessage(string content, string ep)
|
||||
{
|
||||
Debug.WriteLine(ep);
|
||||
|
||||
try
|
||||
{
|
||||
var client = new HttpClient();
|
||||
@@ -68,6 +66,50 @@ namespace Discord_Client_Custom.Connections
|
||||
}
|
||||
|
||||
|
||||
public static async Task<JsonNode> sendTyping(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = new HttpClient();
|
||||
|
||||
var request = new HttpRequestMessage()
|
||||
{
|
||||
RequestUri = new Uri(url),
|
||||
Method = HttpMethod.Post,
|
||||
};
|
||||
|
||||
request.Headers.Clear();
|
||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
//CHANGE THIS TO CONFIG LATER
|
||||
request.Headers.Add("Authorization", userToken);
|
||||
request.Headers.Add("User-Agent", ".NET Foundation Repository Reporter");
|
||||
|
||||
|
||||
var taskResponse = await client.SendAsync(request);
|
||||
var responseContent = await taskResponse.Content.ReadAsStringAsync();
|
||||
|
||||
//Typing
|
||||
if (responseContent.Length == 0) return null;
|
||||
|
||||
JsonNode responseJSON = JsonNode.Parse(responseContent);
|
||||
|
||||
if (taskResponse.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
Debug.Write(responseJSON["message"]);
|
||||
return null;
|
||||
}
|
||||
|
||||
return responseJSON;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static async Task<JsonNode> getChannels()
|
||||
{
|
||||
var client = new HttpClient();
|
||||
|
||||
Reference in New Issue
Block a user