修改消息界面提示语和发送

This commit is contained in:
CYH 2023-07-19 16:14:31 +08:00
parent 92065b0cb3
commit 459e5ca108
6 changed files with 218 additions and 23 deletions

View File

@ -405,7 +405,7 @@ class _TIMUIKItHistoryMessageListItemState
return Column( return Column(
children: [ children: [
Container( Container(
height: info.containsKey('city') ? 175.sp : 135.sp, // height: info.containsKey('city') ? 175.sp : 135.sp,
width: Get.width, width: Get.width,
margin: EdgeInsets.only(left: isFromSelf ? 16 : 0, right: isFromSelf ? 0 : 16), margin: EdgeInsets.only(left: isFromSelf ? 16 : 0, right: isFromSelf ? 0 : 16),
decoration: BoxDecoration( decoration: BoxDecoration(
@ -414,6 +414,10 @@ class _TIMUIKItHistoryMessageListItemState
image: AssetImage( image: AssetImage(
getCircleImage('pic_bg'), getCircleImage('pic_bg'),
))), ))),
constraints: BoxConstraints(
maxHeight: 175.sp,
minHeight: 135.sp
),
child: Column( child: Column(
children: [ children: [
Container( Container(
@ -446,10 +450,12 @@ class _TIMUIKItHistoryMessageListItemState
), ),
if (info.containsKey('both_interests')) if (info.containsKey('both_interests'))
Container( Container(
margin: EdgeInsets.only(top: 16.sp),
margin: EdgeInsets.only(top: 16.sp,right: 16.sp),
child: Row( child: Row(
children: [ children: [
Container( Container(
margin: EdgeInsets.only(right: 5.sp), margin: EdgeInsets.only(right: 5.sp),
width: 3, width: 3,
height: 3, height: 3,
@ -457,12 +463,17 @@ class _TIMUIKItHistoryMessageListItemState
borderRadius: BorderRadius.circular(1.5), borderRadius: BorderRadius.circular(1.5),
color: Color(0xFF00FFF4)), color: Color(0xFF00FFF4)),
), ),
Text( Container(
width:Get.width - 80.sp,
child: Text(
info['both_interests'], info['both_interests'],
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 14.sp, fontSize: 14.sp,
fontWeight: FontWeight.w500), fontWeight: FontWeight.w500,),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
) )
], ],
), ),

View File

@ -1,6 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:math'; import 'dart:math';
import 'package:circle_app/app/chat/TIMUIKitChat/TIMUIKitTextField/tim_uikit_text_field_layout/narrow.dart'; import 'package:circle_app/app/chat/TIMUIKitChat/TIMUIKitTextField/tim_uikit_text_field_layout/narrow.dart';
import 'package:circle_app/main.dart';
import 'package:circle_app/util/util.dart'; import 'package:circle_app/util/util.dart';
import 'package:diff_match_patch/diff_match_patch.dart'; import 'package:diff_match_patch/diff_match_patch.dart';
import 'package:tencent_cloud_chat_uikit/business_logic/view_models/tui_setting_model.dart'; import 'package:tencent_cloud_chat_uikit/business_logic/view_models/tui_setting_model.dart';
@ -25,7 +27,6 @@ import 'package:tencent_cloud_chat_uikit/ui/views/TIMUIKitChat/TIMUIKitTextField
enum MuteStatus { none, me, all } enum MuteStatus { none, me, all }
GlobalKey<_InputTextFieldState> myInputTextFieldState = GlobalKey(); GlobalKey<_InputTextFieldState> myInputTextFieldState = GlobalKey();
class TIMInputTextField extends StatefulWidget { class TIMInputTextField extends StatefulWidget {
@ -45,7 +46,7 @@ class TIMInputTextField extends StatefulWidget {
final AutoScrollController? atMemberPanelScroll; final AutoScrollController? atMemberPanelScroll;
/// hint text for textField widget /// hint text for textField widget
final String? hintText; String? hintText;
/// config for more pannel /// config for more pannel
final MorePanelConfig? morePanelConfig; final MorePanelConfig? morePanelConfig;
@ -83,12 +84,12 @@ class TIMInputTextField extends StatefulWidget {
final String? groupType; final String? groupType;
const TIMInputTextField( TIMInputTextField(
{Key? key, {Key? key,
required this.conversationID, required this.conversationID,
required this.conversationType, required this.conversationType,
this.initText, this.initText,
this.hintText, required this.hintText,
this.scrollController, this.scrollController,
this.morePanelConfig, this.morePanelConfig,
this.customStickerPanel, this.customStickerPanel,
@ -122,6 +123,8 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
bool isAddingAtSearchWords = false; bool isAddingAtSearchWords = false;
double inputWidth = 900; double inputWidth = 900;
String hintText = '说些什么吧~';
Map<String, V2TimGroupMemberFullInfo> memberInfoMap = {}; Map<String, V2TimGroupMemberFullInfo> memberInfoMap = {};
late TextEditingController textEditingController; late TextEditingController textEditingController;
@ -257,6 +260,45 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
lastText = ""; lastText = "";
final text = textEditingController.text.trim(); final text = textEditingController.text.trim();
final convType = widget.conversationType; final convType = widget.conversationType;
if (text.isEmpty) {
if (hintText.contains('说些什么吧~')) {
showToast('请输入消息内容后发送');
return;
} else {
if ((widget.currentConversation.lastMessage?.customElem ?? null) !=
null) {
if (widget.currentConversation.lastMessage?.customElem!.extension ==
'cardData') {
sendHiText();
}
} else {
var result = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.getC2CHistoryMessageList(
userID: widget.currentConversation.userID!,
count: 1,
lastMsgID: null,
);
if (result.code == 0 && (result.data?.isNotEmpty ?? false)) {
V2TimMessage msg = result.data!.last!;
if (msg.customElem != null) {
if (msg.customElem!.extension == 'cardData') {
Map info = jsonDecode(msg.customElem!.data!);
sendHiTextMsg(info['guide_text']);
}
}
} else {
showToast('请输入消息内容后发送');
}
}
return;
}
}
if (text.isNotEmpty && text != zeroWidthSpace) { if (text.isNotEmpty && text != zeroWidthSpace) {
if (widget.model.repliedMessage != null) { if (widget.model.repliedMessage != null) {
MessageUtils.handleMessageError( MessageUtils.handleMessageError(
@ -288,7 +330,28 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
} else { } else {
showToast('请输入消息内容'); showToast('请输入消息内容');
} }
} }
sendHiText() async {
Map info =
jsonDecode(widget.currentConversation.lastMessage!.customElem!.data!);
sendHiTextMsg(info['guide_text']);
// var result = await widget.model.sendTextMessage(
// text: info['guide_text'],
// convID: widget.conversationID,
// convType: ConvType.c2c);
//
// hintText = '说些什么吧~';
// setState(() {});
}
sendHiTextMsg(String text) async {
var result = await widget.model.sendTextMessage(
text: text, convID: widget.conversationID, convType: ConvType.c2c);
hintText = '说些什么吧~';
setState(() {});
}
void goDownBottom() { void goDownBottom() {
if (globalModel.getMessageListPosition(widget.conversationID) == if (globalModel.getMessageListPosition(widget.conversationID) ==
@ -547,6 +610,7 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
checkHintText();
if (PlatformUtils().isWeb || PlatformUtils().isDesktop) { if (PlatformUtils().isWeb || PlatformUtils().isDesktop) {
focusNode = FocusNode( focusNode = FocusNode(
onKey: (node, event) { onKey: (node, event) {
@ -752,6 +816,7 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
return LayoutBuilder( return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) { builder: (BuildContext context, BoxConstraints constraints) {
inputWidth = constraints.maxWidth; inputWidth = constraints.maxWidth;
return TUIKitScreenUtils.getDeviceWidget( return TUIKitScreenUtils.getDeviceWidget(
defaultWidget: TIMTextFieldLayoutNarrow( defaultWidget: TIMTextFieldLayoutNarrow(
onEmojiSubmitted: onEmojiSubmitted, onEmojiSubmitted: onEmojiSubmitted,
@ -760,13 +825,54 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
addStickerToText: addStickerToText, addStickerToText: addStickerToText,
customStickerPanel: widget.customStickerPanel, customStickerPanel: widget.customStickerPanel,
forbiddenText: forbiddenText, forbiddenText: forbiddenText,
onChanged: (text) async {
if (widget.onChanged != null) {
widget.onChanged!(text);
}
onChanged: widget.onChanged, if (!hintText!.contains('说些什么吧~') && text.isNotEmpty) {
if ((widget.currentConversation.lastMessage
?.customElem ??
null) !=
null) {
if (widget.currentConversation.lastMessage
?.customElem!.extension ==
'cardData') {
hintText = '说些什么吧~';
setState(() {
});
}
} else {
var result = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.getC2CHistoryMessageList(
userID: widget.currentConversation.userID!,
count: 1,
lastMsgID: null,
);
if (result.code == 0 &&
(result.data?.isNotEmpty ?? false)) {
V2TimMessage msg = result.data!.last!;
if (msg.customElem != null) {
if (msg.customElem!.extension == 'cardData') {
hintText = '说些什么吧~';
setState(() {
});
}
}
}
}
}
},
backgroundColor: widget.backgroundColor, backgroundColor: widget.backgroundColor,
morePanelConfig: widget.morePanelConfig, morePanelConfig: widget.morePanelConfig,
repliedMessage: value, repliedMessage: value,
currentCursor: currentCursor, currentCursor: currentCursor,
hintText: widget.hintText, hintText: hintText,
isUseDefaultEmoji: widget.isUseDefaultEmoji, isUseDefaultEmoji: widget.isUseDefaultEmoji,
languageType: languageType, languageType: languageType,
textEditingController: textEditingController, textEditingController: textEditingController,
@ -801,7 +907,7 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
morePanelConfig: widget.morePanelConfig, morePanelConfig: widget.morePanelConfig,
repliedMessage: value, repliedMessage: value,
currentCursor: currentCursor, currentCursor: currentCursor,
hintText: widget.hintText, hintText: hintText,
isUseDefaultEmoji: widget.isUseDefaultEmoji, isUseDefaultEmoji: widget.isUseDefaultEmoji,
languageType: languageType, languageType: languageType,
textEditingController: textEditingController, textEditingController: textEditingController,
@ -827,4 +933,48 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
}), }),
selector: (c, model) => model.repliedMessage); selector: (c, model) => model.repliedMessage);
} }
checkHintText() async {
if (hintText!.contains('说些')) {
if ((widget.currentConversation.lastMessage?.customElem ?? null) !=
null) {
if (widget.currentConversation.lastMessage?.customElem!.extension ==
'cardData') {
Map info = jsonDecode(
widget.currentConversation.lastMessage!.customElem!.data!);
hintText = info['guide_text'];
setState(() {
});
}
} else if (widget.currentConversation.lastMessage == null) {
getConverstationLastInfo();
}
}
}
getConverstationLastInfo() async {
//
// lastMsgID null
// lastMsgID 使id
var result = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.getC2CHistoryMessageList(
userID: widget.currentConversation.userID!,
count: 1,
lastMsgID: null,
);
if (result.code == 0 && (result.data?.isNotEmpty ?? false)) {
V2TimMessage msg = result.data!.last!;
if (msg.customElem != null) {
if (msg.customElem!.extension == 'cardData') {
Map info = jsonDecode(msg.customElem!.data!);
hintText = info['guide_text'];
setState(() {});
}
}
}
}
} }

View File

@ -4,6 +4,7 @@ import 'package:circle_app/components/func_widget.dart';
import 'package:desktop_drop/desktop_drop.dart'; import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart'; import 'package:provider/single_child_widget.dart';
import 'package:scroll_to_index/scroll_to_index.dart'; import 'package:scroll_to_index/scroll_to_index.dart';
@ -315,6 +316,11 @@ class _TUIChatState extends TIMUIKitState<TIMChat> {
return widget.conversation.type == 1 ? ConvType.c2c : ConvType.group; return widget.conversation.type == 1 ? ConvType.c2c : ConvType.group;
} }
String _getTotalUnReadCount(int unreadCount) {
return unreadCount < 99 ? unreadCount.toString() : "99+";
}
@override @override
Widget tuiBuild(BuildContext context, TUIKitBuildValue value) { Widget tuiBuild(BuildContext context, TUIKitBuildValue value) {
final TUITheme theme = value.theme; final TUITheme theme = value.theme;
@ -376,7 +382,32 @@ class _TUIChatState extends TIMUIKitState<TIMChat> {
child: Scaffold( child: Scaffold(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
appBar:widget.customAppBar!, appBar:PreferredSize(
preferredSize: const Size.fromHeight(48.0),
child: Stack(
alignment: Alignment.centerLeft,
children: [
widget.customAppBar!,
chatGlobalModel.totalUnReadCount > 0 ? Positioned(left: 40.sp,bottom: 12.sp,child: Container(
// width: 22,
height: 22,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(11),
color: theme.cautionColor,
),
constraints: BoxConstraints(
maxWidth: 30,
minWidth: 22,
),
child:
Text(_getTotalUnReadCount(chatGlobalModel.totalUnReadCount),style: TextStyle(color: Colors.white,fontSize: 12.sp),),
)) : Container()
],
),
),
body: DropTarget( body: DropTarget(
onDragDone: (detail) { onDragDone: (detail) {
setState(() { setState(() {
@ -484,7 +515,7 @@ class _TUIChatState extends TIMUIKitState<TIMChat> {
scrollController: autoController, scrollController: autoController,
conversationID: _getConvID(), conversationID: _getConvID(),
conversationType: _getConvType(), conversationType: _getConvType(),
hintText: '最近心情怎么样?', hintText: '说些什么吧~',
showMorePanel: widget.config showMorePanel: widget.config
?.isAllowShowMorePanel ?? ?.isAllowShowMorePanel ??
true, true,

View File

@ -99,7 +99,7 @@ class _ChatPageState extends State<ChatPage> {
), ),
userAvatarBuilder: (BuildContext context, V2TimMessage message) { userAvatarBuilder: (BuildContext context, V2TimMessage message) {
return avatarWidget(message.faceUrl ?? 'http://qiniuyun.ikuayou.com/avatar/default/default_header.png'); return avatarWidget((message.faceUrl?.isNotEmpty ?? false) ? message.faceUrl! : 'http://qiniuyun.ikuayou.com/avatar/default/default_header.png');
}, },
); );

View File

@ -176,7 +176,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
var data = await DioManager.instance.get( var data = await DioManager.instance.get(
url: "/up-service/callout/${bean.id}/chat",); url: "/up-service/callout/${bean.id}/chat",);
if (data["code"] == 200) { if (data["code"] == 200) {
pushChatPage(data['data']['account_id'],data['data']['account_id'], bean.user!.nickname!); pushChatPage(data['data']['account_id'].toString().split("_").last,data['data']['account_id'], bean.user!.nickname!);
} }
} }

View File

@ -69,7 +69,7 @@ createCustomMsg(String userId,String imId) async {
if (data['data']['both_cities'] != null) { if (data['data']['both_cities'] != null) {
List city = data['data']['both_cities']; List city = data['data']['both_cities'];
if (city.isNotEmpty) { if (city.isNotEmpty) {
desc = '· 你们都在$city留下过足迹'; desc = '你们都在$city留下过足迹';
} }
} }
if (data['data']['both_interests'] != null) { if (data['data']['both_interests'] != null) {
@ -79,9 +79,9 @@ createCustomMsg(String userId,String imId) async {
circleList.add(element['title']); circleList.add(element['title']);
}); });
if (circleList.isNotEmpty) { if (circleList.isNotEmpty) {
info['both_interests'] = '· 你们有${circleList.length}个共同的圈子:${circleList.join('')}'; info['both_interests'] = '你们有${circleList.length}个共同的圈子:${circleList.join('')}';
if (desc.isEmpty) { if (desc.isEmpty) {
desc = '· 你们有${circleList.length}个共同的圈子:${circleList.join('')}'; desc = '你们有${circleList.length}个共同的圈子:${circleList.join('')}';
} }
} }
} }
@ -91,6 +91,7 @@ createCustomMsg(String userId,String imId) async {
info['my'] = data['data']['my'] ?? ''; info['my'] = data['data']['my'] ?? '';
info['myInterests'] = data['data']['myInterests'] ?? []; info['myInterests'] = data['data']['myInterests'] ?? [];
info['user'] = data['data']['user']; info['user'] = data['data']['user'];
info['guide_text'] = data['data']['guide_text'] ?? '请问现在有空吗?';
await sendCustomMsg(imId, jsonEncode(info), desc); await sendCustomMsg(imId, jsonEncode(info), desc);
return true; return true;
} }
@ -102,13 +103,13 @@ createCustomMsg(String userId,String imId) async {
// //
sendTextMsg(String userId) async { sendTextMsg(String userId,{String content = '看看这次缘分匹配到哪位小可爱呢?'}) async {
// //
V2TimValueCallback<V2TimMsgCreateInfoResult> createTextMessageRes = V2TimValueCallback<V2TimMsgCreateInfoResult> createTextMessageRes =
await TencentImSDKPlugin.v2TIMManager await TencentImSDKPlugin.v2TIMManager
.getMessageManager() .getMessageManager()
.createTextMessage( .createTextMessage(
text: '看看这次缘分匹配到哪位小可爱呢?', // text: content, //
); );
if (createTextMessageRes.code == 0) { if (createTextMessageRes.code == 0) {
// //
@ -123,7 +124,9 @@ sendTextMsg(String userId) async {
.sendMessage(id: id!, receiver: userId, groupID: ''); .sendMessage(id: id!, receiver: userId, groupID: '');
if (sendMessageRes.code == 0) { if (sendMessageRes.code == 0) {
// //
return true;
} }
return false;
} }
// V2TimValueCallback<V2TimMsgCreateInfoResult> createCustomMessageRes = // V2TimValueCallback<V2TimMsgCreateInfoResult> createCustomMessageRes =
// await TencentImSDKPlugin.v2TIMManager // await TencentImSDKPlugin.v2TIMManager