Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions app/src/main/java/com/anindra/messages/MessagesApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,17 @@ class MessagesApplication : Application(), SingletonImageLoader.Factory {
// import the names may have changed — and drops those of chats that
// are gone.
com.anindra.messages.sms.NotificationHelper.syncNotificationChannels(this@MessagesApplication)
// The nudge's schedule has to follow its switch, and an app start is
// also the moment a nudge that became due while the app was closed
// gets posted (#484).
com.anindra.messages.data.ReplyNudgeScheduler.apply(
this@MessagesApplication, s.replyNudgeEnabled
)
if (s.replyNudgeEnabled) {
com.anindra.messages.data.ReplyNudgeScheduler.checkNow(this@MessagesApplication)
// Reply nudges were removed. An install that had them keeps the
// queued work, its card and its channel otherwise, and the worker
// class no longer exists to run it.
androidx.work.WorkManager.getInstance(this@MessagesApplication).apply {
cancelUniqueWork("messages-reply-nudge")
cancelUniqueWork("messages-reply-nudge-check")
}
getSystemService(android.app.NotificationManager::class.java)?.let { nm ->
nm.activeNotifications.filter { it.tag == "nudge" }
.forEach { nm.cancel(it.tag, it.id) }
nm.deleteNotificationChannel("messages_nudge")
}
// A queued message's countdown card outlives neither a restart of
// the app nor a killed shade entry, so the pending rows are
Expand Down
78 changes: 0 additions & 78 deletions app/src/main/java/com/anindra/messages/data/ReplyNudgePolicy.kt

This file was deleted.

87 changes: 0 additions & 87 deletions app/src/main/java/com/anindra/messages/data/ReplyNudgeScheduler.kt

This file was deleted.

41 changes: 0 additions & 41 deletions app/src/main/java/com/anindra/messages/data/Repository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1894,9 +1894,6 @@ class Repository(private val context: Context) {
"UPDATE conversations SET snippet=?,timestamp=?,unread_count=0,last_is_me=?,deleted_at=0 WHERE id=?",
arrayOf<Any?>(snippet, ts, if (isMe) 1 else 0, conversationId)
)
// A message of ours is the answer a nudge was waiting for (#484), and
// every send path ends here, so the card cannot outlive the reply.
if (isMe) com.anindra.messages.sms.ReplyNudge.cancel(context, conversationId)
notifyChanged()
}

Expand Down Expand Up @@ -2909,44 +2906,6 @@ class Repository(private val context: Context) {
return out
}

/**
* Threads a nudge could apply to (#484): read, unanswered, and not archived,
* blocked or trashed. The age test and the once-a-day cap are
* [ReplyNudgePolicy]'s, so the rule is one function and not a SQL string.
* Read outside a flow — the nudge runs in a background worker.
*/
fun replyNudgeRowsBlocking(): List<ReplyNudgeRow> {
val out = mutableListOf<ReplyNudgeRow>()
// The policy owns the age ceiling; this only keeps a long history from
// being loaded to reach it.
val oldest = System.currentTimeMillis() - ReplyNudgePolicy.MAX_AGE_MILLIS
db.readableDatabase.rawQuery(
"""SELECT id,address,snippet,timestamp,last_is_me,unread_count,archived,blocked,deleted_at
FROM conversations
WHERE deleted_at=0 AND archived=0 AND blocked=0
AND unread_count=0 AND last_is_me=0 AND timestamp>=?
ORDER BY timestamp DESC""",
arrayOf(oldest.toString())
).use { c ->
while (c.moveToNext()) {
out.add(
ReplyNudgeRow(
conversationId = c.getLong(0),
address = c.getString(1),
snippet = c.getString(2) ?: "",
newest = c.getLong(3),
lastIsMine = c.getInt(4) == 1,
unread = c.getInt(5),
archived = c.getInt(6) == 1,
blocked = c.getInt(7) == 1,
deleted = c.getLong(8) != 0L
)
)
}
}
return out
}

fun addScheduledMessage(address: String, body: String, timestamp: Long, conversationId: Long, subId: Int): Long {
require(address.isNotBlank()) { "Address must not be blank" }
require(body.isNotBlank()) { "Message body must not be blank" }
Expand Down
24 changes: 0 additions & 24 deletions app/src/main/java/com/anindra/messages/data/SettingsStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ class SettingsStore(context: Context) {
const val KEY_NOTIF_ACTION_REPLY = "notif_action_reply"
const val KEY_NOTIF_ACTION_MARK_READ = "notif_action_mark_read"
const val KEY_NOTIF_ACTION_DELETE = "notif_action_delete"
const val KEY_REPLY_NUDGE = "reply_nudge_enabled"
const val KEY_REPLY_NUDGE_HOURS = "reply_nudge_hours"
const val KEY_REPLY_NUDGE_AT_PREFIX = "reply_nudge_at_"
const val KEY_BUBBLE_BACK_CLOSES = "bubble_back_closes"
const val KEY_SUGGESTED_REPLIES = "suggested_replies_enabled"
const val KEY_SHOW_SIM_INDICATOR = "show_sim_indicator"
Expand Down Expand Up @@ -414,27 +411,6 @@ class SettingsStore(context: Context) {
get() = prefs.getBoolean(KEY_NOTIF_ACTION_DELETE, true)
set(v) { prefs.edit().putBoolean(KEY_NOTIF_ACTION_DELETE, v).apply(); _revision.value++ }

/**
* Whether an unanswered thread is nudged after a while (#484). Off by
* default: a reminder the user did not ask for is just another notification.
*/
var replyNudgeEnabled: Boolean
get() = prefs.getBoolean(KEY_REPLY_NUDGE, false)
set(v) { prefs.edit().putBoolean(KEY_REPLY_NUDGE, v).apply(); _revision.value++ }

/** How long the message sits unanswered before the nudge. */
var replyNudgeHours: Int
get() = prefs.getInt(KEY_REPLY_NUDGE_HOURS, ReplyNudgePolicy.DEFAULT_INTERVAL_HOURS)
set(v) { prefs.edit().putInt(KEY_REPLY_NUDGE_HOURS, v).apply(); _revision.value++ }

/** When this conversation was last nudged, so one thread is not re-nudged all day. */
fun replyNudgedAt(conversationId: Long): Long =
prefs.getLong(KEY_REPLY_NUDGE_AT_PREFIX + conversationId, 0L)

fun markReplyNudged(conversationId: Long, at: Long) {
prefs.edit().putLong(KEY_REPLY_NUDGE_AT_PREFIX + conversationId, at).apply()
}

/**
* Whether Back closes a conversation bubble (#354 follow-up). Off by
* default: Back inside a bubble returns to the conversation list and leaves
Expand Down
Loading