This repository has been archived on 2023-06-30. You can view files and clone it, but cannot push or open issues or pull requests.
2chBackAPI/BufferControllers/APIThreadBuffer.cs
RakVhalate e16d6258c3
All checks were successful
continuous-integration/drone/push Build is passing
Previev Sorting Algorytm
2022-12-21 12:06:10 +05:00

83 lines
2.7 KiB
C#

using NeDvachAPI.DBControllers;
using NeDvachAPI.Models;
namespace NeDvachAPI.BufferControllers
{
public class APIThreadBuffer
{
private static List<Post>[] ThreadsPrewievs = new List<Post>[0];
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
{
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);
}
public static List<Post>[] GetThreadPreviews()
{
return ThreadsPrewievs;
}
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
{
Threads = Threads.Append(ThreadToAdd).ToArray();
}
public static int GetThreadLength(int threadId)
{
return Threads[threadId].Count;
}
public static List<Post> GetThread(int threadId)
{
if (threadId < Threads.Length + 1 & threadId != 0)
{
return Threads[threadId - 1];
}
else return null;
}
public static Post GetSinglePost(int thread, int postPosition)
{
List<Post> postsList = Threads[thread];
return postsList[postPosition-1];
}
public static void UpdateThreadPosts(int threadId)
{
Console.WriteLine("Пытаюсь обновить тред " + threadId);
Threads[threadId - 1] = DBchat.PostsList("b", threadId);
}
public static void RefreshThread(int threadId)
{
UpdateThreadPosts(threadId);
UpdateThreadsPreviews(threadId);
}
}
}