Commit db2ccb27 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

file transfer: add notifications

Change-Id: Ibf3a864f01de08fcd4e562f319d60d3ab662b63e
parent f8a33d0f
...@@ -384,6 +384,8 @@ internal enum L10n { ...@@ -384,6 +384,8 @@ internal enum L10n {
internal static let incomingCall = L10n.tr("Localizable", "notifications.incomingCall") internal static let incomingCall = L10n.tr("Localizable", "notifications.incomingCall")
/// Missed Call /// Missed Call
internal static let missedCall = L10n.tr("Localizable", "notifications.missedCall") internal static let missedCall = L10n.tr("Localizable", "notifications.missedCall")
/// New file
internal static let newFile = L10n.tr("Localizable", "notifications.newFile")
/// REFUSE /// REFUSE
internal static let refuseCall = L10n.tr("Localizable", "notifications.refuseCall") internal static let refuseCall = L10n.tr("Localizable", "notifications.refuseCall")
} }
......
...@@ -228,6 +228,7 @@ ...@@ -228,6 +228,7 @@
"notifications.missedCall" = "Missed Call"; "notifications.missedCall" = "Missed Call";
"notifications.acceptCall" = "ACCEPT"; "notifications.acceptCall" = "ACCEPT";
"notifications.refuseCall" = "REFUSE"; "notifications.refuseCall" = "REFUSE";
"notifications.newFile" = "New file";
"dataTransfer.readableStatusAwaiting" = "Pending…"; "dataTransfer.readableStatusAwaiting" = "Pending…";
"dataTransfer.readableStatusRefuse" = "Refuse"; "dataTransfer.readableStatusRefuse" = "Refuse";
"dataTransfer.readableStatusOngoing" = "Transferring"; "dataTransfer.readableStatusOngoing" = "Transferring";
...@@ -236,6 +237,7 @@ ...@@ -236,6 +237,7 @@
"dataTransfer.readableStatusAccept" = "Accept"; "dataTransfer.readableStatusAccept" = "Accept";
"dataTransfer.readableStatusCancel" = "Cancel"; "dataTransfer.readableStatusCancel" = "Cancel";
//Generated Message //Generated Message
"generatedMessage.contactAdded" = "Contact added"; "generatedMessage.contactAdded" = "Contact added";
"generatedMessage.invitationReceived" = "Invitation received"; "generatedMessage.invitationReceived" = "Invitation received";
......
...@@ -86,6 +86,7 @@ class ConversationsManager: MessagesAdapterDelegate { ...@@ -86,6 +86,7 @@ class ConversationsManager: MessagesAdapterDelegate {
self.conversationService.dataTransferMessageMap.removeValue(forKey: transferId) self.conversationService.dataTransferMessageMap.removeValue(forKey: transferId)
case .wait_peer_acceptance, .wait_host_acceptance: case .wait_peer_acceptance, .wait_host_acceptance:
status = DataTransferStatus.awaiting status = DataTransferStatus.awaiting
self.createTransferNotification(info: transferInfo)
self.autoAcceptTransfer(transferInfo: transferInfo, transferId: transferId, accountId: transferInfo.accountId) self.autoAcceptTransfer(transferInfo: transferInfo, transferId: transferId, accountId: transferInfo.accountId)
case .ongoing: case .ongoing:
status = DataTransferStatus.ongoing status = DataTransferStatus.ongoing
...@@ -162,22 +163,7 @@ class ConversationsManager: MessagesAdapterDelegate { ...@@ -162,22 +163,7 @@ class ConversationsManager: MessagesAdapterDelegate {
// only for jami accounts // only for jami accounts
if let hash = JamiURI(schema: URIType.ring, if let hash = JamiURI(schema: URIType.ring,
infoHach: peerUri).hash { infoHach: peerUri).hash {
self.nameService.usernameLookupStatus.single() searchNameAndPresentNotification(data: data, hash: hash)
.filter({ lookupNameResponse in
return lookupNameResponse.address != nil &&
lookupNameResponse.address == hash
})
.subscribe(onNext: { [weak self] lookupNameResponse in
if let name = lookupNameResponse.name, !name.isEmpty {
data [NotificationUserInfoKeys.name.rawValue] = name
self?.notificationHandler.presentMessageNotification(data: data)
} else if let address = lookupNameResponse.address {
data [NotificationUserInfoKeys.name.rawValue] = address
self?.notificationHandler.presentMessageNotification(data: data)
}
}).disposed(by: self.disposeBag)
self.nameService.lookupAddress(withAccount: "", nameserver: "", address: hash)
} }
} }
} }
...@@ -204,6 +190,55 @@ class ConversationsManager: MessagesAdapterDelegate { ...@@ -204,6 +190,55 @@ class ConversationsManager: MessagesAdapterDelegate {
.disposed(by: self.disposeBag) .disposed(by: self.disposeBag)
} }
func createTransferNotification(info: NSDataTransferInfo) {
if UIApplication.shared.applicationState == .active {
return
}
guard let account = self.accountsService.getAccount(fromAccountId: info.accountId), AccountModelHelper
.init(withAccount: account).isAccountRing() &&
accountsService.getCurrentProxyState(accountID: info.accountId) else {
return
}
var data = [String: String]()
var message = L10n.Notifications.newFile + " "
if let name = info.path.split(separator: "/").last {
message += name
} else {
message += info.path
}
data [NotificationUserInfoKeys.messageContent.rawValue] = message
data [NotificationUserInfoKeys.participantID.rawValue] = info.peer
data [NotificationUserInfoKeys.accountID.rawValue] = info.accountId
if let name = info.displayName {
data [NotificationUserInfoKeys.name.rawValue] = name
self.notificationHandler.presentMessageNotification(data: data)
} else {
guard let hash = JamiURI(schema: URIType.ring,
infoHach: info.peer).hash else {return}
searchNameAndPresentNotification(data: data, hash: hash)
}
}
func searchNameAndPresentNotification(data: [String: String], hash: String) {
var data = data
self.nameService.usernameLookupStatus.single()
.filter({ lookupNameResponse in
return lookupNameResponse.address != nil &&
lookupNameResponse.address == hash
})
.subscribe(onNext: { [weak self] lookupNameResponse in
if let name = lookupNameResponse.name, !name.isEmpty {
data [NotificationUserInfoKeys.name.rawValue] = name
self?.notificationHandler.presentMessageNotification(data: data)
} else if let address = lookupNameResponse.address {
data [NotificationUserInfoKeys.name.rawValue] = address
self?.notificationHandler.presentMessageNotification(data: data)
}
}).disposed(by: self.disposeBag)
self.nameService.lookupAddress(withAccount: "", nameserver: "", address: hash)
}
func messageStatusChanged(_ status: MessageStatus, for messageId: UInt64, from accountId: String, func messageStatusChanged(_ status: MessageStatus, for messageId: UInt64, from accountId: String,
to uri: String) { to uri: String) {
guard let account = self.accountsService.getAccount(fromAccountId: accountId) else { guard let account = self.accountsService.getAccount(fromAccountId: accountId) else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment