Skip to content

Commit 9de8bce

Browse files
committed
Add markForumTopicAsRead support
1 parent c1a3c78 commit 9de8bce

11 files changed

Lines changed: 90 additions & 3 deletions

File tree

data/src/main/java/org/monogram/data/chats/ForumTopicsManager.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class ForumTopicsManager(
114114
isClosed = topic.info.isClosed,
115115
isPinned = topic.isPinned,
116116
unreadCount = topic.unreadCount,
117+
lastReadInboxMessageId = topic.lastReadInboxMessageId,
118+
lastReadOutboxMessageId = topic.lastReadOutboxMessageId,
119+
unreadMentionCount = topic.unreadMentionCount,
120+
unreadReactionCount = topic.unreadReactionCount,
121+
unreadPollVoteCount = topic.unreadPollVoteCount,
117122
lastMessageText = preview.text,
118123
lastMessageEntities = preview.entities,
119124
lastMessageTime = preview.time,
@@ -135,6 +140,11 @@ class ForumTopicsManager(
135140
isClosed = topic.info.isClosed,
136141
isPinned = topic.isPinned,
137142
unreadCount = topic.unreadCount,
143+
lastReadInboxMessageId = topic.lastReadInboxMessageId,
144+
lastReadOutboxMessageId = topic.lastReadOutboxMessageId,
145+
unreadMentionCount = topic.unreadMentionCount,
146+
unreadReactionCount = topic.unreadReactionCount,
147+
unreadPollVoteCount = topic.unreadPollVoteCount,
138148
lastMessageText = preview.text,
139149
lastMessageTime = preview.time,
140150
order = topic.order,

data/src/main/java/org/monogram/data/datasource/remote/ChatRemoteSource.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface ChatRemoteSource {
2828
suspend fun toggleChatIsPinned(chatList: TdApi.ChatList, chatId: Long, isPinned: Boolean)
2929
suspend fun toggleChatIsMarkedAsUnread(chatId: Long, isMarkedAsUnread: Boolean)
3030
suspend fun markChatAsRead(chatId: Long)
31+
suspend fun markForumTopicAsRead(chatId: Long, topicId: Int)
3132
suspend fun deleteChat(chatId: Long)
3233
suspend fun leaveChat(chatId: Long)
3334
suspend fun clearChatHistory(chatId: Long, revoke: Boolean)

data/src/main/java/org/monogram/data/datasource/remote/TdChatRemoteDataSource.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,35 @@ class TdChatRemoteSource(
218218
}
219219
}
220220

221+
override suspend fun markForumTopicAsRead(chatId: Long, topicId: Int) {
222+
val topic = coRunCatching {
223+
gateway.execute(TdApi.GetForumTopic(chatId, topicId))
224+
}.getOrNull()
225+
226+
topic?.lastMessage?.let { lastMessage ->
227+
coRunCatching {
228+
gateway.execute(
229+
TdApi.ViewMessages(
230+
chatId,
231+
longArrayOf(lastMessage.id),
232+
TdApi.MessageSourceForumTopicHistory(),
233+
true
234+
)
235+
)
236+
}
237+
}
238+
239+
coRunCatching {
240+
gateway.execute(TdApi.ReadAllForumTopicMentions(chatId, topicId))
241+
}
242+
coRunCatching {
243+
gateway.execute(TdApi.ReadAllForumTopicReactions(chatId, topicId))
244+
}
245+
coRunCatching {
246+
gateway.execute(TdApi.ReadAllForumTopicPollVotes(chatId, topicId))
247+
}
248+
}
249+
221250
override suspend fun deleteChat(chatId: Long) {
222251
coRunCatching { gateway.execute(TdApi.DeleteChat(chatId)) }
223252
}

data/src/main/java/org/monogram/data/db/MonogramDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import org.monogram.data.db.model.WallpaperEntity
6060
SponsorEntity::class,
6161
TextCompositionStyleEntity::class
6262
],
63-
version = 32,
63+
version = 33,
6464
exportSchema = false
6565
)
6666
abstract class MonogramDatabase : RoomDatabase() {

data/src/main/java/org/monogram/data/db/MonogramMigrations.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,29 @@ object MonogramMigrations {
313313
}
314314
}
315315

