feat: 私信页面表情面板
This commit is contained in:
@ -496,4 +496,7 @@ class Api {
|
||||
/// 已读标记
|
||||
static const String ackSessionMsg =
|
||||
'${HttpString.tUrl}/session_svr/v1/session_svr/update_ack';
|
||||
|
||||
/// 发送私信
|
||||
static const String sendMsg = '${HttpString.tUrl}/web_im/v1/web_im/send_msg';
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'dart:math';
|
||||
import '../models/msg/account.dart';
|
||||
import '../models/msg/session.dart';
|
||||
import '../utils/wbi_sign.dart';
|
||||
@ -22,10 +23,18 @@ class MsgHttp {
|
||||
Map signParams = await WbiSign().makSign(params);
|
||||
var res = await Request().get(Api.sessionList, data: signParams);
|
||||
if (res.data['code'] == 0) {
|
||||
try {
|
||||
return {
|
||||
'status': true,
|
||||
'data': SessionDataModel.fromJson(res.data['data']),
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
'status': false,
|
||||
'date': [],
|
||||
'msg': err.toString(),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
@ -42,12 +51,16 @@ class MsgHttp {
|
||||
'mobi_app': 'web',
|
||||
});
|
||||
if (res.data['code'] == 0) {
|
||||
try {
|
||||
return {
|
||||
'status': true,
|
||||
'data': res.data['data']
|
||||
.map<AccountListModel>((e) => AccountListModel.fromJson(e))
|
||||
.toList(),
|
||||
};
|
||||
} catch (err) {
|
||||
print('err🔟: $err');
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
@ -118,4 +131,93 @@ class MsgHttp {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 发送私信
|
||||
static Future sendMsg({
|
||||
int? senderUid,
|
||||
int? receiverId,
|
||||
int? receiverType,
|
||||
int? msgType,
|
||||
dynamic content,
|
||||
}) async {
|
||||
String csrf = await Request.getCsrf();
|
||||
Map<String, dynamic> params = await WbiSign().makSign({
|
||||
'msg[sender_uid]': senderUid,
|
||||
'msg[receiver_id]': receiverId,
|
||||
'msg[receiver_type]': receiverType ?? 1,
|
||||
'msg[msg_type]': msgType ?? 1,
|
||||
'msg[msg_status]': 0,
|
||||
'msg[dev_id]': getDevId(),
|
||||
'msg[timestamp]': DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
'msg[new_face_version]': 0,
|
||||
'msg[content]': content,
|
||||
'from_firework': 0,
|
||||
'build': 0,
|
||||
'mobi_app': 'web',
|
||||
'csrf_token': csrf,
|
||||
'csrf': csrf,
|
||||
});
|
||||
var res =
|
||||
await Request().post(Api.sendMsg, queryParameters: <String, dynamic>{
|
||||
...params,
|
||||
'csrf_token': csrf,
|
||||
'csrf': csrf,
|
||||
}, data: {
|
||||
'w_sender_uid': params['msg[sender_uid]'],
|
||||
'w_receiver_id': params['msg[receiver_id]'],
|
||||
'w_dev_id': params['msg[dev_id]'],
|
||||
'w_rid': params['w_rid'],
|
||||
'wts': params['wts'],
|
||||
'csrf_token': csrf,
|
||||
'csrf': csrf,
|
||||
});
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': res.data['data'],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'date': [],
|
||||
'msg': "message: ${res.data['message']},"
|
||||
" msg: ${res.data['msg']},"
|
||||
" code: ${res.data['code']}",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static String getDevId() {
|
||||
final List<String> b = [
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'A',
|
||||
'B',
|
||||
'C',
|
||||
'D',
|
||||
'E',
|
||||
'F'
|
||||
];
|
||||
final List<String> s = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split('');
|
||||
for (int i = 0; i < s.length; i++) {
|
||||
if ('-' == s[i] || '4' == s[i]) {
|
||||
continue;
|
||||
}
|
||||
final int randomInt = Random().nextInt(16);
|
||||
if ('x' == s[i]) {
|
||||
s[i] = b[randomInt];
|
||||
} else {
|
||||
s[i] = b[3 & randomInt | 8];
|
||||
}
|
||||
}
|
||||
return s.join();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class SessionDataModel {
|
||||
this.hasMore,
|
||||
});
|
||||
|
||||
List? sessionList;
|
||||
List<SessionList>? sessionList;
|
||||
int? hasMore;
|
||||
|
||||
SessionDataModel.fromJson(Map<String, dynamic> json) {
|
||||
@ -121,35 +121,37 @@ class LastMsg {
|
||||
this.msgKey,
|
||||
this.msgStatus,
|
||||
this.notifyCode,
|
||||
this.newFaceVersion,
|
||||
// this.newFaceVersion,
|
||||
});
|
||||
|
||||
int? senderIid;
|
||||
int? receiverType;
|
||||
int? receiverId;
|
||||
int? msgType;
|
||||
Map? content;
|
||||
dynamic content;
|
||||
int? msgSeqno;
|
||||
int? timestamp;
|
||||
String? atUids;
|
||||
int? msgKey;
|
||||
int? msgStatus;
|
||||
String? notifyCode;
|
||||
int? newFaceVersion;
|
||||
// int? newFaceVersion;
|
||||
|
||||
LastMsg.fromJson(Map<String, dynamic> json) {
|
||||
senderIid = json['sender_uid'];
|
||||
receiverType = json['receiver_type'];
|
||||
receiverId = json['receiver_id'];
|
||||
msgType = json['msg_type'];
|
||||
content = jsonDecode(json['content']);
|
||||
content = json['content'] != null && json['content'] != ''
|
||||
? jsonDecode(json['content'])
|
||||
: '';
|
||||
msgSeqno = json['msg_seqno'];
|
||||
timestamp = json['timestamp'];
|
||||
atUids = json['at_uids'];
|
||||
msgKey = json['msg_key'];
|
||||
msgStatus = json['msg_status'];
|
||||
notifyCode = json['notify_code'];
|
||||
newFaceVersion = json['new_face_version'];
|
||||
// newFaceVersion = json['new_face_version'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,7 +216,9 @@ class MessageItem {
|
||||
receiverId = json['receiver_id'];
|
||||
// 1 文本 2 图片 18 系统提示 10 系统通知 5 撤回的消息
|
||||
msgType = json['msg_type'];
|
||||
content = jsonDecode(json['content']);
|
||||
content = json['content'] != null && json['content'] != ''
|
||||
? jsonDecode(json['content'])
|
||||
: '';
|
||||
msgSeqno = json['msg_seqno'];
|
||||
timestamp = json['timestamp'];
|
||||
atUids = json['at_uids'];
|
||||
|
@ -108,8 +108,8 @@ class _WhisperPageState extends State<WhisperPage> {
|
||||
future: _futureBuilderFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
Map data = snapshot.data as Map;
|
||||
if (data['status']) {
|
||||
Map? data = snapshot.data;
|
||||
if (data != null && data['status']) {
|
||||
RxList sessionList = _whisperController.sessionList;
|
||||
return Obx(
|
||||
() => sessionList.isEmpty
|
||||
@ -162,7 +162,13 @@ class _WhisperPageState extends State<WhisperPage> {
|
||||
title: Text(
|
||||
sessionList[i].accountInfo.name),
|
||||
subtitle: Text(
|
||||
sessionList[i].lastMsg.content !=
|
||||
null &&
|
||||
sessionList[i]
|
||||
.lastMsg
|
||||
.content !=
|
||||
''
|
||||
? (sessionList[i]
|
||||
.lastMsg
|
||||
.content['text'] ??
|
||||
sessionList[i]
|
||||
@ -174,8 +180,8 @@ class _WhisperPageState extends State<WhisperPage> {
|
||||
sessionList[i]
|
||||
.lastMsg
|
||||
.content[
|
||||
'reply_content'] ??
|
||||
'',
|
||||
'reply_content'])
|
||||
: '不支持的消息类型',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context)
|
||||
@ -212,7 +218,9 @@ class _WhisperPageState extends State<WhisperPage> {
|
||||
);
|
||||
} else {
|
||||
// 请求错误
|
||||
return const SizedBox();
|
||||
return Center(
|
||||
child: Text(data?['msg'] ?? '请求异常'),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
|
@ -1,7 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/http/msg.dart';
|
||||
import 'package:pilipala/models/msg/session.dart';
|
||||
import '../../utils/feed_back.dart';
|
||||
import '../../utils/storage.dart';
|
||||
|
||||
class WhisperDetailController extends GetxController {
|
||||
late int talkerId;
|
||||
@ -11,6 +15,8 @@ class WhisperDetailController extends GetxController {
|
||||
RxList<MessageItem> messageList = <MessageItem>[].obs;
|
||||
//表情转换图片规则
|
||||
List<dynamic>? eInfos;
|
||||
final TextEditingController replyContentController = TextEditingController();
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@ -42,14 +48,34 @@ class WhisperDetailController extends GetxController {
|
||||
if (messageList.isEmpty) {
|
||||
return;
|
||||
}
|
||||
var res = await MsgHttp.ackSessionMsg(
|
||||
await MsgHttp.ackSessionMsg(
|
||||
talkerId: talkerId,
|
||||
ackSeqno: messageList.last.msgSeqno,
|
||||
);
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast("已读成功");
|
||||
}
|
||||
|
||||
Future sendMsg() async {
|
||||
feedBack();
|
||||
String message = replyContentController.text;
|
||||
final userInfo = userInfoCache.get('userInfoCache');
|
||||
if (userInfo == null) {
|
||||
SmartDialog.showToast('请先登录');
|
||||
return;
|
||||
}
|
||||
if (message == '') {
|
||||
SmartDialog.showToast('请输入内容');
|
||||
return;
|
||||
}
|
||||
var result = await MsgHttp.sendMsg(
|
||||
senderUid: userInfo.mid,
|
||||
receiverId: int.parse(mid),
|
||||
content: {'content': message},
|
||||
msgType: 1,
|
||||
);
|
||||
if (result['status']) {
|
||||
SmartDialog.showToast('发送成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/pages/emote/index.dart';
|
||||
import 'package:pilipala/pages/whisper_detail/controller.dart';
|
||||
import 'package:pilipala/utils/feed_back.dart';
|
||||
|
||||
import '../../utils/storage.dart';
|
||||
import 'widget/chat_item.dart';
|
||||
|
||||
class WhisperDetailPage extends StatefulWidget {
|
||||
@ -13,15 +16,63 @@ class WhisperDetailPage extends StatefulWidget {
|
||||
State<WhisperDetailPage> createState() => _WhisperDetailPageState();
|
||||
}
|
||||
|
||||
class _WhisperDetailPageState extends State<WhisperDetailPage> {
|
||||
class _WhisperDetailPageState extends State<WhisperDetailPage>
|
||||
with WidgetsBindingObserver {
|
||||
final WhisperDetailController _whisperDetailController =
|
||||
Get.put(WhisperDetailController());
|
||||
late Future _futureBuilderFuture;
|
||||
late TextEditingController _replyContentController;
|
||||
final FocusNode replyContentFocusNode = FocusNode();
|
||||
final _debouncer = Debouncer(milliseconds: 200); // 设置延迟时间
|
||||
late double emoteHeight = 0.0;
|
||||
double keyboardHeight = 0.0; // 键盘高度
|
||||
String toolbarType = 'input';
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_futureBuilderFuture = _whisperDetailController.querySessionMsg();
|
||||
_replyContentController = _whisperDetailController.replyContentController;
|
||||
_focuslistener();
|
||||
}
|
||||
|
||||
_focuslistener() {
|
||||
replyContentFocusNode.addListener(() {
|
||||
if (replyContentFocusNode.hasFocus) {
|
||||
setState(() {
|
||||
toolbarType = 'input';
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeMetrics() {
|
||||
super.didChangeMetrics();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// 键盘高度
|
||||
final viewInsets = EdgeInsets.fromViewPadding(
|
||||
View.of(context).viewInsets, View.of(context).devicePixelRatio);
|
||||
_debouncer.run(() {
|
||||
if (mounted) {
|
||||
if (keyboardHeight == 0) {
|
||||
setState(() {
|
||||
emoteHeight = keyboardHeight =
|
||||
keyboardHeight == 0.0 ? viewInsets.bottom : keyboardHeight;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
replyContentFocusNode.removeListener(() {});
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -89,7 +140,14 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
body: GestureDetector(
|
||||
onTap: () {
|
||||
FocusScope.of(context).unfocus();
|
||||
setState(() {
|
||||
keyboardHeight = 0;
|
||||
});
|
||||
},
|
||||
child: FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
@ -134,10 +192,11 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
// resizeToAvoidBottomInset: true,
|
||||
bottomNavigationBar: Container(
|
||||
width: double.infinity,
|
||||
height: MediaQuery.of(context).padding.bottom + 70,
|
||||
height: MediaQuery.of(context).padding.bottom + 70 + keyboardHeight,
|
||||
padding: EdgeInsets.only(
|
||||
left: 8,
|
||||
right: 12,
|
||||
@ -152,7 +211,9 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -164,7 +225,14 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
|
||||
// ),
|
||||
// ),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
// if (toolbarType == 'input') {
|
||||
// setState(() {
|
||||
// toolbarType = 'emote';
|
||||
// });
|
||||
// }
|
||||
// FocusScope.of(context).unfocus();
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.emoji_emotions_outlined,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
@ -174,13 +242,18 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
|
||||
child: Container(
|
||||
height: 45,
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
Theme.of(context).colorScheme.primary.withOpacity(0.08),
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary
|
||||
.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(40.0),
|
||||
),
|
||||
child: TextField(
|
||||
readOnly: true,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
controller: _replyContentController,
|
||||
autofocus: false,
|
||||
focusNode: replyContentFocusNode,
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none, // 移除默认边框
|
||||
hintText: '开发中 ...', // 提示文本
|
||||
@ -190,10 +263,50 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
IconButton(
|
||||
// onPressed: _whisperDetailController.sendMsg,
|
||||
onPressed: null,
|
||||
icon: Icon(
|
||||
Icons.send,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
// const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
AnimatedSize(
|
||||
curve: Curves.easeInOut,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: toolbarType == 'input' ? keyboardHeight : emoteHeight,
|
||||
child: EmotePanel(
|
||||
onChoose: (package, emote) => {},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
typedef DebounceCallback = void Function();
|
||||
|
||||
class Debouncer {
|
||||
DebounceCallback? callback;
|
||||
final int? milliseconds;
|
||||
Timer? _timer;
|
||||
|
||||
Debouncer({this.milliseconds});
|
||||
|
||||
run(DebounceCallback callback) {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(Duration(milliseconds: milliseconds!), () {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -352,7 +352,9 @@ class ChatItem extends StatelessWidget {
|
||||
));
|
||||
default:
|
||||
return Text(
|
||||
content['content'] ?? content.toString(),
|
||||
content != null && content != ''
|
||||
? (content['content'] ?? content.toString())
|
||||
: '不支持的消息类型',
|
||||
style: TextStyle(
|
||||
letterSpacing: 0.6,
|
||||
height: 1.5,
|
||||
|
Reference in New Issue
Block a user