mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +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'
|
testImplementation 'org.robolectric:shadows-multidex:4.4'
|
||||||
}
|
}
|
||||||
|
|
||||||
def canonicalVersionCode = 296
|
def canonicalVersionCode = 297
|
||||||
def canonicalVersionName = "1.15.1"
|
def canonicalVersionName = "1.15.2"
|
||||||
|
|
||||||
def postFixSize = 10
|
def postFixSize = 10
|
||||||
def abiPostFix = ['armeabi-v7a' : 1,
|
def abiPostFix = ['armeabi-v7a' : 1,
|
||||||
|
@ -1054,7 +1054,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
dateSent = emojiTimestamp,
|
dateSent = emojiTimestamp,
|
||||||
dateReceived = 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) {
|
val originalAuthor = if (originalMessage.isOutgoing) {
|
||||||
fromSerialized(viewModel.blindedPublicKey ?: textSecurePreferences.getLocalNumber()!!)
|
fromSerialized(viewModel.blindedPublicKey ?: textSecurePreferences.getLocalNumber()!!)
|
||||||
} else originalMessage.individualRecipient.address
|
} else originalMessage.individualRecipient.address
|
||||||
@ -1077,7 +1077,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
val emojiTimestamp = System.currentTimeMillis()
|
val emojiTimestamp = System.currentTimeMillis()
|
||||||
message.sentTimestamp = emojiTimestamp
|
message.sentTimestamp = emojiTimestamp
|
||||||
val author = textSecurePreferences.getLocalNumber()!!
|
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) {
|
val originalAuthor = if (originalMessage.isOutgoing) {
|
||||||
fromSerialized(viewModel.blindedPublicKey ?: textSecurePreferences.getLocalNumber()!!)
|
fromSerialized(viewModel.blindedPublicKey ?: textSecurePreferences.getLocalNumber()!!)
|
||||||
|
@ -13,10 +13,10 @@ import org.session.libsession.utilities.IdentityKeyMismatch;
|
|||||||
import org.session.libsession.utilities.IdentityKeyMismatchList;
|
import org.session.libsession.utilities.IdentityKeyMismatchList;
|
||||||
import org.session.libsignal.crypto.IdentityKey;
|
import org.session.libsignal.crypto.IdentityKey;
|
||||||
import org.session.libsignal.utilities.JsonUtil;
|
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.session.libsignal.utilities.Log;
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
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.io.IOException;
|
||||||
import java.util.ArrayList;
|
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 {
|
try {
|
||||||
MessageRecord message = getMessageRecord(messageId);
|
MessageRecord message = getMessageRecord(messageId);
|
||||||
ContentValues values = new ContentValues();
|
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);
|
values.put(REACTIONS_UNREAD, 0);
|
||||||
} else if (!isRemoval) {
|
|
||||||
values.put(REACTIONS_UNREAD, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.isOutgoing() && hasReactions) {
|
if (message.isOutgoing() && hasReactions) {
|
||||||
|
@ -94,7 +94,7 @@ class ReactionDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
|||||||
return reactions
|
return reactions
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addReaction(messageId: MessageId, reaction: ReactionRecord) {
|
fun addReaction(messageId: MessageId, reaction: ReactionRecord, notifyUnread: Boolean) {
|
||||||
|
|
||||||
writableDatabase.beginTransaction()
|
writableDatabase.beginTransaction()
|
||||||
try {
|
try {
|
||||||
@ -113,9 +113,9 @@ class ReactionDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
|||||||
writableDatabase.insert(TABLE_NAME, null, values)
|
writableDatabase.insert(TABLE_NAME, null, values)
|
||||||
|
|
||||||
if (messageId.mms) {
|
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 {
|
} 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()
|
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(
|
deleteReactions(
|
||||||
messageId = messageId,
|
messageId = messageId,
|
||||||
query = "$MESSAGE_ID = ? AND $IS_MMS = ? AND $EMOJI = ? AND $AUTHOR_ID = ?",
|
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(
|
deleteReactions(
|
||||||
messageId = messageId,
|
messageId = messageId,
|
||||||
query = "$MESSAGE_ID = ? AND $IS_MMS = ? AND $EMOJI = ?",
|
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(
|
deleteReactions(
|
||||||
messageId = messageId,
|
messageId = messageId,
|
||||||
query = "$MESSAGE_ID = ? AND $IS_MMS = ?",
|
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()
|
writableDatabase.beginTransaction()
|
||||||
try {
|
try {
|
||||||
writableDatabase.delete(TABLE_NAME, query, args)
|
writableDatabase.delete(TABLE_NAME, query, args)
|
||||||
|
|
||||||
if (messageId.mms) {
|
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 {
|
} 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()
|
writableDatabase.setTransactionSuccessful()
|
||||||
|
@ -892,7 +892,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
return mapping
|
return mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addReaction(reaction: Reaction, messageSender: String) {
|
override fun addReaction(reaction: Reaction, messageSender: String, notifyUnread: Boolean) {
|
||||||
val timestamp = reaction.timestamp
|
val timestamp = reaction.timestamp
|
||||||
val localId = reaction.localId
|
val localId = reaction.localId
|
||||||
val isMms = reaction.isMms
|
val isMms = reaction.isMms
|
||||||
@ -914,14 +914,15 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
sortId = reaction.index!!,
|
sortId = reaction.index!!,
|
||||||
dateSent = reaction.dateSent!!,
|
dateSent = reaction.dateSent!!,
|
||||||
dateReceived = reaction.dateReceived!!
|
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 messageRecord = DatabaseComponent.get(context).mmsSmsDatabase().getMessageForTimestamp(messageTimestamp) ?: return
|
||||||
val messageId = MessageId(messageRecord.id, messageRecord.isMms)
|
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) {
|
override fun updateReactionIfNeeded(message: Message, sender: String, openGroupSentTimestamp: Long) {
|
||||||
|
@ -190,8 +190,8 @@ interface StorageProtocol {
|
|||||||
fun removeLastOutboxMessageId(server: String)
|
fun removeLastOutboxMessageId(server: String)
|
||||||
fun getOrCreateBlindedIdMapping(blindedId: String, server: String, serverPublicKey: String, fromOutbox: Boolean = false): BlindedIdMapping
|
fun getOrCreateBlindedIdMapping(blindedId: String, server: String, serverPublicKey: String, fromOutbox: Boolean = false): BlindedIdMapping
|
||||||
|
|
||||||
fun addReaction(reaction: Reaction, messageSender: String)
|
fun addReaction(reaction: Reaction, messageSender: String, notifyUnread: Boolean)
|
||||||
fun removeReaction(emoji: String, messageTimestamp: Long, author: String)
|
fun removeReaction(emoji: String, messageTimestamp: Long, author: String, notifyUnread: Boolean)
|
||||||
fun updateReactionIfNeeded(message: Message, sender: String, openGroupSentTimestamp: Long)
|
fun updateReactionIfNeeded(message: Message, sender: String, openGroupSentTimestamp: Long)
|
||||||
fun deleteReactions(messageId: Long, mms: Boolean)
|
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
|
// 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
|
throw MessageReceiver.Error.NoThread
|
||||||
}
|
}
|
||||||
|
val threadRecipient = storage.getRecipientForThread(threadID)
|
||||||
// Update profile if needed
|
// Update profile if needed
|
||||||
val recipient = Recipient.from(context, Address.fromSerialized(messageSender!!), false)
|
val recipient = Recipient.from(context, Address.fromSerialized(messageSender!!), false)
|
||||||
if (runProfileUpdate) {
|
if (runProfileUpdate) {
|
||||||
@ -295,14 +296,15 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Parse reaction if needed
|
// Parse reaction if needed
|
||||||
|
val threadIsGroup = threadRecipient?.isGroupRecipient == true
|
||||||
message.reaction?.let { reaction ->
|
message.reaction?.let { reaction ->
|
||||||
if (reaction.react == true) {
|
if (reaction.react == true) {
|
||||||
reaction.serverId = message.openGroupServerMessageID?.toString() ?: message.serverHash.orEmpty()
|
reaction.serverId = message.openGroupServerMessageID?.toString() ?: message.serverHash.orEmpty()
|
||||||
reaction.dateSent = message.sentTimestamp ?: 0
|
reaction.dateSent = message.sentTimestamp ?: 0
|
||||||
reaction.dateReceived = message.receivedTimestamp ?: 0
|
reaction.dateReceived = message.receivedTimestamp ?: 0
|
||||||
storage.addReaction(reaction, messageSender)
|
storage.addReaction(reaction, messageSender, !threadIsGroup)
|
||||||
} else {
|
} else {
|
||||||
storage.removeReaction(reaction.emoji!!, reaction.timestamp!!, reaction.publicKey!!)
|
storage.removeReaction(reaction.emoji!!, reaction.timestamp!!, reaction.publicKey!!, threadIsGroup)
|
||||||
}
|
}
|
||||||
} ?: run {
|
} ?: run {
|
||||||
// Persist the message
|
// Persist the message
|
||||||
@ -357,7 +359,7 @@ fun MessageReceiver.handleOpenGroupReactions(
|
|||||||
serverId = "$openGroupMessageServerID",
|
serverId = "$openGroupMessageServerID",
|
||||||
count = count,
|
count = count,
|
||||||
index = reaction.index
|
index = reaction.index
|
||||||
), reactor)
|
), reactor, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all other reactions
|
// Add all other reactions
|
||||||
@ -373,7 +375,7 @@ fun MessageReceiver.handleOpenGroupReactions(
|
|||||||
serverId = "$openGroupMessageServerID",
|
serverId = "$openGroupMessageServerID",
|
||||||
count = 0, // Only want this on the first reaction
|
count = 0, // Only want this on the first reaction
|
||||||
index = reaction.index
|
index = reaction.index
|
||||||
), reactor)
|
), reactor, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the current user reaction (if applicable and not already included)
|
// Add the current user reaction (if applicable and not already included)
|
||||||
@ -387,7 +389,7 @@ fun MessageReceiver.handleOpenGroupReactions(
|
|||||||
serverId = "$openGroupMessageServerID",
|
serverId = "$openGroupMessageServerID",
|
||||||
count = 1,
|
count = 1,
|
||||||
index = reaction.index
|
index = reaction.index
|
||||||
), userPublicKey)
|
), userPublicKey, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user