✨ iOS quick reply (finished)
This commit is contained in:
parent
be98fe133d
commit
7182336a0d
@ -38,13 +38,10 @@ target 'Runner' do
|
|||||||
|
|
||||||
target 'SolarNotifyService' do
|
target 'SolarNotifyService' do
|
||||||
inherit! :search_paths
|
inherit! :search_paths
|
||||||
use_frameworks!
|
|
||||||
use_modular_headers!
|
|
||||||
|
|
||||||
pod 'home_widget', :path => '.symlinks/plugins/home_widget/ios'
|
pod 'home_widget', :path => '.symlinks/plugins/home_widget/ios'
|
||||||
pod 'shared_preferences_foundation', :path => '.symlinks/plugins/shared_preferences_foundation/darwin'
|
|
||||||
|
|
||||||
pod 'Kingfisher', '~> 8.0'
|
pod 'Kingfisher', '~> 8.0'
|
||||||
|
pod 'Alamofire'
|
||||||
end
|
end
|
||||||
|
|
||||||
target 'SolarWidgetExtension' do
|
target 'SolarWidgetExtension' do
|
||||||
@ -53,7 +50,6 @@ target 'Runner' do
|
|||||||
use_modular_headers!
|
use_modular_headers!
|
||||||
|
|
||||||
pod 'home_widget', :path => '.symlinks/plugins/home_widget/ios'
|
pod 'home_widget', :path => '.symlinks/plugins/home_widget/ios'
|
||||||
pod 'shared_preferences_foundation', :path => '.symlinks/plugins/shared_preferences_foundation/darwin'
|
|
||||||
|
|
||||||
pod 'Kingfisher', '~> 8.0'
|
pod 'Kingfisher', '~> 8.0'
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
PODS:
|
PODS:
|
||||||
|
- Alamofire (5.10.2)
|
||||||
- connectivity_plus (0.0.1):
|
- connectivity_plus (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
@ -221,6 +222,7 @@ PODS:
|
|||||||
- Flutter
|
- Flutter
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
|
- Alamofire
|
||||||
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
|
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
|
||||||
- croppy (from `.symlinks/plugins/croppy/ios`)
|
- croppy (from `.symlinks/plugins/croppy/ios`)
|
||||||
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
|
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
|
||||||
@ -257,6 +259,7 @@ DEPENDENCIES:
|
|||||||
|
|
||||||
SPEC REPOS:
|
SPEC REPOS:
|
||||||
trunk:
|
trunk:
|
||||||
|
- Alamofire
|
||||||
- DKImagePickerController
|
- DKImagePickerController
|
||||||
- DKPhotoGallery
|
- DKPhotoGallery
|
||||||
- Firebase
|
- Firebase
|
||||||
@ -343,6 +346,7 @@ EXTERNAL SOURCES:
|
|||||||
:path: ".symlinks/plugins/workmanager/ios"
|
:path: ".symlinks/plugins/workmanager/ios"
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
|
Alamofire: 7193b3b92c74a07f85569e1a6c4f4237291e7496
|
||||||
connectivity_plus: 18382e7311ba19efcaee94442b23b32507b20695
|
connectivity_plus: 18382e7311ba19efcaee94442b23b32507b20695
|
||||||
croppy: b6199bc8d56bd2e03cc11609d1c47ad9875c1321
|
croppy: b6199bc8d56bd2e03cc11609d1c47ad9875c1321
|
||||||
device_info_plus: bf2e3232933866d73fe290f2942f2156cdd10342
|
device_info_plus: bf2e3232933866d73fe290f2942f2156cdd10342
|
||||||
@ -394,6 +398,6 @@ SPEC CHECKSUMS:
|
|||||||
WebRTC-SDK: 79942c006ea64f6fb48d7da8a4786dfc820bc1db
|
WebRTC-SDK: 79942c006ea64f6fb48d7da8a4786dfc820bc1db
|
||||||
workmanager: 0afdcf5628bbde6924c21af7836fed07b42e30e6
|
workmanager: 0afdcf5628bbde6924c21af7836fed07b42e30e6
|
||||||
|
|
||||||
PODFILE CHECKSUM: c287205af8b370f21f61cbff93ce745f0157a3c8
|
PODFILE CHECKSUM: 9b244e02f87527430136c8d21cbdcf1cd586b6bc
|
||||||
|
|
||||||
COCOAPODS: 1.16.2
|
COCOAPODS: 1.16.2
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import home_widget
|
import home_widget
|
||||||
|
import Alamofire
|
||||||
|
|
||||||
class NotifyDelegate: UIResponder, UNUserNotificationCenterDelegate {
|
class NotifyDelegate: UIResponder, UNUserNotificationCenterDelegate {
|
||||||
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
||||||
@ -19,21 +20,34 @@ class NotifyDelegate: UIResponder, UNUserNotificationCenterDelegate {
|
|||||||
let channelId = metadata["channel_id"] as? Int
|
let channelId = metadata["channel_id"] as? Int
|
||||||
let eventId = metadata["event_id"] as? Int
|
let eventId = metadata["event_id"] as? Int
|
||||||
|
|
||||||
|
let replyToken = metadata["reply_token"] as? String
|
||||||
|
|
||||||
if #available(iOS 17, *) {
|
if (channelId == nil || eventId == nil || replyToken == nil) {
|
||||||
Task {
|
return;
|
||||||
await HomeWidgetBackgroundWorker.run(
|
|
||||||
url: URL(string: "solink:///chat/reply")?.appending(queryItems: [
|
|
||||||
URLQueryItem(name: "channel_id", value: String(channelId ?? 0)),
|
|
||||||
URLQueryItem(name: "event_id", value: String(eventId ?? 0)),
|
|
||||||
URLQueryItem(name: "text", value: textResponse.userText)
|
|
||||||
]),
|
|
||||||
appGroup: "group.solsynth.solian"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fallback on earlier versions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let serverUrl = "https://api.sn.solsynth.dev"
|
||||||
|
let url = "\(serverUrl)/cgi/im/quick/\(channelId!)/reply/\(eventId!)?replyToken=\(replyToken!)"
|
||||||
|
|
||||||
|
let parameters: [String: Any] = [
|
||||||
|
"type": "messages.new",
|
||||||
|
"body": [
|
||||||
|
"text": textResponse.userText,
|
||||||
|
"algorithm": "plain"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default)
|
||||||
|
.validate()
|
||||||
|
.responseString { response in
|
||||||
|
switch response.result {
|
||||||
|
case .success(_):
|
||||||
|
break
|
||||||
|
case .failure(let error):
|
||||||
|
print("Failed to send chat reply message: \(error)")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
completionHandler()
|
completionHandler()
|
||||||
|
@ -57,23 +57,6 @@ void appBackgroundDispatcher() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@pragma("vm:entry-point")
|
|
||||||
FutureOr<void> appInteractiveBackgroundDispatcher(Uri? data) async {
|
|
||||||
print('Interactive background dispatcher called with $data');
|
|
||||||
switch (data?.path) {
|
|
||||||
case "/chat/reply":
|
|
||||||
final channelId = data?.queryParameters['channel_id'];
|
|
||||||
final eventId = data?.queryParameters['event_id'];
|
|
||||||
final message = data?.queryParameters['text'];
|
|
||||||
if (channelId != null && eventId != null && (message?.isNotEmpty ?? false)) {
|
|
||||||
await chatReplyMessage(channelId, eventId, message!);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await EasyLocalization.ensureInitialized();
|
await EasyLocalization.ensureInitialized();
|
||||||
|
@ -140,19 +140,3 @@ class ChatChannelProvider extends ChangeNotifier {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> chatReplyMessage(channelId, eventId, String message) async {
|
|
||||||
print('Chat reply message called with $channelId $eventId $message');
|
|
||||||
try {
|
|
||||||
final snc = await SnNetworkProvider.createOffContextClient();
|
|
||||||
await snc.post('/cgi/im/quick/$channelId/reply/$eventId', data: {
|
|
||||||
'type': 'messages.new',
|
|
||||||
'body': {
|
|
||||||
'text': message,
|
|
||||||
'algorithm': 'plain',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
print('Failed to send chat reply message: $err');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -5,7 +5,6 @@ import 'dart:io';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:home_widget/home_widget.dart';
|
import 'package:home_widget/home_widget.dart';
|
||||||
import 'package:surface/main.dart';
|
|
||||||
import 'package:surface/providers/sn_network.dart';
|
import 'package:surface/providers/sn_network.dart';
|
||||||
import 'package:surface/types/post.dart';
|
import 'package:surface/types/post.dart';
|
||||||
|
|
||||||
@ -17,8 +16,6 @@ class HomeWidgetProvider {
|
|||||||
if (!kIsWeb && Platform.isIOS) {
|
if (!kIsWeb && Platform.isIOS) {
|
||||||
await HomeWidget.setAppGroupId("group.solsynth.solian");
|
await HomeWidget.setAppGroupId("group.solsynth.solian");
|
||||||
}
|
}
|
||||||
|
|
||||||
await HomeWidget.registerInteractivityCallback(appInteractiveBackgroundDispatcher);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveWidgetData(String id, dynamic data, {bool update = true}) async {
|
Future<void> saveWidgetData(String id, dynamic data, {bool update = true}) async {
|
||||||
|
@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 2.1.1+35
|
version: 2.1.1+36
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.4
|
sdk: ^3.5.4
|
||||||
|
Loading…
Reference in New Issue
Block a user