Skip to content

Commit 79a0967

Browse files
Merge pull request #1613 from session-foundation/fix/reaction-notifications
Reaction notifications
2 parents 4901be7 + 4b59add commit 79a0967

File tree

13 files changed

+121
-285
lines changed

13 files changed

+121
-285
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,7 @@
432432
</intent-filter>
433433
</receiver>
434434
<receiver android:name="org.thoughtcrime.securesms.notifications.DeleteNotificationReceiver"
435-
android:exported="true">
436-
<intent-filter>
437-
<action android:name="network.loki.securesms.DELETE_NOTIFICATION" />
438-
</intent-filter>
435+
android:exported="false">
439436
</receiver>
440437
<receiver
441438
android:name="org.thoughtcrime.securesms.service.PanicResponderListener"

app/src/main/java/org/session/libsession/database/StorageProtocol.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ interface StorageProtocol {
181181
attachments: List<Attachment>,
182182
runThreadUpdate: Boolean
183183
): MessageId?
184-
fun markConversationAsRead(threadId: Long, lastSeenTime: Long, force: Boolean = false)
184+
fun markConversationAsRead(threadId: Long, lastSeenTime: Long, force: Boolean = false, updateNotification: Boolean = true)
185185
fun markConversationAsUnread(threadId: Long)
186186
fun getLastSeen(threadId: Long): Long
187187
fun ensureMessageHashesAreSender(hashes: Set<String>, sender: String, closedGroupId: String): Boolean

app/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/MessageNotifier.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import android.content.Context
55
interface MessageNotifier {
66
fun setHomeScreenVisible(isVisible: Boolean)
77
fun setVisibleThread(threadId: Long)
8-
fun setLastDesktopActivityTimestamp(timestamp: Long)
9-
fun cancelDelayedNotifications()
108
fun updateNotification(context: Context)
119
fun updateNotification(context: Context, threadId: Long)
1210
fun updateNotification(context: Context, threadId: Long, signal: Boolean)
1311
fun updateNotification(context: Context, signal: Boolean, reminderCount: Int)
14-
fun clearReminder(context: Context)
1512
}

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,18 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
13761376
val maybeTargetVisiblePosition = layoutManager?.findLastVisibleItemPosition()
13771377
val targetVisiblePosition = maybeTargetVisiblePosition ?: RecyclerView.NO_POSITION
13781378
if (!firstLoad.get() && targetVisiblePosition != RecyclerView.NO_POSITION) {
1379-
adapter.getTimestampForItemAt(targetVisiblePosition)?.let { visibleItemTimestamp ->
1380-
bufferedLastSeenChannel.trySend(visibleItemTimestamp).apply {
1381-
if (isFailure) Log.e(TAG, "trySend failed", exceptionOrNull())
1382-
}
1379+
val timestampToSend: Long? = if (binding.conversationRecyclerView.isFullyScrolled) {
1380+
// We are at the bottom, so mark "now" as the last seen time
1381+
clock.currentTimeMills()
1382+
} else {
1383+
// We are not at the bottom, so just mark the timestamp of the last visible message
1384+
adapter.getTimestampForItemAt(targetVisiblePosition)
1385+
}
1386+
1387+
timestampToSend?.let {
1388+
bufferedLastSeenChannel.trySend(it).apply {
1389+
if (isFailure) Log.e(TAG, "trySend failed", exceptionOrNull())
1390+
}
13831391
}
13841392
}
13851393

app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,17 @@ open class Storage @Inject constructor(
191191
return messages.map { it.second } // return the message hashes
192192
}
193193

194-
override fun markConversationAsRead(threadId: Long, lastSeenTime: Long, force: Boolean) {
194+
override fun markConversationAsRead(threadId: Long, lastSeenTime: Long, force: Boolean, updateNotification: Boolean) {
195195
val threadDb = threadDatabase
196196
getRecipientForThread(threadId)?.let { recipient ->
197-
val currentLastRead = threadDb.getLastSeenAndHasSent(threadId).first()
198197
// don't set the last read in the volatile if we didn't set it in the DB
199-
if (!threadDb.markAllAsRead(threadId, lastSeenTime, force) && !force) return
198+
if (!threadDb.markAllAsRead(threadId, lastSeenTime, force, updateNotification) && !force) return
200199

201200
// don't process configs for inbox recipients
202201
if (recipient.isCommunityInboxRecipient) return
203202

203+
val currentLastRead = threadDb.getLastSeenAndHasSent(threadId).first()
204+
204205
configFactory.withMutableUserConfigs { configs ->
205206
val config = configs.convoInfoVolatile
206207
val convo = getConvo(recipient, config) ?: return@withMutableUserConfigs

app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,15 @@ public boolean isRead(long threadId) {
761761
/**
762762
* @param threadId
763763
* @param lastSeenTime
764+
* @param force
765+
* @param updateNotifications - if true, update the notification state. Set to false if you already came from a notification interaction
764766
* @return true if we have set the last seen for the thread, false if there were no messages in the thread
765767
*/
766-
public boolean markAllAsRead(long threadId, long lastSeenTime, boolean force) {
768+
public boolean markAllAsRead(long threadId, long lastSeenTime, boolean force, boolean updateNotifications) {
767769
if (mmsSmsDatabase.get().getConversationCount(threadId) <= 0 && !force) return false;
768770
List<MarkedMessageInfo> messages = setRead(threadId, lastSeenTime);
769771
MarkReadReceiver.process(context, messages);
770-
messageNotifier.get().updateNotification(context, threadId);
772+
if(updateNotifications) messageNotifier.get().updateNotification(context, threadId);
771773
return setLastSeen(threadId, lastSeenTime);
772774
}
773775

app/src/main/java/org/thoughtcrime/securesms/dependencies/DatabaseComponent.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,10 @@ interface DatabaseComponent {
2929
fun mediaDatabase(): MediaDatabase
3030
fun threadDatabase(): ThreadDatabase
3131
fun mmsSmsDatabase(): MmsSmsDatabase
32-
fun draftDatabase(): DraftDatabase
33-
fun pushDatabase(): PushDatabase
3432
fun groupDatabase(): GroupDatabase
3533
fun recipientDatabase(): RecipientDatabase
36-
fun groupReceiptDatabase(): GroupReceiptDatabase
37-
fun searchDatabase(): SearchDatabase
3834
fun lokiAPIDatabase(): LokiAPIDatabase
3935
fun lokiMessageDatabase(): LokiMessageDatabase
40-
fun lokiUserDatabase(): LokiUserDatabase
41-
fun lokiBackupFilesDatabase(): LokiBackupFilesDatabase
42-
fun sessionJobDatabase(): SessionJobDatabase
43-
fun sessionContactDatabase(): SessionContactDatabase
4436
fun reactionDatabase(): ReactionDatabase
45-
fun emojiSearchDatabase(): EmojiSearchDatabase
4637
fun storage(): Storage
47-
fun attachmentProvider(): MessageDataProvider
48-
fun blindedIdMappingDatabase(): BlindedIdMappingDatabase
49-
fun groupMemberDatabase(): GroupMemberDatabase
50-
fun expirationConfigurationDatabase(): ExpirationConfigurationDatabase
51-
fun configDatabase(): ConfigDatabase
5238
}

0 commit comments

Comments
 (0)