mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Fix emoji notifications (#960)
* fix: don't notify on group threads * fix: flip boolean and compile issue * build: update build number
This commit is contained in:
parent
361ff8370b
commit
7d186c198e
@ -156,8 +156,8 @@ dependencies {
|
||||
testImplementation 'org.robolectric:shadows-multidex:4.4'
|
||||
}
|
||||
|
||||
def canonicalVersionCode = 296
|
||||
def canonicalVersionName = "1.15.1"
|
||||
def canonicalVersionCode = 297
|
||||
def canonicalVersionName = "1.15.2"
|
||||
|
||||
def postFixSize = 10
|
||||
def abiPostFix = ['armeabi-v7a' : 1,
|
||||
|
@ -1054,7 +1054,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
dateSent = emojiTimestamp,
|
||||
dateReceived = emojiTimestamp
|
||||
)
|
||||
reactionDb.addReaction(MessageId(originalMessage.id, originalMessage.isMms), reaction)
|
||||
reactionDb.addReaction(MessageId(originalMessage.id, originalMessage.isMms), reaction, false)
|
||||
val originalAuthor = if (originalMessage.isOutgoing) {
|
||||
fromSerialized(viewModel.blindedPublicKey ?: textSecurePreferences.getLocalNumber()!!)
|
||||
} else originalMessage.individualRecipient.address
|
||||
@ -1077,7 +1077,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
val emojiTimestamp = System.currentTimeMillis()
|
||||
message.sentTimestamp = emojiTimestamp
|
||||
val author = textSecurePreferences.getLocalNumber()!!
|
||||
reactionDb.deleteReaction(emoji, MessageId(originalMessage.id, originalMessage.isMms), author)
|
||||
reactionDb.deleteReaction(emoji, MessageId(originalMessage.id, originalMessage.isMms), author, false)
|
||||
|
||||
val originalAuthor = if (originalMessage.isOutgoing) {
|
||||
fromSerialized(viewModel.blindedPublicKey ?: textSecurePreferences.getLocalNumber()!!)
|
||||
|
@ -13,10 +13,10 @@ import org.session.libsession.utilities.IdentityKeyMismatch;
|
||||
import org.session.libsession.utilities.IdentityKeyMismatchList;
|
||||
import org.session.libsignal.crypto.IdentityKey;
|
||||
import org.session.libsignal.utilities.JsonUtil;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.util.SqlUtil;
|
||||
import org.session.libsignal.utilities.Log;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.util.SqlUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -67,15 +67,19 @@ public abstract class MessagingDatabase extends Database implements MmsSmsColumn
|
||||
}
|
||||
}
|
||||
|
||||
void updateReactionsUnread(SQLiteDatabase db, long messageId, boolean hasReactions, boolean isRemoval) {
|
||||
void updateReactionsUnread(SQLiteDatabase db, long messageId, boolean hasReactions, boolean isRemoval, boolean notifyUnread) {
|
||||
try {
|
||||
MessageRecord message = getMessageRecord(messageId);
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
if (!hasReactions) {
|
||||
if (notifyUnread) {
|
||||
if (!hasReactions) {
|
||||
values.put(REACTIONS_UNREAD, 0);
|
||||
} else if (!isRemoval) {
|
||||
values.put(REACTIONS_UNREAD, 1);
|
||||
}
|
||||
} else {
|
||||
values.put(REACTIONS_UNREAD, 0);
|
||||
} else if (!isRemoval) {
|
||||
values.put(REACTIONS_UNREAD, 1);
|
||||
}
|
||||
|
||||
if (message.isOutgoing() && hasReactions) {
|
||||
|
@ -94,7 +94,7 @@ class ReactionDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
||||
return reactions
|
||||
}
|
||||
|
||||
fun addReaction(messageId: MessageId, reaction: ReactionRecord) {
|
||||
fun addReaction(messageId: MessageId, reaction: ReactionRecord, notifyUnread: Boolean) {
|
||||
|
||||
writableDatabase.beginTransaction()
|
||||
try {
|
||||
@ -113,9 +113,9 @@ class ReactionDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
||||
writableDatabase.insert(TABLE_NAME, null, values)
|
||||
|
||||
if (messageId.mms) {
|
||||
DatabaseComponent.get(context).mmsDatabase().updateReactionsUnread(writableDatabase, messageId.id, hasReactions(messageId), false)
|
||||
DatabaseComponent.get(context).mmsDatabase().updateReactionsUnread(writableDatabase, messageId.id, hasReactions(messageId), false, notifyUnread)
|
||||
} else {
|
||||
DatabaseComponent.get(context).smsDatabase().updateReactionsUnread(writableDatabase, messageId.id, hasReactions(messageId), false)
|
||||
DatabaseComponent.get(context).smsDatabase().updateReactionsUnread(writableDatabase, messageId.id, hasReactions(messageId), false, notifyUnread)
|
||||
}
|
||||
|
||||
writableDatabase.setTransactionSuccessful()
|
||||
@ -124,11 +124,12 @@ class ReactionDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteReaction(emoji: String, messageId: MessageId, author: String) {
|
||||
fun deleteReaction(emoji: String, messageId: MessageId, author: String, notifyUnread: Boolean) {
|
||||
deleteReactions(
|
||||
messageId = messageId,
|
||||
query = "$MESSAGE_ID = ? AND $IS_MMS = ? AND $EMOJI = ? AND $AUTHOR_ID = ?",
|
||||
args = arrayOf("${messageId.id}", "${if (messageId.mms) 1 else 0}", emoji, author)
|
||||
args = arrayOf("${messageId.id}", "${if (messageId.mms) 1 else 0}", emoji, author),
|
||||
notifyUnread
|
||||
)
|
||||
}
|
||||
|
||||
@ -136,7 +137,8 @@ class ReactionDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
||||
deleteReactions(
|
||||
messageId = messageId,
|
||||
query = "$MESSAGE_ID = ? AND $IS_MMS = ? AND $EMOJI = ?",
|
||||
args = arrayOf("${messageId.id}", "${if (messageId.mms) 1 else 0}", emoji)
|
||||
args = arrayOf("${messageId.id}", "${if (messageId.mms) 1 else 0}", emoji),
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
@ -144,19 +146,20 @@ class ReactionDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
||||
deleteReactions(
|
||||
messageId = messageId,
|
||||
query = "$MESSAGE_ID = ? AND $IS_MMS = ?",
|
||||
args = arrayOf("${messageId.id}", "${if (messageId.mms) 1 else 0}")
|
||||
args = arrayOf("${messageId.id}", "${if (messageId.mms) 1 else 0}"),
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
private fun deleteReactions(messageId: MessageId, query: String, args: Array<String>) {
|
||||
private fun deleteReactions(messageId: MessageId, query: String, args: Array<String>, notifyUnread: Boolean) {
|
||||
writableDatabase.beginTransaction()
|
||||
try {
|
||||
writableDatabase.delete(TABLE_NAME, query, args)
|
||||
|
||||
if (messageId.mms) {
|
||||
DatabaseComponent.get(context).mmsDatabase().updateReactionsUnread(writableDatabase, messageId.id, hasReactions(messageId), true)
|
||||
DatabaseComponent.get(context).mmsDatabase().updateReactionsUnread(writableDatabase, messageId.id, hasReactions(messageId), true, notifyUnread)
|
||||
} else {
|
||||
DatabaseComponent.get(context).smsDatabase().updateReactionsUnread(writableDatabase, messageId.id, hasReactions(messageId), true)
|
||||
DatabaseComponent.get(context).smsDatabase().updateReactionsUnread(writableDatabase, messageId.id, hasReactions(messageId), true, notifyUnread)
|
||||
}
|
||||
|
||||
writableDatabase.setTransactionSuccessful()
|
||||
|
@ -892,7 +892,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
return mapping
|
||||
}
|
||||
|
||||
override fun addReaction(reaction: Reaction, messageSender: String) {
|
||||
override fun addReaction(reaction: Reaction, messageSender: String, notifyUnread: Boolean) {
|
||||
val timestamp = reaction.timestamp
|
||||
val localId = reaction.localId
|
||||
val isMms = reaction.isMms
|
||||
@ -914,14 +914,15 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
sortId = reaction.index!!,
|
||||
dateSent = reaction.dateSent!!,
|
||||
dateReceived = reaction.dateReceived!!
|
||||
)
|
||||
),
|
||||
notifyUnread
|
||||
)
|
||||
}
|
||||
|
||||
override fun removeReaction(emoji: String, messageTimestamp: Long, author: String) {
|
||||
override fun removeReaction(emoji: String, messageTimestamp: Long, author: String, notifyUnread: Boolean) {
|
||||
val messageRecord = DatabaseComponent.get(context).mmsSmsDatabase().getMessageForTimestamp(messageTimestamp) ?: return
|
||||
val messageId = MessageId(messageRecord.id, messageRecord.isMms)
|
||||
DatabaseComponent.get(context).reactionDatabase().deleteReaction(emoji, messageId, author)
|
||||
DatabaseComponent.get(context).reactionDatabase().deleteReaction(emoji, messageId, author, notifyUnread)
|
||||
}
|
||||
|
||||
override fun updateReactionIfNeeded(message: Message, sender: String, openGroupSentTimestamp: Long) {
|
||||
|
@ -190,8 +190,8 @@ interface StorageProtocol {
|
||||
fun removeLastOutboxMessageId(server: String)
|
||||
fun getOrCreateBlindedIdMapping(blindedId: String, server: String, serverPublicKey: String, fromOutbox: Boolean = false): BlindedIdMapping
|
||||
|
||||
fun addReaction(reaction: Reaction, messageSender: String)
|
||||
fun removeReaction(emoji: String, messageTimestamp: Long, author: String)
|
||||
fun addReaction(reaction: Reaction, messageSender: String, notifyUnread: Boolean)
|
||||
fun removeReaction(emoji: String, messageTimestamp: Long, author: String, notifyUnread: Boolean)
|
||||
fun updateReactionIfNeeded(message: Message, sender: String, openGroupSentTimestamp: Long)
|
||||
fun deleteReactions(messageId: Long, mms: Boolean)
|
||||
}
|
||||
|
@ -230,6 +230,7 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage,
|
||||
// Thread doesn't exist; should only be reached in a case where we are processing open group messages for a no longer existent thread
|
||||
throw MessageReceiver.Error.NoThread
|
||||
}
|
||||
val threadRecipient = storage.getRecipientForThread(threadID)
|
||||
// Update profile if needed
|
||||
val recipient = Recipient.from(context, Address.fromSerialized(messageSender!!), false)
|
||||
if (runProfileUpdate) {
|
||||
@ -295,14 +296,15 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage,
|
||||
}
|
||||
}
|
||||
// Parse reaction if needed
|
||||
val threadIsGroup = threadRecipient?.isGroupRecipient == true
|
||||
message.reaction?.let { reaction ->
|
||||
if (reaction.react == true) {
|
||||
reaction.serverId = message.openGroupServerMessageID?.toString() ?: message.serverHash.orEmpty()
|
||||
reaction.dateSent = message.sentTimestamp ?: 0
|
||||
reaction.dateReceived = message.receivedTimestamp ?: 0
|
||||
storage.addReaction(reaction, messageSender)
|
||||
storage.addReaction(reaction, messageSender, !threadIsGroup)
|
||||
} else {
|
||||
storage.removeReaction(reaction.emoji!!, reaction.timestamp!!, reaction.publicKey!!)
|
||||
storage.removeReaction(reaction.emoji!!, reaction.timestamp!!, reaction.publicKey!!, threadIsGroup)
|
||||
}
|
||||
} ?: run {
|
||||
// Persist the message
|
||||
@ -357,7 +359,7 @@ fun MessageReceiver.handleOpenGroupReactions(
|
||||
serverId = "$openGroupMessageServerID",
|
||||
count = count,
|
||||
index = reaction.index
|
||||
), reactor)
|
||||
), reactor, false)
|
||||
}
|
||||
|
||||
// Add all other reactions
|
||||
@ -373,7 +375,7 @@ fun MessageReceiver.handleOpenGroupReactions(
|
||||
serverId = "$openGroupMessageServerID",
|
||||
count = 0, // Only want this on the first reaction
|
||||
index = reaction.index
|
||||
), reactor)
|
||||
), reactor, false)
|
||||
}
|
||||
|
||||
// Add the current user reaction (if applicable and not already included)
|
||||
@ -387,7 +389,7 @@ fun MessageReceiver.handleOpenGroupReactions(
|
||||
serverId = "$openGroupMessageServerID",
|
||||
count = 1,
|
||||
index = reaction.index
|
||||
), userPublicKey)
|
||||
), userPublicKey, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user