feat: 投稿番剧评论时转发到动态

This commit is contained in:
guozhigq
2024-04-21 16:47:38 +08:00
parent e707789986
commit 03e1cfe356
3 changed files with 65 additions and 8 deletions

View File

@ -152,16 +152,28 @@ class DynamicsHttp {
}
static Future dynamicCreate({
required String dynIdStr,
required int mid,
required int scene,
int? oid,
String? dynIdStr,
String? rawText,
}) async {
DateTime now = DateTime.now();
int timestamp = now.millisecondsSinceEpoch ~/ 1000;
Random random = Random();
int randomNumber = random.nextInt(9000) + 1000;
String uploadId =
mid.toString() + timestamp.toString() + randomNumber.toString();
String uploadId = '${mid}_${timestamp}_$randomNumber';
Map<String, dynamic> webRepostSrc = {
'dyn_id_str': dynIdStr ?? '',
};
/// 投稿转发
if (scene == 5) {
webRepostSrc = {
'revs_id': {'dyn_type': 8, 'rid': oid}
};
}
var res = await Request().post(Api.dynamicCreate, queryParameters: {
'platform': 'web',
'csrf': await Request.getCsrf(),
@ -174,14 +186,14 @@ class DynamicsHttp {
{'raw_text': rawText ?? '', 'type': 1, 'biz_id': ''}
]
},
'scene': 4,
'scene': scene,
'attach_card': null,
'upload_id': uploadId,
'meta': {
'app_meta': {'from': 'create.dynamic.web', 'mobi_app': 'web'}
}
},
'web_repost_src': {'dyn_id_str': dynIdStr}
'web_repost_src': webRepostSrc
});
if (res.data['code'] == 0) {
return {

View File

@ -361,6 +361,7 @@ class _ActionPanelState extends State<ActionPanel>
dynIdStr: dynamicId,
mid: _dynamicsController.userInfo.mid,
rawText: _inputText,
scene: 4,
);
if (res['status']) {
SmartDialog.showToast(type == 'forward' ? '转发成功' : '发布成功');

View File

@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/http/dynamics.dart';
import 'package:pilipala/http/video.dart';
import 'package:pilipala/models/common/reply_type.dart';
import 'package:pilipala/models/video/reply/emote.dart';
@ -40,6 +41,8 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
double keyboardHeight = 0.0; // 键盘高度
final _debouncer = Debouncer(milliseconds: 200); // 设置延迟时间
String toolbarType = 'input';
RxBool isForward = false.obs;
RxBool showForward = false.obs;
@override
void initState() {
@ -52,6 +55,10 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
_autoFocus();
// 监听聚焦状态
_focuslistener();
final String routePath = Get.currentRoute;
if (routePath.startsWith('/video')) {
showForward.value = true;
}
}
_autoFocus() async {
@ -88,6 +95,16 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
Get.back(result: {
'data': ReplyItemModel.fromJson(result['data']['reply'], ''),
});
/// 投稿、番剧页面
if (isForward.value) {
await DynamicsHttp.dynamicCreate(
mid: 0,
rawText: message,
oid: widget.oid!,
scene: 5,
);
}
} else {
SmartDialog.showToast(result['msg']);
}
@ -145,7 +162,6 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
double _keyboardHeight = EdgeInsets.fromViewPadding(
View.of(context).viewInsets, View.of(context).devicePixelRatio)
.bottom;
print('_keyboardHeight: $_keyboardHeight');
return Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
@ -225,9 +241,37 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
toolbarType: toolbarType,
selected: toolbarType == 'emote',
),
const SizedBox(width: 6),
Obx(
() => showForward.value
? TextButton.icon(
onPressed: () {
isForward.value = !isForward.value;
},
icon: Icon(
isForward.value
? Icons.check_box
: Icons.check_box_outline_blank,
size: 22),
label: const Text('转发到动态'),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(
isForward.value
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.outline,
),
),
)
: const SizedBox(),
),
const Spacer(),
TextButton(
onPressed: () => submitReplyAdd(), child: const Text('发送'))
SizedBox(
height: 36,
child: FilledButton(
onPressed: () => submitReplyAdd(),
child: const Text('发送'),
),
),
],
),
),