@@ -5,10 +5,12 @@ import kotlinx.coroutines.Dispatchers
55import kotlinx.coroutines.async
66import kotlinx.coroutines.awaitAll
77import kotlinx.coroutines.runBlocking
8+ import network.loki.messenger.libsession_util.ConfigBase
89import nl.komponents.kovenant.Promise
910import nl.komponents.kovenant.task
1011import org.session.libsession.messaging.MessagingModuleConfiguration
1112import org.session.libsession.messaging.messages.Message
13+ import org.session.libsession.messaging.messages.Message.Companion.senderOrSync
1214import org.session.libsession.messaging.messages.control.CallMessage
1315import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage
1416import org.session.libsession.messaging.messages.control.ConfigurationMessage
@@ -96,6 +98,26 @@ class BatchMessageReceiveJob(
9698 executeAsync(dispatcherName).get()
9799 }
98100
101+ private fun isHidden (message : Message ): Boolean {
102+ // if the contact is marked as hidden for 1on1 messages
103+ // and the message's sentTimestamp is earlier than the sentTimestamp of the last config
104+ val config = MessagingModuleConfiguration .shared.configFactory
105+ val publicKey = MessagingModuleConfiguration .shared.storage.getUserPublicKey()
106+ if (config.contacts == null || message.sentTimestamp == null || publicKey == null ) return false
107+ val contactConfigTimestamp = config.getConfigTimestamp(config.contacts!! , publicKey)
108+ if (message.groupPublicKey == null && // not a group
109+ message.openGroupServerMessageID == null && // not a community
110+ // not marked as hidden
111+ config.contacts?.get(message.senderOrSync)?.priority == ConfigBase .PRIORITY_HIDDEN &&
112+ // the message's sentTimestamp is earlier than the sentTimestamp of the last config
113+ message.sentTimestamp!! < contactConfigTimestamp
114+ ) {
115+ return true
116+ }
117+
118+ return false
119+ }
120+
99121 fun executeAsync (dispatcherName : String ): Promise <Unit , Exception > {
100122 return task {
101123 val threadMap = mutableMapOf<Long , MutableList <ParsedMessage >>()
@@ -112,6 +134,9 @@ class BatchMessageReceiveJob(
112134 val (message, proto) = MessageReceiver .parse(data, openGroupMessageServerID, openGroupPublicKey = serverPublicKey, currentClosedGroups = currentClosedGroups)
113135 message.serverHash = serverHash
114136 val parsedParams = ParsedMessage (messageParameters, message, proto)
137+
138+ if (isHidden(message)) return @forEach
139+
115140 val threadID = Message .getThreadId(message, openGroupID, storage, shouldCreateThread(parsedParams)) ? : NO_THREAD_MAPPING
116141 if (! threadMap.containsKey(threadID)) {
117142 threadMap[threadID] = mutableListOf (parsedParams)
0 commit comments