diff options
| Commit | 12558447c73da90f63276143f4d6a8796ec2fe7b (patch) | |
|---|---|---|
| Author | 2021-07-21 11:04:46 +0300 | |
| Committer | 2021-07-21 11:04:46 +0300 | |
| Files | fad42fa04b56d497d7251bf4270f7c427ba8feea /go-src/utils | |
| ctfc-12558447c73da90f63276143f4d6a8796ec2fe7b.tar ctfc-12558447c73da90f63276143f4d6a8796ec2fe7b.tar.gz ctfc-12558447c73da90f63276143f4d6a8796ec2fe7b.zip | ||
| Parent | 7457f7af8effa21ecf328058475e944e46075670 (diff) | |
Implemented a very hardcoded way for chat message pagination and real time updating
1 files changed, 11 insertions, 1 deletions
| -rw-r--r-- | go-src/utils/utils.go | 12 |
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)] +} |
