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

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(
children: [
Container(
height: info.containsKey('city') ? 175.sp : 135.sp,
// height: info.containsKey('city') ? 175.sp : 135.sp,
width: Get.width,
margin: EdgeInsets.only(left: isFromSelf ? 16 : 0, right: isFromSelf ? 0 : 16),
decoration: BoxDecoration(
@ -414,6 +414,10 @@ class _TIMUIKItHistoryMessageListItemState
image: AssetImage(
getCircleImage('pic_bg'),
))),
constraints: BoxConstraints(
maxHeight: 175.sp,
minHeight: 135.sp
),
child: Column(
children: [
Container(
@ -446,10 +450,12 @@ class _TIMUIKItHistoryMessageListItemState
),
if (info.containsKey('both_interests'))
Container(
margin: EdgeInsets.only(top: 16.sp),
margin: EdgeInsets.only(top: 16.sp,right: 16.sp),
child: Row(
children: [
Container(
margin: EdgeInsets.only(right: 5.sp),
width: 3,
height: 3,
@ -457,12 +463,17 @@ class _TIMUIKItHistoryMessageListItemState
borderRadius: BorderRadius.circular(1.5),
color: Color(0xFF00FFF4)),
),
Text(
Container(
width:Get.width - 80.sp,
child: Text(
info['both_interests'],
style: TextStyle(
color: Colors.white,
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:convert';
import 'dart:math';
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:diff_match_patch/diff_match_patch.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 }
GlobalKey<_InputTextFieldState> myInputTextFieldState = GlobalKey();
class TIMInputTextField extends StatefulWidget {
@ -45,7 +46,7 @@ class TIMInputTextField extends StatefulWidget {
final AutoScrollController? atMemberPanelScroll;
/// hint text for textField widget
final String? hintText;
String? hintText;
/// config for more pannel
final MorePanelConfig? morePanelConfig;
@ -83,12 +84,12 @@ class TIMInputTextField extends StatefulWidget {
final String? groupType;
const TIMInputTextField(
TIMInputTextField(
{Key? key,
required this.conversationID,
required this.conversationType,
this.initText,
this.hintText,
required this.hintText,
this.scrollController,
this.morePanelConfig,
this.customStickerPanel,
@ -122,6 +123,8 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
bool isAddingAtSearchWords = false;
double inputWidth = 900;
String hintText = '说些什么吧~';
Map<String, V2TimGroupMemberFullInfo> memberInfoMap = {};
late TextEditingController textEditingController;
@ -257,6 +260,45 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
lastText = "";
final text = textEditingController.text.trim();
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 (widget.model.repliedMessage != null) {
MessageUtils.handleMessageError(
@ -290,6 +332,27 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
}
}
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() {
if (globalModel.getMessageListPosition(widget.conversationID) ==
HistoryMessagePosition.notShowLatest) {
@ -547,6 +610,7 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
@override
void initState() {
super.initState();
checkHintText();
if (PlatformUtils().isWeb || PlatformUtils().isDesktop) {
focusNode = FocusNode(
onKey: (node, event) {
@ -752,6 +816,7 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
inputWidth = constraints.maxWidth;
return TUIKitScreenUtils.getDeviceWidget(
defaultWidget: TIMTextFieldLayoutNarrow(
onEmojiSubmitted: onEmojiSubmitted,
@ -760,13 +825,54 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
addStickerToText: addStickerToText,
customStickerPanel: widget.customStickerPanel,
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,
morePanelConfig: widget.morePanelConfig,
repliedMessage: value,
currentCursor: currentCursor,
hintText: widget.hintText,
hintText: hintText,
isUseDefaultEmoji: widget.isUseDefaultEmoji,
languageType: languageType,
textEditingController: textEditingController,
@ -801,7 +907,7 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
morePanelConfig: widget.morePanelConfig,
repliedMessage: value,
currentCursor: currentCursor,
hintText: widget.hintText,
hintText: hintText,
isUseDefaultEmoji: widget.isUseDefaultEmoji,
languageType: languageType,
textEditingController: textEditingController,
@ -827,4 +933,48 @@ class _InputTextFieldState extends TIMUIKitState<TIMInputTextField> {
}),
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:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.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;
}
String _getTotalUnReadCount(int unreadCount) {
return unreadCount < 99 ? unreadCount.toString() : "99+";
}
@override
Widget tuiBuild(BuildContext context, TUIKitBuildValue value) {
final TUITheme theme = value.theme;
@ -376,7 +382,32 @@ class _TUIChatState extends TIMUIKitState<TIMChat> {
child: Scaffold(
backgroundColor: Colors.transparent,
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(
onDragDone: (detail) {
setState(() {
@ -484,7 +515,7 @@ class _TUIChatState extends TIMUIKitState<TIMChat> {
scrollController: autoController,
conversationID: _getConvID(),
conversationType: _getConvType(),
hintText: '最近心情怎么样?',
hintText: '说些什么吧~',
showMorePanel: widget.config
?.isAllowShowMorePanel ??
true,

View File

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