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">
|
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||||
<value />
|
<value />
|
||||||
</option>
|
</option>
|
||||||
|
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
||||||
|
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
|
||||||
</JetCodeStyleSettings>
|
</JetCodeStyleSettings>
|
||||||
<codeStyleSettings language="HTML">
|
<codeStyleSettings language="HTML">
|
||||||
<indentOptions>
|
<indentOptions>
|
||||||
|
|
|
@ -639,14 +639,13 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
values.put(TYPE, type);
|
values.put(TYPE, type);
|
||||||
values.put(THREAD_ID, threadId);
|
values.put(THREAD_ID, threadId);
|
||||||
|
|
||||||
long messageId = getWritableDatabase().insert(TABLE_NAME, null, values);
|
long messageId = getWritableDatabase().insert(TABLE_NAME, null, values);
|
||||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && Recipient.resolved(recipientId).isMuted();
|
|
||||||
|
|
||||||
if (unread) {
|
if (unread) {
|
||||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
SignalDatabase.threads().update(threadId, true);
|
||||||
|
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
TrimThreadJob.enqueueAsync(threadId);
|
TrimThreadJob.enqueueAsync(threadId);
|
||||||
|
@ -661,15 +660,14 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
values.put(READ, unread ? 0 : 1);
|
values.put(READ, unread ? 0 : 1);
|
||||||
getWritableDatabase().update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(messageId));
|
getWritableDatabase().update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(messageId));
|
||||||
|
|
||||||
long threadId = getThreadIdForMessage(messageId);
|
long threadId = getThreadIdForMessage(messageId);
|
||||||
Recipient recipient = SignalDatabase.threads().getRecipientForThreadId(threadId);
|
Recipient recipient = SignalDatabase.threads().getRecipientForThreadId(threadId);
|
||||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && recipient != null && recipient.isMuted();
|
|
||||||
|
|
||||||
if (unread) {
|
if (unread) {
|
||||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
SignalDatabase.threads().update(threadId, true);
|
||||||
|
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(messageId));
|
ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(messageId));
|
||||||
|
@ -719,8 +717,8 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
|
|
||||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
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();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -796,8 +794,7 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && recipient.isMuted();
|
SignalDatabase.threads().update(threadId, true);
|
||||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -948,8 +945,7 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
final boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && (recipient.isMuted() || (groupRecipient != null && groupRecipient.isMuted()));
|
SignalDatabase.threads().update(threadId, true);
|
||||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getSubscriptionId() != -1) {
|
if (message.getSubscriptionId() != -1) {
|
||||||
|
@ -2503,8 +2499,6 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
if (threadRecipientId == null) {
|
if (threadRecipientId == null) {
|
||||||
threadRecipientId = retrieved.getFrom();
|
threadRecipientId = retrieved.getFrom();
|
||||||
}
|
}
|
||||||
boolean keepThreadArchived = threadRecipientId != null && SignalStore.settings().shouldKeepMutedChatsArchived() && Recipient.resolved(threadRecipientId).isMuted();
|
|
||||||
|
|
||||||
long messageId = insertMediaMessage(threadId,
|
long messageId = insertMediaMessage(threadId,
|
||||||
retrieved.getBody(),
|
retrieved.getBody(),
|
||||||
retrieved.getAttachments(),
|
retrieved.getAttachments(),
|
||||||
|
@ -2516,13 +2510,14 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
contentValues,
|
contentValues,
|
||||||
null,
|
null,
|
||||||
updateThread,
|
updateThread,
|
||||||
!keepThreadArchived);
|
true);
|
||||||
|
|
||||||
boolean isNotStoryGroupReply = retrieved.getParentStoryId() == null || !retrieved.getParentStoryId().isGroupReply();
|
boolean isNotStoryGroupReply = retrieved.getParentStoryId() == null || !retrieved.getParentStoryId().isGroupReply();
|
||||||
|
|
||||||
if (!MessageTypes.isPaymentsActivated(mailbox) && !MessageTypes.isPaymentsRequestToActivate(mailbox) && !MessageTypes.isExpirationTimerUpdate(mailbox) && !retrieved.getStoryType().isStory() && isNotStoryGroupReply) {
|
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()));
|
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().incrementUnread(threadId, 1, incrementUnreadMentions ? 1 : 0);
|
||||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
SignalDatabase.threads().update(threadId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
|
@ -2671,8 +2666,7 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
long messageId = db.insert(TABLE_NAME, null, values);
|
long messageId = db.insert(TABLE_NAME, null, values);
|
||||||
|
|
||||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && Recipient.resolved(recipientId).isMuted();
|
SignalDatabase.threads().update(threadId, true);
|
||||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
|
||||||
|
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
|
|
||||||
|
@ -2695,8 +2689,7 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||||
databaseHelper.getSignalWritableDatabase().insert(TABLE_NAME, null, values);
|
databaseHelper.getSignalWritableDatabase().insert(TABLE_NAME, null, values);
|
||||||
|
|
||||||
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
SignalDatabase.threads().incrementUnread(threadId, 1, 0);
|
||||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && Recipient.resolved(recipientId).isMuted();
|
SignalDatabase.threads().update(threadId, true);
|
||||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
|
||||||
|
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.signal.core.util.optionalLong
|
||||||
import org.signal.core.util.optionalString
|
import org.signal.core.util.optionalString
|
||||||
import org.signal.core.util.or
|
import org.signal.core.util.or
|
||||||
import org.signal.core.util.readToSet
|
import org.signal.core.util.readToSet
|
||||||
|
import org.signal.core.util.readToSingleBoolean
|
||||||
import org.signal.core.util.requireBlob
|
import org.signal.core.util.requireBlob
|
||||||
import org.signal.core.util.requireBoolean
|
import org.signal.core.util.requireBoolean
|
||||||
import org.signal.core.util.requireInt
|
import org.signal.core.util.requireInt
|
||||||
|
@ -3064,6 +3065,16 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||||
return results
|
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> {
|
fun getRegisteredE164s(): Set<String> {
|
||||||
return readableDatabase
|
return readableDatabase
|
||||||
.select(PHONE)
|
.select(PHONE)
|
||||||
|
|
|
@ -243,7 +243,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||||
.where("$ID = ?", threadId)
|
.where("$ID = ?", threadId)
|
||||||
.run()
|
.run()
|
||||||
|
|
||||||
if (unarchive) {
|
if (unarchive && allowedToUnarchive(threadId)) {
|
||||||
val archiveValues = contentValuesOf(ARCHIVED to 0)
|
val archiveValues = contentValuesOf(ARCHIVED to 0)
|
||||||
val query = SqlUtil.buildTrueUpdateQuery(ID_WHERE, SqlUtil.buildArgs(threadId), archiveValues)
|
val query = SqlUtil.buildTrueUpdateQuery(ID_WHERE, SqlUtil.buildArgs(threadId), archiveValues)
|
||||||
if (writableDatabase.update(TABLE_NAME, archiveValues, query.where, query.whereArgs) > 0) {
|
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?) {
|
fun updateSnippetUriSilently(threadId: Long, attachment: Uri?) {
|
||||||
writableDatabase
|
writableDatabase
|
||||||
.update(TABLE_NAME)
|
.update(TABLE_NAME)
|
||||||
|
@ -272,7 +282,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||||
SNIPPET_URI to attachment?.toString()
|
SNIPPET_URI to attachment?.toString()
|
||||||
)
|
)
|
||||||
|
|
||||||
if (unarchive) {
|
if (unarchive && allowedToUnarchive(threadId)) {
|
||||||
contentValues.put(ARCHIVED, 0)
|
contentValues.put(ARCHIVED, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,8 +126,7 @@ public final class IdentityUtil {
|
||||||
} catch (MmsException e) {
|
} catch (MmsException e) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
boolean keepThreadArchived = SignalStore.settings().shouldKeepMutedChatsArchived() && recipient.isMuted();
|
SignalDatabase.threads().update(threadId, true);
|
||||||
SignalDatabase.threads().update(threadId, !keepThreadArchived);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
@JvmOverloads
|
||||||
inline fun <T> Cursor.readToList(predicate: (T) -> Boolean = { true }, mapper: (Cursor) -> T): List<T> {
|
inline fun <T> Cursor.readToList(predicate: (T) -> Boolean = { true }, mapper: (Cursor) -> T): List<T> {
|
||||||
val list = mutableListOf<T>()
|
val list = mutableListOf<T>()
|
||||||
|
|
Loading…
Add table
Reference in a new issue