Răsfoiți Sursa

add last chats to share suggestions

cyberta 5 ani în urmă
părinte
comite
81be036ea5

+ 12 - 0
DcCore/DcCore/DC/Wrapper.swift

@@ -93,6 +93,7 @@ public class DcContext {
 
     public func sendMsgSync(chatId: Int, msg: DcMsg) {
         dc_send_msg_sync(contextPointer, UInt32(chatId), msg.messagePointer)
+        DcUtils.donateSendMessageIntent(chatId: chatId)
     }
 
     public func getChatMedia(chatId: Int, messageType: Int32, messageType2: Int32, messageType3: Int32) -> [Int] {
@@ -269,10 +270,12 @@ public class DcContext {
 
     public func forwardMessage(with msgId: Int, to chat: Int) {
         dc_forward_msgs(contextPointer, [UInt32(msgId)], 1, UInt32(chat))
+        DcUtils.donateSendMessageIntent(chatId: chat)
     }
 
     public func sendTextInChat(id: Int, message: String) {
         dc_send_text_msg(contextPointer, UInt32(id), message)
+        DcUtils.donateSendMessageIntent(chatId: id)
     }
 
     public func initiateKeyTransfer() -> String? {
@@ -408,6 +411,7 @@ public class DcContext {
 
     public func sendLocationsToChat(chatId: Int, seconds: Int) {
         dc_send_locations_to_chat(contextPointer, UInt32(chatId), Int32(seconds))
+        //TODO: discuss if we want to omit the message intent donation here here
     }
 
     public func setLocation(latitude: Double, longitude: Double, accuracy: Double) {
@@ -582,6 +586,13 @@ public class DcContext {
     }
 }
 
+
+
+
+
+
+
+
 public class DcEventEmitter {
     private var eventEmitterPointer: OpaquePointer?
 
@@ -1014,6 +1025,7 @@ public class DcMsg {
 
     public func sendInChat(id: Int) {
         dc_send_msg(DcContext.shared.contextPointer, UInt32(id), messagePointer)
+        DcUtils.donateSendMessageIntent(chatId: chatId)
     }
 
     public func previousMediaURLs() -> [URL] {

+ 33 - 0
DcCore/DcCore/Helper/DcUtils.swift

@@ -2,6 +2,7 @@ import Foundation
 import UIKit
 import MobileCoreServices
 import AVFoundation
+import Intents
 
 public struct DcUtils {
 
@@ -13,6 +14,38 @@ public struct DcUtils {
         }
     }
 
+    public static func donateSendMessageIntent(chatId: Int) {
+       let chat = DcContext.shared.getChat(chatId: chatId)
+       let groupName = INSpeakableString(spokenPhrase: chat.name)
+
+       let sendMessageIntent = INSendMessageIntent(recipients: nil,
+                                                   content: nil,
+                                                   speakableGroupName: groupName,
+                                                   conversationIdentifier: "\(chat.id)",
+                                                   serviceName: nil,
+                                                   sender: nil)
+
+       // Add the user's avatar to the intent.
+        if #available(iOS 12.0, *) {
+            if let imageData = chat.profileImage?.pngData() {
+                let image = INImage(imageData: imageData)
+                sendMessageIntent.setImage(image, forParameterNamed: \.speakableGroupName)
+            }
+        }
+
+       // Donate the intent.
+       let interaction = INInteraction(intent: sendMessageIntent, response: nil)
+       interaction.donate(completion: { error in
+           if error != nil {
+               // Add error handling here.
+                DcContext.shared.logger?.error(error.debugDescription)
+           } else {
+               // Do something, e.g. send the content to a contact.
+                DcContext.shared.logger?.debug("donated message intent")
+           }
+       })
+    }
+
     static func copyAndFreeArray(inputArray: OpaquePointer?) -> [Int] {
         var acc: [Int] = []
         let len = dc_array_get_cnt(inputArray)

+ 4 - 0
DcShare/Info.plist

@@ -24,6 +24,10 @@
 	<dict>
 		<key>NSExtensionAttributes</key>
 		<dict>
+			<key>IntentsSupported</key>
+			<array>
+				<string>INSendMessageIntent</string>
+			</array>
 			<key>NSExtensionActivationRule</key>
 			<string>SUBQUERY (
 extensionItems,

+ 4 - 0
deltachat-ios/Info.plist

@@ -2,6 +2,10 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
+	<key>NSUserActivityTypes</key>
+	<array>
+		<string>INSendMessageIntent</string>
+	</array>
 	<key>CFBundleDevelopmentRegion</key>
 	<string>$(DEVELOPMENT_LANGUAGE)</string>
 	<key>CFBundleDisplayName</key>