Browse Source

send video chat invites

cyberta 4 years ago
parent
commit
69877853cd
2 changed files with 29 additions and 0 deletions
  1. 4 0
      DcCore/DcCore/DC/Wrapper.swift
  2. 25 0
      deltachat-ios/Chat/ChatViewController.swift

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

@@ -126,6 +126,10 @@ public class DcContext {
         dc_send_msg(contextPointer, UInt32(chatId), message.messagePointer)
     }
 
+    public func sendVideoChatInvitation(chatId: Int) -> Int {
+        return Int(dc_send_videochat_invitation(contextPointer,  UInt32(chatId)))
+    }
+
     // TODO: remove count and from parameters if we don't use it
     public func getMessageIds(chatId: Int, count: Int? = nil, from: Int? = nil) -> [Int] {
         let start = CFAbsoluteTimeGetCurrent()

+ 25 - 0
deltachat-ios/Chat/ChatViewController.swift

@@ -990,11 +990,13 @@ class ChatViewController: UITableViewController {
         let locationStreamingAction = UIAlertAction(title: isLocationStreaming ? String.localized("stop_sharing_location") : String.localized("location"),
                                                     style: isLocationStreaming ? .destructive : .default,
                                                     handler: locationStreamingButtonPressed(_:))
+        let videoChatInvitation = UIAlertAction(title: String.localized("videochat"), style: .default, handler: videoChatButtonPressed(_:))
 
         alert.addAction(cameraAction)
         alert.addAction(galleryAction)
         alert.addAction(documentAction)
         alert.addAction(voiceMessageAction)
+        alert.addAction(videoChatInvitation)
         if UserDefaults.standard.bool(forKey: "location_streaming") {
             alert.addAction(locationStreamingAction)
         }
@@ -1170,6 +1172,29 @@ class ChatViewController: UITableViewController {
         }
     }
 
+    private func videoChatButtonPressed(_ action: UIAlertAction) {
+        let chat = dcContext.getChat(chatId: chatId)
+
+        let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("videochat_invite_user_to_videochat"), chat.name),
+                                      message: String.localized("videochat_invite_user_hint"),
+                                      preferredStyle: .alert)
+        let cancel = UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil)
+        let ok = UIAlertAction(title: String.localized("ok"),
+                               style: .default,
+                               handler: { _ in
+                                DispatchQueue.global(qos: .userInitiated).async { [weak self] in
+                                    guard let self = self else { return }
+                                    let messageId = self.dcContext.sendVideoChatInvitation(chatId: self.chatId)
+                                    let inviteMessage = self.dcContext.getMessage(id: messageId)
+                                    if let url = NSURL(string: inviteMessage.getVideoChatUrl()) {
+                                        UIApplication.shared.open(url as URL)
+                                    }
+                                }})
+        alert.addAction(ok)
+        alert.addAction(cancel)
+        self.present(alert, animated: true, completion: nil)
+    }
+
     private func addDurationSelectionAction(to alert: UIAlertController, key: String, duration: Int) {
         let action = UIAlertAction(title: String.localized(key), style: .default, handler: { _ in
             self.locationStreamingFor(seconds: duration)