diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/forums/PostsState.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/forums/PostsState.kt
index 2c99b09c194c4b2f5533e61d2eaf1efa7c5367ef..2996d0c2da48c7216329414365292fd7a4a092c6 100644
--- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/forums/PostsState.kt
+++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/forums/PostsState.kt
@@ -32,7 +32,7 @@ class Loaded(
 
     @UiExecutor
     fun unreadBeforeIndex(index: Int): UnreadPostInfo {
-        if (index <= 0) return UnreadPostInfo(null, 0)
+        if (index <= 0 || index >= posts.size) return UnreadPostInfo(null, 0)
 
         var lastUnread: Int? = null
         var num = 0
@@ -45,7 +45,7 @@ class Loaded(
 
     @UiExecutor
     fun unreadAfterIndex(index: Int): UnreadPostInfo {
-        if (index == -1) return UnreadPostInfo(null, 0)
+        if (index < 0 || index >= posts.size) return UnreadPostInfo(null, 0)
 
         var firstUnread: Int? = null
         var num = 0