From 12558447c73da90f63276143f4d6a8796ec2fe7b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 21 Jul 2021 11:04:46 +0300 Subject: Implemented a very hardcoded way for chat message pagination and real time updating --- go-src/utils/utils.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'go-src/utils') diff --git a/go-src/utils/utils.go b/go-src/utils/utils.go index 754c7ed..c1bd8a4 100644 --- a/go-src/utils/utils.go +++ b/go-src/utils/utils.go @@ -1,6 +1,8 @@ package utils -import "os" +import ( + "os" +) // Repeats a rune given amount of times and returns the result as a string func RepeatRune(r rune, times int) (result string) { @@ -31,3 +33,11 @@ func AppendToFile(path string, value string) { allChatsFile.WriteString(value) allChatsFile.Close() } + +func TotalPages(maxSize int, messageAmount int) int { + return messageAmount / maxSize +} + +func Paginate(page int, maxSize int, messages ...string) []string { + return messages[len(messages)-maxSize*page : len(messages)-maxSize*(page-1)] +} -- cgit v1.2.3