@@ -16,7 +16,9 @@ import com.getcode.model.notifications.parse
1616import com.getcode.network.BalanceController
1717import com.getcode.network.HistoryController
1818import com.getcode.network.TipController
19+ import com.getcode.network.repository.AccountRepository
1920import com.getcode.network.repository.PushRepository
21+ import com.getcode.network.repository.TransactionRepository
2022import com.getcode.ui.components.chat.utils.localizedText
2123import com.getcode.util.CurrencyUtils
2224import com.getcode.util.resources.ResourceHelper
@@ -27,7 +29,6 @@ import com.google.firebase.Firebase
2729import com.google.firebase.installations.installations
2830import com.google.firebase.messaging.FirebaseMessagingService
2931import com.google.firebase.messaging.RemoteMessage
30- import com.ionspin.kotlin.crypto.LibsodiumInitializer
3132import dagger.hilt.android.AndroidEntryPoint
3233import kotlinx.coroutines.CoroutineScope
3334import kotlinx.coroutines.Dispatchers
@@ -44,6 +45,12 @@ class CodePushMessagingService : FirebaseMessagingService(),
4445 @Inject
4546 lateinit var pushRepository: PushRepository
4647
48+ @Inject
49+ lateinit var transactionRepository: TransactionRepository
50+
51+ @Inject
52+ lateinit var accountRepository: AccountRepository
53+
4754 @Inject
4855 lateinit var resources: ResourceHelper
4956
@@ -93,6 +100,9 @@ class CodePushMessagingService : FirebaseMessagingService(),
93100 launch { historyController.fetchChats() }
94101 launch { balanceController.fetchBalanceSuspend() }
95102 }
103+ NotificationType .ExecuteSwap -> {
104+ updateOrganizerAndSwap()
105+ }
96106 NotificationType .Twitter -> {
97107 launch { tipController.checkForConnection() }
98108 }
@@ -129,6 +139,8 @@ class CodePushMessagingService : FirebaseMessagingService(),
129139 title : String ,
130140 content : String ,
131141 ) {
142+ if (! type.isNotifiable()) return
143+
132144 val notificationManager =
133145 getSystemService(Context .NOTIFICATION_SERVICE ) as NotificationManager
134146
@@ -166,21 +178,38 @@ class CodePushMessagingService : FirebaseMessagingService(),
166178
167179 notificationManager.notify(title.hashCode(), notificationBuilder.build())
168180 }
181+
182+ private fun updateOrganizerAndSwap () = launch {
183+ val owner = SessionManager .getKeyPair()
184+ if (owner == null ) {
185+ ErrorUtils .handleError(Throwable (" ExecuteSwap:: Missing owner" ))
186+ return @launch
187+ }
188+
189+ val organizer = SessionManager .getOrganizer()
190+ if (organizer == null ) {
191+ ErrorUtils .handleError(Throwable (" ExecuteSwap:: Missing organizer" ))
192+ return @launch
193+ }
194+
195+ val accountInfo = accountRepository.getTokenAccountInfos(owner).blockingGet()
196+ organizer.setAccountInfo(accountInfo)
197+ transactionRepository.swapIfNeeded(organizer)
198+ }
169199}
170200
201+
202+
171203private fun NotificationManager.getActiveNotification (notificationId : Int ): Notification ? {
172- val barNotifications = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
173- getActiveNotifications()
174- } else {
175- emptyArray()
176- }
204+ val barNotifications = getActiveNotifications()
177205 for (notification in barNotifications) {
178206 if (notification.id == notificationId) {
179207 return notification.notification
180208 }
181209 }
182210 return null
183211}
212+
184213private fun String.localizedStringByKey (resources : ResourceHelper ): String? {
185214 val name = this .replace(" ." , " _" )
186215 val resId = resources.getIdentifier(
0 commit comments