From 60912c9a0b61de6fd0b5e777ed3d504ae43aa2b6 Mon Sep 17 00:00:00 2001 From: ION606 Date: Sat, 11 Mar 2023 09:53:18 -0500 Subject: [PATCH] Changed the message format --- Channels/ChannelMsgGroup.cs | 1 + Channels/ChannelObj.cs | 50 ++++++++++++++++++++++++++----------- Connections/MsgRequests.cs | 3 ++- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Channels/ChannelMsgGroup.cs b/Channels/ChannelMsgGroup.cs index ef5b19f..b3e8640 100644 --- a/Channels/ChannelMsgGroup.cs +++ b/Channels/ChannelMsgGroup.cs @@ -159,6 +159,7 @@ namespace Discord_Client_Custom.Channels Label txt = new Label(); txt.Text = msg.getContent(); txt.Tag = msg.getId(); + txt.Padding = new Padding(0, 0, 0, 10); txt.MaximumSize = new Size(dmFlowContent.Width - 70, 100000000); txt.AutoSize = true; diff --git a/Channels/ChannelObj.cs b/Channels/ChannelObj.cs index cc34956..2cd4d8a 100644 --- a/Channels/ChannelObj.cs +++ b/Channels/ChannelObj.cs @@ -89,7 +89,7 @@ namespace Discord_Client_Custom.Channels //There's gonna be a faster way var arr = contents.AsArray().ToArray().Reverse().ToArray(); - string id_current = (string)arr.Last()["id"]; + string id_current = (string)arr[0]["author"]["id"]; int startInd = 0; //Make sure the first column is consitant @@ -98,43 +98,62 @@ namespace Discord_Client_Custom.Channels dmFlowContent.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); //dmFlowContent.ColumnStyles[1].Width = 500; + //Add all content into one "message" + string msgContent = ""; //(string)arr[0]["content"]; int i; + + int skipCounter = 0; + for (i = 0; i < arr.Length; i++) { - if ((string)arr[i]["content"] == "") continue; + if ((string)arr[i]["content"] == "") + { + skipCounter++; + continue; + } + + //Remove when attatcmenent integration is added + if (msgContent.Length == 0 && skipCounter == i) id_current = (string)arr[i]["author"]["id"]; string authorName = (string)arr[i]["author"]["id"]; - //Removed for spacing reasons - //if (authorName != id_current) - //{ - Debug.WriteLine(arr[i]["content"]); - if (authorName == uMainId) + + if (authorName != id_current) + { + var msgObjTemp = (JsonNode)arr[startInd]; + msgObjTemp["content"] = msgContent; + + if (authorName != uMainId) { - groupedMsgs.Add(new ChannelMsgGroup(arr[i], dmFlowContent, uMainIcon, i)); + groupedMsgs.Add(new ChannelMsgGroup(msgObjTemp, dmFlowContent, uMainIcon, i)); } else { - groupedMsgs.Add(new ChannelMsgGroup(arr[i], dmFlowContent, uicon, i)); + groupedMsgs.Add(new ChannelMsgGroup(msgObjTemp, dmFlowContent, uicon, i)); } startInd = i; id_current = authorName; - //} + msgContent = ""; + } + + msgContent += arr[i]["content"] + "\n"; } - /* if (i != startInd) { + var msgObjTemp = (JsonNode)arr[startInd]; + msgObjTemp["content"] = msgContent; + if ((string)arr[startInd]["author"]["id"] == uMainId) { - groupedMsgs[groupedMsgs.Count - 1] = new ChannelMsgGroup(arr[startInd..i], dmFlowContent, uMainIcon, i); + groupedMsgs[groupedMsgs.Count - 1] = new ChannelMsgGroup(msgObjTemp, dmFlowContent, uMainIcon, i); } else { - groupedMsgs[groupedMsgs.Count - 1] = new ChannelMsgGroup(arr[startInd..i], dmFlowContent, uicon, i); + groupedMsgs[groupedMsgs.Count - 1] = new ChannelMsgGroup(msgObjTemp, dmFlowContent, uicon, i); } - }*/ + } lastSent = id_current; @@ -158,7 +177,7 @@ namespace Discord_Client_Custom.Channels } var response = await MsgRequests.sendMessage(txtbx.Text, ep); - JsonNode[] arr = new JsonNode[1]; + //JsonNode[] arr = new JsonNode[1]; //arr[0] = response; //Add the message to chat in the app @@ -178,6 +197,7 @@ namespace Discord_Client_Custom.Channels dmFlowContent.Controls.Add(txtbx, 0, i+1); dmFlowContent.SetColumnSpan(txtbx, 2); + dmFlowContent.ScrollControlIntoView(txtbx); } diff --git a/Connections/MsgRequests.cs b/Connections/MsgRequests.cs index 34d7073..cb39bb5 100644 --- a/Connections/MsgRequests.cs +++ b/Connections/MsgRequests.cs @@ -9,8 +9,9 @@ namespace Discord_Client_Custom.Connections { internal class MsgRequests { + private static int msgFetchLimit = 50; private static string dmMePath = "https://discord.com/api/users/@me/channels"; - private static string dmGetMsgsBasepath = "https://discord.com/api/channels/{{id}}/messages?limit=10"; + private static string dmGetMsgsBasepath = "https://discord.com/api/channels/{{id}}/messages?limit=" + msgFetchLimit.ToString(); public static string userToken = System.Environment.GetEnvironmentVariable("userToken"); public MsgRequests(string url, string reqType)