mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-17 06:37: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"
|
"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": {
|
"conversation_preview": {
|
||||||
"streak_expiration": "expires in {day} days {hour} hours {minute} minutes",
|
"streak_expiration": "expires in {day} days {hour} hours {minute} minutes",
|
||||||
"total_messages": "Total sent/received messages: {count}",
|
"total_messages": "Total sent/received messages: {count}",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.rhunk.snapenhance.core.database
|
package me.rhunk.snapenhance.core.database
|
||||||
|
|
||||||
|
import android.content.ContentValues
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.database.sqlite.SQLiteDatabase
|
import android.database.sqlite.SQLiteDatabase
|
||||||
import android.database.sqlite.SQLiteDatabase.OpenParams
|
import android.database.sqlite.SQLiteDatabase.OpenParams
|
||||||
@ -55,8 +56,8 @@ class DatabaseAccess(
|
|||||||
)
|
)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
context.log.error("Failed to open database ${database.fileName}!", it)
|
context.log.error("Failed to open database ${database.fileName}!", it)
|
||||||
}.getOrNull()?.takeIf { !writeMode }?.also {
|
}.getOrNull()?.also {
|
||||||
openedDatabases[database] = it
|
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 {
|
useDatabase(DatabaseType.MAIN, writeMode = true)?.apply {
|
||||||
performOperation {
|
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()
|
close()
|
||||||
}
|
}
|
||||||
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAccessTokens(userId: String): Map<String, String>? {
|
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.applyTheme
|
||||||
import me.rhunk.snapenhance.core.ui.menu.AbstractMenu
|
import me.rhunk.snapenhance.core.ui.menu.AbstractMenu
|
||||||
import me.rhunk.snapenhance.core.ui.triggerRootCloseTouchEvent
|
import me.rhunk.snapenhance.core.ui.triggerRootCloseTouchEvent
|
||||||
|
import me.rhunk.snapenhance.core.util.ktx.vibrateLongPress
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
@ -124,7 +125,7 @@ class FriendFeedInfoMenu : AbstractMenu() {
|
|||||||
private fun markAsSeen(conversationId: String) {
|
private fun markAsSeen(conversationId: String) {
|
||||||
val messaging = context.feature(Messaging::class)
|
val messaging = context.feature(Messaging::class)
|
||||||
val messageIds = messaging.getFeedCachedMessageIds(conversationId)?.takeIf { it.isNotEmpty() } ?: run {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,10 +330,27 @@ class FriendFeedInfoMenu : AbstractMenu() {
|
|||||||
viewConsumer(Button(view.context).apply {
|
viewConsumer(Button(view.context).apply {
|
||||||
text = translation["mark_stories_as_seen_locally"]
|
text = translation["mark_stories_as_seen_locally"]
|
||||||
applyTheme(view.width, hasRadius = true)
|
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()
|
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