文件提交
This commit is contained in:
parent
4d33af7c0a
commit
20c824b84b
@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:circle_app/app/splash/binding.dart';
|
import 'package:circle_app/app/splash/binding.dart';
|
||||||
|
import 'package:circle_app/network/api.dart';
|
||||||
|
import 'package:circle_app/network/dio_manager.dart';
|
||||||
import 'package:circle_app/router/app_pages.dart';
|
import 'package:circle_app/router/app_pages.dart';
|
||||||
import 'package:circle_app/router/app_routers.dart';
|
import 'package:circle_app/router/app_routers.dart';
|
||||||
import 'package:circle_app/util/PaymentUtils.dart';
|
import 'package:circle_app/util/PaymentUtils.dart';
|
||||||
@ -10,13 +12,14 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:tencent_cloud_chat_uikit/business_logic/separate_models/tui_chat_separate_view_model.dart';
|
||||||
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
|
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
|
||||||
|
|
||||||
import 'app/splash/view.dart';
|
import 'app/splash/view.dart';
|
||||||
|
|
||||||
|
|
||||||
final CoreServicesImpl coreInstance = TIMUIKitCore.getInstance();
|
final CoreServicesImpl coreInstance = TIMUIKitCore.getInstance();
|
||||||
|
final TUIChatSeparateViewModel chatSeparateViewModel = TUIChatSeparateViewModel();
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
@ -36,7 +39,10 @@ logoutIM() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//跳转发消息页面
|
//跳转发消息页面
|
||||||
pushChatPage(String imId,String userName) {
|
pushChatPage(String userId,String imId,String userName) async {
|
||||||
|
await createCustomMsg(userId,imId);
|
||||||
|
|
||||||
|
|
||||||
var con = V2TimConversation(
|
var con = V2TimConversation(
|
||||||
conversationID: "c2c_$imId",
|
conversationID: "c2c_$imId",
|
||||||
userID: imId,
|
userID: imId,
|
||||||
@ -45,6 +51,133 @@ pushChatPage(String imId,String userName) {
|
|||||||
Get.toNamed(AppRoutes.Chat,arguments: con);
|
Get.toNamed(AppRoutes.Chat,arguments: con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createCustomMsg(String userId,String imId) async {
|
||||||
|
//通过会话ID获取指定会话列表
|
||||||
|
V2TimValueCallback<List<V2TimConversation>>
|
||||||
|
getConversationListByConversaionIdsRes = await TencentImSDKPlugin
|
||||||
|
.v2TIMManager
|
||||||
|
.getConversationManager()
|
||||||
|
.getConversationListByConversaionIds(conversationIDList: ["c2c_$imId"]);//需要获取会话列表数据的会话id列表
|
||||||
|
if (getConversationListByConversaionIdsRes.code == 0 && getConversationListByConversaionIdsRes.data!.isEmpty) {
|
||||||
|
//获取资料,然后发送自定义卡片消息
|
||||||
|
var data = await DioManager.instance
|
||||||
|
.get(url: 'msg-service/user/$userId/chat/card', );
|
||||||
|
if (data['code'] == 200) {
|
||||||
|
String desc = '';
|
||||||
|
Map<String, dynamic> info = {};
|
||||||
|
if (data['data']['both_cities'] != null) {
|
||||||
|
List city = data['data']['both_cities'];
|
||||||
|
if (city.isNotEmpty) {
|
||||||
|
desc = '· 你们都在$city留下过足迹';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data['data']['both_interests'] != null) {
|
||||||
|
List<dynamic> both_interests = data['data']['both_interests'];
|
||||||
|
List<String> circleList = [];
|
||||||
|
both_interests.forEach((element) {
|
||||||
|
circleList.add(element['title']);
|
||||||
|
});
|
||||||
|
if (circleList.isNotEmpty) {
|
||||||
|
info['both_interests'] = '· 你们有${circleList.length}个共同的圈子:${circleList.join('、')}';
|
||||||
|
if (desc.isEmpty) {
|
||||||
|
desc = '· 你们有${circleList.length}个共同的圈子:${circleList.join('、')}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (desc.isNotEmpty) {
|
||||||
|
info['interests'] = data['data']['interests'] ?? [];
|
||||||
|
info['guide_text'] = data['data']['guide_text'] ?? '';
|
||||||
|
info['my'] = data['data']['my'] ?? '';
|
||||||
|
info['myInterests'] = data['data']['myInterests'] ?? [];
|
||||||
|
info['user'] = data['data']['user'];
|
||||||
|
await sendCustomMsg(imId, jsonEncode(info), desc);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//发送文本消息
|
||||||
|
sendTextMsg(String userId) async {
|
||||||
|
// 创建文本消息
|
||||||
|
V2TimValueCallback<V2TimMsgCreateInfoResult> createTextMessageRes =
|
||||||
|
await TencentImSDKPlugin.v2TIMManager
|
||||||
|
.getMessageManager()
|
||||||
|
.createTextMessage(
|
||||||
|
text: '看看这次缘分匹配到哪位小可爱呢?', // 文本信息
|
||||||
|
);
|
||||||
|
if (createTextMessageRes.code == 0) {
|
||||||
|
// 文本信息创建成功
|
||||||
|
String? id = createTextMessageRes.data?.id;
|
||||||
|
// 发送文本消息
|
||||||
|
// 在sendMessage时,若只填写receiver则发个人用户单聊消息
|
||||||
|
// 若只填写groupID则发群组消息
|
||||||
|
// 若填写了receiver与groupID则发群内的个人用户,消息在群聊中显示,只有指定receiver能看见
|
||||||
|
V2TimValueCallback<V2TimMessage> sendMessageRes = await TencentImSDKPlugin
|
||||||
|
.v2TIMManager
|
||||||
|
.getMessageManager()
|
||||||
|
.sendMessage(id: id!, receiver: userId, groupID: '');
|
||||||
|
if (sendMessageRes.code == 0) {
|
||||||
|
// 发送成功
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// V2TimValueCallback<V2TimMsgCreateInfoResult> createCustomMessageRes =
|
||||||
|
// await TencentImSDKPlugin.v2TIMManager
|
||||||
|
// .getMessageManager()
|
||||||
|
// .createTextAtMessage(text: '看看这次缘分匹配到哪位小可爱呢?',atUserList: [],
|
||||||
|
// );
|
||||||
|
// if (createCustomMessageRes.code == 0) {
|
||||||
|
// String? id = createCustomMessageRes.data?.id;
|
||||||
|
// // 发送自定义消息
|
||||||
|
// // 在sendMessage时,若只填写receiver则发个人用户单聊消息
|
||||||
|
// // 若只填写groupID则发群组消息
|
||||||
|
// // 若填写了receiver与groupID则发群内的个人用户,消息在群聊中显示,只有指定receiver能看见
|
||||||
|
// V2TimValueCallback<V2TimMessage> sendMessageRes = await TencentImSDKPlugin
|
||||||
|
// .v2TIMManager
|
||||||
|
// .getMessageManager()
|
||||||
|
// .sendMessage(id: id!, receiver: userId,groupID: '');
|
||||||
|
// if (sendMessageRes.code == 0) {
|
||||||
|
// // 发送成功
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//发送自定义消息
|
||||||
|
sendCustomMsg(String userId,String data, String desc) async {
|
||||||
|
// 创建自定义消息
|
||||||
|
V2TimValueCallback<V2TimMsgCreateInfoResult> createCustomMessageRes =
|
||||||
|
await TencentImSDKPlugin.v2TIMManager
|
||||||
|
.getMessageManager()
|
||||||
|
.createCustomMessage(
|
||||||
|
data: data,
|
||||||
|
desc: desc,
|
||||||
|
extension: 'cardData',
|
||||||
|
);
|
||||||
|
if (createCustomMessageRes.code == 0) {
|
||||||
|
String? id = createCustomMessageRes.data?.id;
|
||||||
|
// 发送自定义消息
|
||||||
|
// 在sendMessage时,若只填写receiver则发个人用户单聊消息
|
||||||
|
// 若只填写groupID则发群组消息
|
||||||
|
// 若填写了receiver与groupID则发群内的个人用户,消息在群聊中显示,只有指定receiver能看见
|
||||||
|
V2TimValueCallback<V2TimMessage> sendMessageRes = await TencentImSDKPlugin
|
||||||
|
.v2TIMManager
|
||||||
|
.getMessageManager()
|
||||||
|
.sendMessage(id: id!, receiver: userId,groupID: '');
|
||||||
|
if (sendMessageRes.code == 0) {
|
||||||
|
// 发送成功
|
||||||
|
sendMessageRes.data?.customElem?.data; //自定义data
|
||||||
|
sendMessageRes.data?.customElem?.desc; //自定义desc
|
||||||
|
sendMessageRes.data?.customElem?.extension; //自定义extension
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user