added typing presence - OUTGOING

This commit is contained in:
ION606
2023-03-11 15:54:43 -05:00
parent bc991c84af
commit 7d2f847f44
2 changed files with 74 additions and 3 deletions
+30 -1
View File
@@ -4,6 +4,7 @@ using System.Collections;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Net; using System.Net;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text.Json.Nodes; using System.Text.Json.Nodes;
using static Discord_Client_Custom.client_internals.Client; using static Discord_Client_Custom.client_internals.Client;
@@ -48,6 +49,7 @@ namespace Discord_Client_Custom.Channels
private static string? cicon; private static string? cicon;
private static string? cownerId; private static string? cownerId;
private string lastSent; private string lastSent;
private static System.Threading.Timer typingTimer;
public ChannelObj() { } public ChannelObj() { }
@@ -191,21 +193,48 @@ namespace Discord_Client_Custom.Channels
} }
var response = await MsgRequests.sendMessage(txtbx.Text, ep); 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]; //JsonNode[] arr = new JsonNode[1];
//arr[0] = response; //arr[0] = response;
//Add the message to chat in the app //Add the message to chat in the app
groupedMsgs.Add(new ChannelMsgGroup(response, dmFlowContent, uMainIcon, i + 1)); groupedMsgs.Add(new ChannelMsgGroup(response, dmFlowContent, uMainIcon, i + 1));
txtbx.Clear(); txtbx.Clear();
typingTimer.Dispose();
i++; i++;
dmFlowContent.Controls.Remove(txtbx); dmFlowContent.Controls.Remove(txtbx);
dmFlowContent.Controls.Add(txtbx, 1, i + 1); dmFlowContent.Controls.Add(txtbx, 1, i + 1);
dmFlowContent.SetColumnSpan(txtbx, 2); dmFlowContent.SetColumnSpan(txtbx, 2);
dmFlowContent.ScrollControlIntoView(txtbx);
} else } else
{ {
//Do typing intent stuff here //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;
}
} }
}; };
+44 -2
View File
@@ -23,8 +23,6 @@ namespace Discord_Client_Custom.Connections
public async static Task<JsonNode> sendMessage(string content, string ep) public async static Task<JsonNode> sendMessage(string content, string ep)
{ {
Debug.WriteLine(ep);
try try
{ {
var client = new HttpClient(); 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() public static async Task<JsonNode> getChannels()
{ {
var client = new HttpClient(); var client = new HttpClient();