2022-11-25 22:40:17 +10:00
|
|
|
|
using NeDvachAPI.DBControllers;
|
|
|
|
|
using NeDvachAPI.Models;
|
|
|
|
|
|
|
|
|
|
namespace NeDvachAPI.BufferControllers
|
2022-11-25 12:37:26 +10:00
|
|
|
|
{
|
|
|
|
|
public class APIThreadBuffer
|
|
|
|
|
{
|
2022-12-21 17:06:10 +10:00
|
|
|
|
private static List<Post>[] ThreadsPrewievs = new List<Post>[0];
|
2022-11-25 12:37:26 +10:00
|
|
|
|
private static List<Post>[] Threads = new List<Post>[0];
|
|
|
|
|
public static void WriteThreadPreviewsBuffer(List<Post> OPPostsToWrite) //add list of OP-posts and last post to buffer
|
|
|
|
|
{
|
2022-12-21 17:06:10 +10:00
|
|
|
|
for(int pos = 0; pos < OPPostsToWrite.Count; pos ++)
|
|
|
|
|
{
|
|
|
|
|
var deb = new List<Post>();
|
|
|
|
|
deb.Add(OPPostsToWrite[pos]);
|
|
|
|
|
ThreadsPrewievs = ThreadsPrewievs.Append(deb).ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AppendToThreadPreviews(int index,Post toAppend)
|
|
|
|
|
{
|
|
|
|
|
ThreadsPrewievs[index].Add(toAppend);
|
2022-11-25 12:37:26 +10:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 17:06:10 +10:00
|
|
|
|
public static List<Post>[] GetThreadPreviews()
|
2022-11-25 12:37:26 +10:00
|
|
|
|
{
|
|
|
|
|
return ThreadsPrewievs;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 17:06:10 +10:00
|
|
|
|
public static void UpdateThreadsPreviews(int threadId)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Пытаюсь обновить превью треда " + threadId);
|
|
|
|
|
|
|
|
|
|
var newPreview = new List<Post>();
|
|
|
|
|
newPreview.Add(ThreadsPrewievs[threadId -1][0]);
|
|
|
|
|
int targetLength = APIThreadBuffer.GetThreadLength(threadId - 1);
|
|
|
|
|
for (int lastofthree = targetLength- 2; lastofthree <= targetLength; lastofthree ++)
|
|
|
|
|
{
|
|
|
|
|
newPreview.Add(GetSinglePost(threadId - 1,lastofthree));
|
|
|
|
|
}
|
|
|
|
|
ThreadsPrewievs[threadId -1] = newPreview;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AppendThreadsBuffer(List<Post> ThreadToAdd) //add thread's posts from DB to buffer
|
2022-11-25 12:37:26 +10:00
|
|
|
|
{
|
|
|
|
|
Threads = Threads.Append(ThreadToAdd).ToArray();
|
|
|
|
|
}
|
2022-12-21 17:06:10 +10:00
|
|
|
|
|
|
|
|
|
public static int GetThreadLength(int threadId)
|
|
|
|
|
{
|
|
|
|
|
return Threads[threadId].Count;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 22:40:17 +10:00
|
|
|
|
public static List<Post> GetThread(int threadId)
|
2022-11-25 12:37:26 +10:00
|
|
|
|
{
|
2022-11-25 22:40:17 +10:00
|
|
|
|
if (threadId < Threads.Length + 1 & threadId != 0)
|
2022-11-25 12:37:26 +10:00
|
|
|
|
{
|
|
|
|
|
return Threads[threadId - 1];
|
|
|
|
|
}
|
|
|
|
|
else return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 17:06:10 +10:00
|
|
|
|
public static Post GetSinglePost(int thread, int postPosition)
|
2022-11-25 12:37:26 +10:00
|
|
|
|
{
|
2022-12-21 17:06:10 +10:00
|
|
|
|
List<Post> postsList = Threads[thread];
|
|
|
|
|
return postsList[postPosition-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UpdateThreadPosts(int threadId)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Пытаюсь обновить тред " + threadId);
|
2022-11-25 12:37:26 +10:00
|
|
|
|
Threads[threadId - 1] = DBchat.PostsList("b", threadId);
|
|
|
|
|
}
|
2022-11-25 22:40:17 +10:00
|
|
|
|
|
2022-12-21 17:06:10 +10:00
|
|
|
|
public static void RefreshThread(int threadId)
|
|
|
|
|
{
|
|
|
|
|
UpdateThreadPosts(threadId);
|
|
|
|
|
UpdateThreadsPreviews(threadId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 12:37:26 +10:00
|
|
|
|
}
|
|
|
|
|
}
|