Skip to content

Commit

Permalink
fix(core): mark as seen
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed Feb 4, 2024
1 parent ccde97c commit d89d7c0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
8 changes: 8 additions & 0 deletions common/src/main/assets/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,14 @@
"multiple_media_toast": "You can only send one media at a time"
},

"mark_as_seen": {
"no_unseen_snaps_toast": "No unseen Snaps found!",
"seen_toast": "Marked as seen!",
"unseen_toast": "Marked as unseen!",
"already_seen_toast": "Already marked as seen!",
"already_unseen_toast": "Already marked as unseen!"
},

"conversation_preview": {
"streak_expiration": "expires in {day} days {hour} hours {minute} minutes",
"total_messages": "Total sent/received messages: {count}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.rhunk.snapenhance.core.database

import android.content.ContentValues
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteDatabase.OpenParams
Expand Down Expand Up @@ -55,8 +56,8 @@ class DatabaseAccess(
)
}.onFailure {
context.log.error("Failed to open database ${database.fileName}!", it)
}.getOrNull()?.takeIf { !writeMode }?.also {
openedDatabases[database] = it
}.getOrNull()?.also {
if (!writeMode) openedDatabases[database] = it
}
}

Expand Down Expand Up @@ -367,13 +368,22 @@ class DatabaseAccess(
}
}

fun markFriendStoriesAsSeen(userId: String) {
fun setStoriesViewedState(userId: String, viewed: Boolean): Boolean {
var success = false
useDatabase(DatabaseType.MAIN, writeMode = true)?.apply {
performOperation {
execSQL("UPDATE StorySnap SET viewed = 1 WHERE userId = ?", arrayOf(userId))
success = update(
"StorySnap",
ContentValues().apply {
put("viewed", if (viewed) 1 else 0)
},
"userId = ? AND viewed != ?",
arrayOf(userId, if (viewed) "1" else "0")
) > 0
}
close()
}
return success
}

fun getAccessTokens(userId: String): Map<String, String>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import me.rhunk.snapenhance.core.ui.ViewAppearanceHelper
import me.rhunk.snapenhance.core.ui.applyTheme
import me.rhunk.snapenhance.core.ui.menu.AbstractMenu
import me.rhunk.snapenhance.core.ui.triggerRootCloseTouchEvent
import me.rhunk.snapenhance.core.util.ktx.vibrateLongPress
import java.net.HttpURLConnection
import java.net.URL
import java.text.DateFormat
Expand Down Expand Up @@ -124,7 +125,7 @@ class FriendFeedInfoMenu : AbstractMenu() {
private fun markAsSeen(conversationId: String) {
val messaging = context.feature(Messaging::class)
val messageIds = messaging.getFeedCachedMessageIds(conversationId)?.takeIf { it.isNotEmpty() } ?: run {
context.shortToast("No recent snaps found")
context.shortToast(context.translation["mark_as_seen.no_unseen_snaps_toast"])
return
}

Expand Down Expand Up @@ -329,10 +330,27 @@ class FriendFeedInfoMenu : AbstractMenu() {
viewConsumer(Button(view.context).apply {
text = translation["mark_stories_as_seen_locally"]
applyTheme(view.width, hasRadius = true)
setOnClickListener {
this@FriendFeedInfoMenu.context.apply {

val translations = this@FriendFeedInfoMenu.context.translation.getCategory("mark_as_seen")

this@FriendFeedInfoMenu.context.apply {
setOnClickListener {
mainActivity?.triggerRootCloseTouchEvent()
database.markFriendStoriesAsSeen(targetUser)
if (database.setStoriesViewedState(targetUser, true)) {
shortToast(translations["seen_toast"])
} else {
shortToast(translations["already_seen_toast"])
}
}
setOnLongClickListener {
context.vibrateLongPress()
mainActivity?.triggerRootCloseTouchEvent()
if (database.setStoriesViewedState(targetUser, false)) {
shortToast(translations["unseen_toast"])
} else {
shortToast(translations["already_unseen_toast"])
}
true
}
}
})
Expand Down

0 comments on commit d89d7c0

Please sign in to comment.