tencent_cloud_chat_sdk 7.0.8-preview tencent_cloud_chat_sdk: ^7.0.8-preview 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/friend_type_enum.dart';
import 'package:tencent_cloud_chat_sdk/enum/group_member_filter_enum.dart';
import 'package:tencent_cloud_chat_sdk/enum/group_member_role_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_member.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_user_full_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");
},
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");
},
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 = 0;
final userID = "";
final userSig = "";
// 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);
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: ["121405"],)).toJson());
// print((await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().getBlackList()).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());
} 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'),
),
),
);
}
}