316+
val MIGRATION_32_33 = object : Migration(32, 33) {
317+
override fun migrate(db: SupportSQLiteDatabase) {
318+
db.addColumn("topics", "lastReadInboxMessageId", "INTEGER NOT NULL DEFAULT 0")
319+
db.addColumn("topics", "lastReadOutboxMessageId", "INTEGER NOT NULL DEFAULT 0")
320+
db.addColumn("topics", "unreadMentionCount", "INTEGER NOT NULL DEFAULT 0")
321+
db.addColumn("topics", "unreadReactionCount", "INTEGER NOT NULL DEFAULT 0")
322+
db.addColumn("topics", "unreadPollVoteCount", "INTEGER NOT NULL DEFAULT 0")
323+
324+
db.execSQL(
325+
"""
326+
UPDATE `messages`
327+
SET `mediaFileId` = 0,
328+
`mediaPath` = NULL,
329+
`mediaThumbnailPath` = NULL
330+
WHERE `mediaFileId` != 0
331+
OR `mediaPath` IS NOT NULL
332+
OR `mediaThumbnailPath` IS NOT NULL
333+
""".trimIndent()
334+
)
335+
db.execSQL("DELETE FROM `sticker_paths`")
336+
}
337+
}
338+
316339
private fun SupportSQLiteDatabase.addColumn(table: String, column: String, definition: String) {
317340
execSQL("ALTER TABLE `$table` ADD COLUMN `$column` $definition")
318341
}

data/src/main/java/org/monogram/data/db/model/TopicEntity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ data class TopicEntity(
1212
val isClosed: Boolean,
1313
val isPinned: Boolean,
1414
val unreadCount: Int,
15+
val lastReadInboxMessageId: Long = 0L,
16+
val lastReadOutboxMessageId: Long = 0L,
17+
val unreadMentionCount: Int = 0,
18+
val unreadReactionCount: Int = 0,
19+
val unreadPollVoteCount: Int = 0,
1520
val lastMessageText: String,
1621
val lastMessageTime: String,
1722
val order: Long,

data/src/main/java/org/monogram/data/di/dataModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ val dataModule = module {
260260
MonogramMigrations.MIGRATION_28_29,
261261
MonogramMigrations.MIGRATION_29_30,
262262
MonogramMigrations.MIGRATION_30_31,
263-
MonogramMigrations.MIGRATION_31_32
263+
MonogramMigrations.MIGRATION_31_32,
264+
MonogramMigrations.MIGRATION_32_33
264265
)
265266
.build()
266267
}

data/src/main/java/org/monogram/data/repository/ChatsListRepositoryImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,12 @@ class ChatsListRepositoryImpl(
813813
)
814814
}
815815

816+
override suspend fun markForumTopicAsRead(chatId: Long, topicId: Int) {
817+
chatRemoteSource.markForumTopicAsRead(chatId, topicId)
818+
forumTopicsManager.getForumTopics(chatId = chatId, limit = 100)
819+
refreshChat(chatId)
820+
}
821+
816822
override fun clearChatHistory(chatId: Long, revoke: Boolean) {
817823
scope.launch(dispatchers.io) {
818824
chatRemoteSource.clearChatHistory(chatId, revoke)

domain/src/main/java/org/monogram/domain/models/TopicModel.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ data class TopicModel(
99
val isClosed: Boolean = false,
1010
val isPinned: Boolean = false,
1111
val unreadCount: Int = 0,
12+
val lastReadInboxMessageId: Long = 0L,
13+
val lastReadOutboxMessageId: Long = 0L,
14+
val unreadMentionCount: Int = 0,
15+
val unreadReactionCount: Int = 0,
16+
val unreadPollVoteCount: Int = 0,
1217
val lastMessageText: String = "",
1318
val lastMessageEntities: List<MessageEntity> = emptyList(),
1419
val lastMessageTime: String = "",

domain/src/main/java/org/monogram/domain/repository/ForumTopicsRepository.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ interface ForumTopicsRepository {
1414
offsetForumTopicId: Int = 0,
1515
limit: Int = 20
1616
): List<TopicModel>
17-
}
17+
18+
suspend fun markForumTopicAsRead(chatId: Long, topicId: Int)
19+
}

0 commit comments

Comments
 (0)