mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-16 22:27:09 +02:00
fix(core): mark as seen
This commit is contained in:
parent
ccde97c3bb
commit
d89d7c0f8d
@ -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}",
|
||||
|
@ -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
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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>? {
|
||||
|
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user