tencent_cloud_chat_sdk 7.7.5305 tencent_cloud_chat_sdk: ^7.7.5305 copied to clipboard
Tencent Cloud Chat SDK. Globally interconnected In-App Chat, user profile and relationship chains and offline push.
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:tencent_cloud_chat_sdk/enum/V2TimAdvancedMsgListener.dart';
import 'package:tencent_cloud_chat_sdk/enum/V2TimConversationListener.dart';
import 'package:tencent_cloud_chat_sdk/enum/V2TimFriendshipListener.dart';
import 'package:tencent_cloud_chat_sdk/enum/V2TimGroupListener.dart';
import 'package:tencent_cloud_chat_sdk/enum/V2TimSDKListener.dart';
import 'package:tencent_cloud_chat_sdk/enum/group_add_opt_enum.dart';
import 'package:tencent_cloud_chat_sdk/enum/log_level_enum.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_callback.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_group_info.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_value_callback.dart';
import 'package:tencent_cloud_chat_sdk/tencent_im_sdk_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
final V2TimSDKListener listener = V2TimSDKListener(
onConnectSuccess: () {
print("onConnectSuccess");
},
onConnecting: () {
print("onConnecting");
},
onConnectFailed: (code, error) {
print("onConnectFailed");
},
);
final V2TimConversationListener onConversationChanged = V2TimConversationListener(
onConversationChanged: (conversationList) {
print("onConversationChanged");
for (var element in conversationList) {
print("convID${element.conversationID},isPined ${element.isPinned} orderKey ${element.orderkey}");
}
},
onConversationDeleted: (conversationIDList) {
print("onConversationDeleted");
},
onConversationGroupCreated: (groupName, conversationList) {
print("onConversationGroupCreated");
},
onConversationGroupDeleted: (groupName) {
print("onConversationGroupDeleted");
},
onConversationGroupNameChanged: (oldName, newName) {
print("onConversationGroupNameChanged");
},
onConversationsAddedToGroup: (groupName, conversationList) {
print("onConversationsAddedToGroup");
},
onConversationsDeletedFromGroup: (groupName, conversationList) {
print("onConversationsDeletedFromGroup");
},
onNewConversation: (conversationList) {
print("onNewConversation");
},
onSyncServerFailed: () {
print("onSyncServerFailed");
},
onSyncServerFinish: () {
print("onSyncServerFinish");
},
onSyncServerStart: () {
print("onSyncServerStart");
},
onTotalUnreadMessageCountChanged: (totalUnreadCount) {
print("onTotalUnreadMessageCountChanged");
},
onUnreadMessageCountChangedByFilter: (filter, totalUnreadCount) {
print("onUnreadMessageCountChangedByFilter");
},
);
final V2TimGroupListener glistener = V2TimGroupListener(
onAllGroupMembersMuted: (groupID, isMute) {
print("onAllGroupMembersMuted");
},
onApplicationProcessed: (groupID, opUser, isAgreeJoin, opReason) {
print("onApplicationProcessed");
},
onGroupAttributeChanged: (groupID, groupAttributeMap) {
print("onGroupAttributeChanged");
},
onGrantAdministrator: (groupID, opUser, memberList) {
print("onGrantAdministrator");
},
onGroupCounterChanged: (groupID, key, newValue) {
print("onGroupCounterChanged");
},
onGroupCreated: (groupID) {
print("onGroupCreated");
},
onGroupDismissed: (groupID, opUser) {
print("onGroupDismissed");
},
onGroupInfoChanged: (groupID, changeInfos) {
print("onGroupInfoChanged");
changeInfos.forEach((element) {
print(element.toJson());
});
},
onGroupRecycled: (groupID, opUser) {
print("onGroupRecycled");
},
onMemberEnter: (onGroupRecycled, memberList) {
print("onMemberEnter");
},
onMemberInfoChanged: (groupID, v2TIMGroupMemberChangeInfoList) {
print("onMemberInvited");
},
onMemberInvited: (groupID, opUser, memberList) {
print("onMemberInvited");
},
onMemberKicked: (groupID, opUser, memberList) {
print("onMemberKicked");
},
onMemberLeave: (groupID, member) {
print("onMemberLeave");
},
onMemberMarkChanged: (groupID, memberIDList, markType, enableMark) {
print("onMemberMarkChanged");
},
onQuitFromGroup: (groupID) {
print("onQuitFromGroup");
},
onReceiveJoinApplication: (groupID, member, opReason) {
print("onReceiveJoinApplication");
},
onReceiveRESTCustomData: (groupID, customData) {
print("onReceiveRESTCustomData");
},
onRevokeAdministrator: (groupID, opUser, memberList) {
print("onRevokeAdministrator");
},
onTopicCreated: (groupID, topicID) {
print("onTopicCreated");
},
onTopicDeleted: (groupID, topicIDList) {
print("onTopicDeleted");
},
onTopicInfoChanged: (groupID, topicInfo) {
print("onTopicInfoChanged");
},
);
final V2TimFriendshipListener flistener = V2TimFriendshipListener(
onBlackListAdd: (infoList) {
print("onBlackListAdd");
},
onBlackListDeleted: (userList) {
print("onBlackListDeleted");
},
onFriendApplicationListAdded: (applicationList) {
print("onFriendApplicationListAdded");
},
onFriendApplicationListDeleted: (userIDList) {
print("onFriendApplicationListDeleted");
},
onFriendApplicationListRead: () {
print("onFriendApplicationListRead");
},
onFriendInfoChanged: (infoList) {
print("onFriendInfoChanged");
},
onFriendListAdded: (users) {
print("onFriendListAdded");
},
onFriendListDeleted: (userList) {
print("onFriendListDeleted");
},
);
final V2TimAdvancedMsgListener messageLiener = V2TimAdvancedMsgListener(
onMessageDownloadProgressCallback: (messageProgress) {
print("onMessageDownloadProgressCallback");
},
onRecvC2CReadReceipt: (receiptList) {
print("onRecvC2CReadReceipt");
},
onRecvMessageExtensionsChanged: (msgID, extensions) {
print("onRecvMessageExtensionsChanged");
},
onRecvMessageExtensionsDeleted: (msgID, extensionKeys) {
print("onRecvMessageExtensionsDeleted");
},
onRecvMessageModified: (msg) {
print("onRecvMessageModified");
},
onRecvMessageReactionsChanged: (changeInfos) {
print("onRecvMessageReactionsChanged");
},
onRecvMessageReadReceipts: (receiptList) {
print("onRecvMessageReadReceipts");
},
onRecvMessageRevoked: (msgID) {
print("onRecvMessageRevoked");
},
onRecvMessageRevokedWithInfo: (msgID, operateUser, reason) {
print("onRecvMessageRevokedWithInfo");
},
onRecvNewMessage: (msg) {
print("onRecvNewMessage");
},
onSendMessageProgress: (message, progress) {
print("onSendMessageProgress");
},
);
final sdkAppID = 1400187352;
final userID = "109442";
final userSig = "eJw1zEELgkAQBeD-sldDZrZddIVOEWTYIdK9BzvKJIbsSmTRf8*0ju97j-cSZXGO7*RFJmQMYjVndnQbuOaZEYxS8tcE1176np3IUAFgmqy1XBp69Oxpcq21BIBFB*6*loDRSuN-G7iZjg-Sj22o2BdRTobzU2n2kb0*0VSGxs4R2jrF3WC3x414fwDCtjBE";
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = 'Unknown platform version';
// await TencentImSDKPlugin.v2TIMManager.getConversationManager().addConversationListener(listener: onConversationChanged);
await TencentImSDKPlugin.v2TIMManager.addGroupListener(listener: glistener);
// await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().addFriendListener(listener: flistener);
await TencentImSDKPlugin.v2TIMManager.getMessageManager().addAdvancedMsgListener(listener: messageLiener);
await TencentImSDKPlugin.v2TIMManager.getMessageManager().addAdvancedMsgListener(listener: messageLiener);
V2TimValueCallback<bool> initres = await TencentImSDKPlugin.v2TIMManager.initSDK(sdkAppID: sdkAppID, loglevel: LogLevelEnum.V2TIM_LOG_NONE, listener: listener);
V2TimCallback loginRes = await TencentImSDKPlugin.v2TIMManager.login(userID: userID, userSig: userSig);
print(initres.toJson());
print(loginRes.toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getServerTime()).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getVersion()).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getLoginStatus()).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.logout()).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getLoginStatus()).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.login(userID: userID, userSig: userSig)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getLoginStatus()).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getUsersInfo(userIDList: ["109442", "121405"])).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getGroupManager().createGroup(groupType: "Public", groupName: "windows",notification: "heheh",introduction: "haha",memberList: List.from([
// V2TimGroupMember(userID: "121405", role: GroupMemberRoleTypeEnum.V2TIM_GROUP_MEMBER_ROLE_MEMBER,),
// ]))).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.setSelfInfo(userFullInfo: V2TimUserFullInfo.fromJson({
// "nickName":"windows change 212",
// // "faceUrl":"http://",
// "customInfo":Map.from({
// "level":"12312"
// })
// }))).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getUsersInfo(userIDList: ["109442", "121405"])).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getConversationManager().getConversationList(nextSeq: "0",count: 10)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getConversationManager().getConversation(conversationID: "c2c_121405")).data?.conversationID);
// print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().getFriendList()).data?.length);
// var data = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createTextMessage(text: "hehehe");
// print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: data.data?.id ?? "", receiver: "121405", groupID: "")).data?.msgID);
// print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().getHistoryMessageList(count: 10,userID: "974118856",getType: HistoryMsgGetTypeEnum.V2TIM_GET_CLOUD_OLDER_MSG,)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().downloadMessage(msgID: "144115381610424665-1708506739-2726675341", messageType: 4, imageType: 0, isSnapshot: false)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().getMessageOnlineUrl(msgID: "144115381610424665-1708506739-2726675341")).toJson());
// print("好友数");
//print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().getFriendList()).data?.length);
// print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().checkFriend(userIDList: ["121405"], checkType: FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH,)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().addToBlackList(userIDList: ["957085528"],)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().getBlackList()).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().deleteFromBlackList(userIDList: ["957085528"])).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().getBlackList()).toJson());
//print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessageReadReceipts(messageIDList: ["144115381610424665-1709725297-1796807869"])).toJson());
//print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().getMessageReadReceipts(messageIDList: ["144115235149692122-1709725653-972184985"])).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().getGroupMessageReadMemberList(messageID: "144115235149692122-1709725653-972184985",filter: GetGroupMessageReadMemberListFilter.V2TIM_GROUP_MESSAGE_READ_MEMBERS_FILTER_READ,)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().getFriendApplicationList()).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().translateText(texts: ["1KB,单次最大支持设置"], targetLanguage: "en")).toJson());
print((await TencentImSDKPlugin.v2TIMManager.getGroupManager().setGroupInfo(info:V2TimGroupInfo.fromJson({
"groupID":"@TGS#2SDSF65NI",
"groupType":"Public",
"groupAddOpt": GroupAddOptTypeEnum.V2TIM_GROUP_ADD_FORBID.index,
}))).toJson());
print((await TencentImSDKPlugin.v2TIMManager.getGroupManager().getGroupsInfo(groupIDList: ["@TGS#2SDSF65NI"])).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getGroupManager().createGroup(
// groupName: "测试windowscreate",
// memberList: [
// V2TimGroupMember(userID: "121405", role:GroupMemberRoleTypeEnum.V2TIM_GROUP_MEMBER_ROLE_MEMBER, )
// ],
// groupType: "Public",
// notification: "12312",
// )).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getGroupManager().getGroupMemberList(groupID: "@TGS#2G7B5Y5NP", filter: GroupMemberFilterTypeEnum.V2TIM_GROUP_MEMBER_FILTER_ALL, nextSeq: "0")).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getMessageManager().getHistoryMessageListV2(count: 1,groupID: "@TGS#2SDSF65NI",getType: HistoryMsgGetTypeEnum.V2TIM_GET_CLOUD_OLDER_MSG,)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getConversationManager().pinConversation(conversationID: "group_@TGS#2SDSF65NI",isPinned: true)).toJson());
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running onoooo: $_platformVersion\n'),
),
),
);
}
}