iOS quick reply (finished)

This commit is contained in:
LittleSheep 2024-12-21 22:19:27 +08:00
parent be98fe133d
commit 7182336a0d
7 changed files with 34 additions and 56 deletions

View File

@ -38,13 +38,10 @@ target 'Runner' do
target 'SolarNotifyService' do
inherit! :search_paths
use_frameworks!
use_modular_headers!
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 'Alamofire'
end
target 'SolarWidgetExtension' do
@ -53,7 +50,6 @@ target 'Runner' do
use_modular_headers!
pod 'home_widget', :path => '.symlinks/plugins/home_widget/ios'
pod 'shared_preferences_foundation', :path => '.symlinks/plugins/shared_preferences_foundation/darwin'
pod 'Kingfisher', '~> 8.0'
end

View File

@ -1,4 +1,5 @@
PODS:
- Alamofire (5.10.2)
- connectivity_plus (0.0.1):
- Flutter
- FlutterMacOS
@ -221,6 +222,7 @@ PODS:
- Flutter
DEPENDENCIES:
- Alamofire
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
- croppy (from `.symlinks/plugins/croppy/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
@ -257,6 +259,7 @@ DEPENDENCIES:
SPEC REPOS:
trunk:
- Alamofire
- DKImagePickerController
- DKPhotoGallery
- Firebase
@ -343,6 +346,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/workmanager/ios"
SPEC CHECKSUMS:
Alamofire: 7193b3b92c74a07f85569e1a6c4f4237291e7496
connectivity_plus: 18382e7311ba19efcaee94442b23b32507b20695
croppy: b6199bc8d56bd2e03cc11609d1c47ad9875c1321
device_info_plus: bf2e3232933866d73fe290f2942f2156cdd10342
@ -394,6 +398,6 @@ SPEC CHECKSUMS:
WebRTC-SDK: 79942c006ea64f6fb48d7da8a4786dfc820bc1db
workmanager: 0afdcf5628bbde6924c21af7836fed07b42e30e6
PODFILE CHECKSUM: c287205af8b370f21f61cbff93ce745f0157a3c8
PODFILE CHECKSUM: 9b244e02f87527430136c8d21cbdcf1cd586b6bc
COCOAPODS: 1.16.2

View File

@ -7,6 +7,7 @@
import Foundation
import home_widget
import Alamofire
class NotifyDelegate: UIResponder, UNUserNotificationCenterDelegate {
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 eventId = metadata["event_id"] as? Int
let replyToken = metadata["reply_token"] as? String
if #available(iOS 17, *) {
Task {
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
if (channelId == nil || eventId == nil || replyToken == nil) {
return;
}
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()

View File

@ -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 {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();

View File

@ -140,19 +140,3 @@ class ChatChannelProvider extends ChangeNotifier {
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');
}
}

View File

@ -5,7 +5,6 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:home_widget/home_widget.dart';
import 'package:surface/main.dart';
import 'package:surface/providers/sn_network.dart';
import 'package:surface/types/post.dart';
@ -17,8 +16,6 @@ class HomeWidgetProvider {
if (!kIsWeb && Platform.isIOS) {
await HomeWidget.setAppGroupId("group.solsynth.solian");
}
await HomeWidget.registerInteractivityCallback(appInteractiveBackgroundDispatcher);
}
Future<void> saveWidgetData(String id, dynamic data, {bool update = true}) async {

View File

@ -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
# 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.
version: 2.1.1+35
version: 2.1.1+36
environment:
sdk: ^3.5.4