Handle keepMutedChatsArchived more generically, also apply it to sends.
Fixes #12788
This commit is contained in:
parent
3f93d4b9fc
commit
17aa0365d6
6 changed files with 50 additions and 25 deletions
2
.idea/codeStyles/Project.xml
generated
2
.idea/codeStyles/Project.xml
generated
|
@ -45,6 +45,8 @@
|
|||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value />
|
||||
</option>
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="HTML">
|
||||
<indentOptions>
|
||||
|
|
|
@ -639,14 +639,13 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
values.put(TYPE, type);
|
||||
values.put(THREAD_ID, threadId);
|
||||
|
||||
long messageId = getWritableDatabase().insert(TABLE_NAME, null, values);
|
||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && Recipient.resolved(recipientId).isMuted();
|
||||
long messageId = getWritableDatabase().insert(TABLE_NAME, null, values);
|
||||
|
||||
if (unread) {
|
||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||
}
|
||||
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
|
||||
notifyConversationListeners(threadId);
|
||||
TrimThreadJob.enqueueAsync(threadId);
|
||||
|
@ -661,15 +660,14 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
values.put(READ, unread ? 0 : 1);
|
||||
getWritableDatabase().update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(messageId));
|
||||
|
||||
long threadId = getThreadIdForMessage(messageId);
|
||||
Recipient recipient = SignalDatabase.threads().getRecipientForThreadId(threadId);
|
||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && recipient != null && recipient.isMuted();
|
||||
long threadId = getThreadIdForMessage(messageId);
|
||||
Recipient recipient = SignalDatabase.threads().getRecipientForThreadId(threadId);
|
||||
|
||||
if (unread) {
|
||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||
}
|
||||
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
|
||||
notifyConversationListeners(threadId);
|
||||
ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(messageId));
|
||||
|
@ -719,8 +717,8 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
|
||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||
}
|
||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && recipient.isMuted();
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
|
@ -796,8 +794,7 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||
}
|
||||
|
||||
final boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && recipient.isMuted();
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
|
@ -948,8 +945,7 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
}
|
||||
|
||||
if (!silent) {
|
||||
final boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && (recipient.isMuted() || (groupRecipient != null && groupRecipient.isMuted()));
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
}
|
||||
|
||||
if (message.getSubscriptionId() != -1) {
|
||||
|
@ -2503,8 +2499,6 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
if (threadRecipientId == null) {
|
||||
threadRecipientId = retrieved.getFrom();
|
||||
}
|
||||
boolean keepThreadArchived = threadRecipientId != null && SignalStore.settings().shouldKeepMutedChatsArchived() && Recipient.resolved(threadRecipientId).isMuted();
|
||||
|
||||
long messageId = insertMediaMessage(threadId,
|
||||
retrieved.getBody(),
|
||||
retrieved.getAttachments(),
|
||||
|
@ -2516,13 +2510,14 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
contentValues,
|
||||
null,
|
||||
updateThread,
|
||||
!keepThreadArchived);
|
||||
true);
|
||||
|
||||
boolean isNotStoryGroupReply = retrieved.getParentStoryId() == null || !retrieved.getParentStoryId().isGroupReply();
|
||||
|
||||
if (!MessageTypes.isPaymentsActivated(mailbox) && !MessageTypes.isPaymentsRequestToActivate(mailbox) && !MessageTypes.isExpirationTimerUpdate(mailbox) && !retrieved.getStoryType().isStory() && isNotStoryGroupReply) {
|
||||
boolean incrementUnreadMentions = !retrieved.getMentions().isEmpty() && retrieved.getMentions().stream().anyMatch(m -> m.getRecipientId().equals(Recipient.self().getId()));
|
||||
SignalDatabase.threads().incrementUnread(threadId, 1, incrementUnreadMentions ? 1 : 0);
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
}
|
||||
|
||||
notifyConversationListeners(threadId);
|
||||
|
@ -2671,8 +2666,7 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
long messageId = db.insert(TABLE_NAME, null, values);
|
||||
|
||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && Recipient.resolved(recipientId).isMuted();
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
|
||||
notifyConversationListeners(threadId);
|
||||
|
||||
|
@ -2695,8 +2689,7 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
|||
databaseHelper.getSignalWritableDatabase().insert(TABLE_NAME, null, values);
|
||||
|
||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && Recipient.resolved(recipientId).isMuted();
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
|
||||
notifyConversationListeners(threadId);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.signal.core.util.optionalLong
|
|||
import org.signal.core.util.optionalString
|
||||
import org.signal.core.util.or
|
||||
import org.signal.core.util.readToSet
|
||||
import org.signal.core.util.readToSingleBoolean
|
||||
import org.signal.core.util.requireBlob
|
||||
import org.signal.core.util.requireBoolean
|
||||
import org.signal.core.util.requireInt
|
||||
|
@ -3064,6 +3065,16 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
|||
return results
|
||||
}
|
||||
|
||||
/** True if the recipient exists and is muted, otherwise false. */
|
||||
fun isMuted(id: RecipientId): Boolean {
|
||||
return readableDatabase
|
||||
.select(MUTE_UNTIL)
|
||||
.from(TABLE_NAME)
|
||||
.where("$ID = ?", id)
|
||||
.run()
|
||||
.readToSingleBoolean()
|
||||
}
|
||||
|
||||
fun getRegisteredE164s(): Set<String> {
|
||||
return readableDatabase
|
||||
.select(PHONE)
|
||||
|
|
|
@ -243,7 +243,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
|||
.where("$ID = ?", threadId)
|
||||
.run()
|
||||
|
||||
if (unarchive) {
|
||||
if (unarchive && allowedToUnarchive(threadId)) {
|
||||
val archiveValues = contentValuesOf(ARCHIVED to 0)
|
||||
val query = SqlUtil.buildTrueUpdateQuery(ID_WHERE, SqlUtil.buildArgs(threadId), archiveValues)
|
||||
if (writableDatabase.update(TABLE_NAME, archiveValues, query.where, query.whereArgs) > 0) {
|
||||
|
@ -252,6 +252,16 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
|||
}
|
||||
}
|
||||
|
||||
private fun allowedToUnarchive(threadId: Long): Boolean {
|
||||
if (!SignalStore.settings().shouldKeepMutedChatsArchived()) {
|
||||
return true
|
||||
}
|
||||
|
||||
val threadRecipientId: RecipientId? = getRecipientIdForThreadId(threadId)
|
||||
|
||||
return threadRecipientId == null || !recipients.isMuted(threadRecipientId)
|
||||
}
|
||||
|
||||
fun updateSnippetUriSilently(threadId: Long, attachment: Uri?) {
|
||||
writableDatabase
|
||||
.update(TABLE_NAME)
|
||||
|
@ -272,7 +282,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
|||
SNIPPET_URI to attachment?.toString()
|
||||
)
|
||||
|
||||
if (unarchive) {
|
||||
if (unarchive && allowedToUnarchive(threadId)) {
|
||||
contentValues.put(ARCHIVED, 0)
|
||||
}
|
||||
|
||||
|
|
|
@ -126,8 +126,7 @@ public final class IdentityUtil {
|
|||
} catch (MmsException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && recipient.isMuted();
|
||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,16 @@ fun Cursor.readToSingleInt(defaultValue: Int = 0): Int {
|
|||
}
|
||||
}
|
||||
|
||||
fun Cursor.readToSingleBoolean(defaultValue: Boolean = false): Boolean {
|
||||
return use {
|
||||
if (it.moveToFirst()) {
|
||||
it.getInt(0) != 0
|
||||
} else {
|
||||
defaultValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
inline fun <T> Cursor.readToList(predicate: (T) -> Boolean = { true }, mapper: (Cursor) -> T): List<T> {
|
||||
val list = mutableListOf<T>()
|
||||
|
|
Loading…
Add table
Reference in a new issue