增加描述 - 宽展代码可读性

This commit is contained in:
Jin857 2025-01-11 14:39:57 +08:00
parent c88aa27015
commit 65d34fef4d
9 changed files with 171 additions and 125 deletions

View File

@ -11,6 +11,16 @@
import 'package:wukongimfluttersdk/wkim.dart'; import 'package:wukongimfluttersdk/wkim.dart';
``` ```
**安装方式**
需要手动下载该项目到本地,注意:与你的开发项目在同一目录下
1. 打开pubspec
项目目录下找到 pubspec.yaml
2. 在 dependencies 中添加
```yaml
wukongimfluttersdk:
path: ../wkim/
```
**初始化sdk** **初始化sdk**
```dart ```dart
WKIM.shared.setup(Options.newDefault('uid', 'token')); WKIM.shared.setup(Options.newDefault('uid', 'token'));
@ -27,6 +37,7 @@ WKIM.shared.options.getAddr = (Function(String address) complete) async {
```dart ```dart
WKIM.shared.connectionManager.connect(); WKIM.shared.connectionManager.connect();
``` ```
**断开** **断开**
```dart ```dart
// isLogout true退出并不再重连 false退出保持重连 // isLogout true退出并不再重连 false退出保持重连
@ -57,18 +68,21 @@ WKIM.shared.connectionManager.addOnConnectionStatus('home',
} }
}); });
``` ```
**消息入库** **消息入库**
```dart ```dart
WKIM.shared.messageManager.addOnMsgInsertedListener((wkMsg) { WKIM.shared.messageManager.addOnMsgInsertedListener((wkMsg) {
// todo 展示在UI上 // todo 展示在UI上
}); });
``` ```
**收到新消息** **收到新消息**
```dart ```dart
WKIM.shared.messageManager.addOnNewMsgListener('chat', (msgs) { WKIM.shared.messageManager.addOnNewMsgListener('chat', (msgs) {
// todo 展示在UI上 // todo 展示在UI上
}); });
``` ```
**刷新某条消息** **刷新某条消息**
```dart ```dart
WKIM.shared.messageManager.addOnRefreshMsgListener('chat', (wkMsg) { WKIM.shared.messageManager.addOnRefreshMsgListener('chat', (wkMsg) {
@ -82,6 +96,7 @@ WKIM.shared.cmdManager.addOnCmdListener('chat', (cmdMsg) {
// todo 按需处理cmd消息 // todo 按需处理cmd消息
}); });
``` ```
- 包含`key`的事件监听均有移除监听的方法,为了避免重复收到事件回掉,在退出或销毁页面时通过传入的`key`移除事件 - 包含`key`的事件监听均有移除监听的方法,为了避免重复收到事件回掉,在退出或销毁页面时通过传入的`key`移除事件
**发送消息时间** **发送消息时间**
@ -100,8 +115,8 @@ ntp7.aliyun.com
**Socket链接逻辑** **Socket链接逻辑**
将socket链接分成两部分: (链接成功之前,链接成功之后)这里是根据是否有返回消息/结合onDone来判断 将socket链接分成两部分: (链接成功之前,链接成功之后)这里是根据是否有返回消息/结合onDone来判断
1.链接成功之前:(链接中) 1.链接成功之前:(链接中)
当前没有任何处理,链接不成功的话不回重复链接。 链接不成功 时 每隔5秒重新链接。即没有返回消息并且onDone触发时会触发 5秒 后断线重连
需求是 链接不成功 时 每隔1.5秒重新链接 当 WKIM.shared.connectionManager.disconnect 时会清理掉计时器
2.链接成功之后 2.链接成功之后
接首到消息返回,开启心跳检测/网络异常监听 接首到消息返回,开启心跳检测/网络异常监听

View File

@ -1,49 +1,70 @@
import '../type/const.dart'; import '../type/const.dart';
///
class WKChannel { class WKChannel {
String channelID = ""; String channelID = "";
int channelType = WKChannelType.personal; int channelType = WKChannelType.personal;
String channelName = ""; String channelName = "";
//()
/// ()
String channelRemark = ""; String channelRemark = "";
int showNick = 0; int showNick = 0;
//
///
int top = 0; int top = 0;
//
///
int save = 0; int save = 0;
//
///
int mute = 0; int mute = 0;
//
///
int forbidden = 0; int forbidden = 0;
//
///
int invite = 0; int invite = 0;
//[12]
/// [12]
int status = 1; int status = 1;
// 0. 1.
/// 0. 1.
int follow = 0; int follow = 0;
//
///
int isDeleted = 0; int isDeleted = 0;
//
///
String createdAt = ""; String createdAt = "";
//
///
String updatedAt = ""; String updatedAt = "";
//
///
String avatar = ""; String avatar = "";
//
///
int version = 0; int version = 0;
//
///
dynamic localExtra; dynamic localExtra;
//线
/// 线
int online = 0; int online = 0;
//线
/// 线
int lastOffline = 0; int lastOffline = 0;
// 线
/// 线
int deviceFlag = 0; int deviceFlag = 0;
//
///
int receipt = 0; int receipt = 0;
//
///
int robot = 0; int robot = 0;
//[service:]
/// [service:]
String category = ""; String category = "";
String username = ""; String username = "";
String avatarCacheKey = ""; String avatarCacheKey = "";
@ -53,8 +74,10 @@ class WKChannel {
WKChannel(this.channelID, this.channelType); WKChannel(this.channelID, this.channelType);
} }
///
class WKChannelSearchResult { class WKChannelSearchResult {
WKChannel? channel; WKChannel? channel;
//
///
String containMemberName = ''; String containMemberName = '';
} }

View File

@ -1,36 +1,53 @@
///
class WKChannelMember { class WKChannelMember {
String channelID = ""; String channelID = "";
//
///
int channelType = 0; int channelType = 0;
//id
/// id
String memberUID = ""; String memberUID = "";
//
///
String memberName = ""; String memberName = "";
//
///
String memberRemark = ""; String memberRemark = "";
//
///
String memberAvatar = ""; String memberAvatar = "";
//
///
int role = 0; int role = 0;
//12
/// 12
int status = 0; int status = 0;
//
///
int isDeleted = 0; int isDeleted = 0;
//
///
String createdAt = ""; String createdAt = "";
//
///
String updatedAt = ""; String updatedAt = "";
//
///
int version = 0; int version = 0;
// 01
/// 01
int robot = 0; int robot = 0;
//
///
dynamic extraMap; dynamic extraMap;
//
///
String remark = ""; String remark = "";
// uid
/// uid
String memberInviteUID = ""; String memberInviteUID = "";
//
///
int forbiddenExpirationTime = 0; int forbiddenExpirationTime = 0;
String memberAvatarCacheKey = ""; String memberAvatarCacheKey = "";
} }

View File

@ -1,8 +1,10 @@
///
class WkSyncCMD { class WkSyncCMD {
String cmd = ''; String cmd = '';
dynamic param; dynamic param;
} }
///
class WKCMD { class WKCMD {
String cmd = ''; String cmd = '';
dynamic param; dynamic param;

View File

@ -6,30 +6,40 @@ import 'cmd.dart';
import 'msg.dart'; import 'msg.dart';
import 'reminder.dart'; import 'reminder.dart';
///
class WKConversationMsg { class WKConversationMsg {
//id /// id
String channelID = ''; String channelID = '';
//
///
int channelType = WKChannelType.personal; int channelType = WKChannelType.personal;
//ID
/// ID
String lastClientMsgNO = ''; String lastClientMsgNO = '';
//
///
int isDeleted = 0; int isDeleted = 0;
//
///
int version = 0; int version = 0;
//
///
int lastMsgTimestamp = 0; int lastMsgTimestamp = 0;
//
///
int unreadCount = 0; int unreadCount = 0;
//
///
int lastMsgSeq = 0; int lastMsgSeq = 0;
//
///
dynamic localExtraMap; dynamic localExtraMap;
WKConversationMsgExtra? msgExtra; WKConversationMsgExtra? msgExtra;
String parentChannelID = ''; String parentChannelID = '';
int parentChannelType = 0; int parentChannelType = 0;
} }
///
class WKConversationMsgExtra { class WKConversationMsgExtra {
String channelID = ''; String channelID = '';
int channelType = 0; int channelType = 0;
@ -41,26 +51,35 @@ class WKConversationMsgExtra {
int draftUpdatedAt = 0; int draftUpdatedAt = 0;
} }
///
class WKUIConversationMsg { class WKUIConversationMsg {
int lastMsgSeq = 0; int lastMsgSeq = 0;
String clientMsgNo = ''; String clientMsgNo = '';
//ID
/// ID
String channelID = ''; String channelID = '';
//
///
int channelType = 0; int channelType = 0;
//
///
int lastMsgTimestamp = 0; int lastMsgTimestamp = 0;
//
///
WKChannel? _wkChannel; WKChannel? _wkChannel;
//
///
WKMsg? _wkMsg; WKMsg? _wkMsg;
//
///
int unreadCount = 0; int unreadCount = 0;
int isDeleted = 0; int isDeleted = 0;
WKConversationMsgExtra? _remoteMsgExtra; WKConversationMsgExtra? _remoteMsgExtra;
//[{type:1,text:'[有人@你]'}]
/// [{type:1,text:'[有人@你]'}]
List<WKReminder>? _reminderList; List<WKReminder>? _reminderList;
//
///
dynamic localExtraMap; dynamic localExtraMap;
String parentChannelID = ''; String parentChannelID = '';
int parentChannelType = 0; int parentChannelType = 0;
@ -103,6 +122,7 @@ class WKUIConversationMsg {
} }
} }
///
class WKSyncConversation { class WKSyncConversation {
int cmdVersion = 0; int cmdVersion = 0;
List<WkSyncCMD>? cmds; List<WkSyncCMD>? cmds;
@ -110,6 +130,7 @@ class WKSyncConversation {
List<WKSyncConvMsg>? conversations; List<WKSyncConvMsg>? conversations;
} }
///
class WKSyncConvMsg { class WKSyncConvMsg {
String channelID = ''; String channelID = '';
int channelType = 0; int channelType = 0;

View File

@ -10,6 +10,7 @@ import '../type/const.dart';
import 'channel.dart'; import 'channel.dart';
import 'channel_member.dart'; import 'channel_member.dart';
///
class WKMsg { class WKMsg {
MessageHeader header = MessageHeader(); MessageHeader header = MessageHeader();
Setting setting = Setting(); Setting setting = Setting();

View File

@ -1,3 +1,4 @@
///
class WKReminder { class WKReminder {
int reminderID = 0; int reminderID = 0;
String messageID = ''; String messageID = '';
@ -15,6 +16,7 @@ class WKReminder {
String publisher = ''; String publisher = '';
} }
///
class WKMentionType { class WKMentionType {
//@ //@
static const int wkReminderTypeMentionMe = 1; static const int wkReminderTypeMentionMe = 1;

View File

@ -7,27 +7,11 @@ void main() {
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key}); const MyApp({super.key});
// This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Flutter Demo', title: 'Flutter Demo',
theme: ThemeData( theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a blue toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true, useMaterial3: true,
), ),
@ -38,16 +22,6 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title}); const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title; final String title;
@override @override
@ -59,50 +33,19 @@ class _MyHomePageState extends State<MyHomePage> {
void _incrementCounter() { void _incrementCounter() {
setState(() { setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++; _counter++;
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title), title: Text(widget.title),
), ),
body: Center( body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column( child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
const Text( const Text(
@ -119,7 +62,7 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _incrementCounter, onPressed: _incrementCounter,
tooltip: 'Increment', tooltip: 'Increment',
child: const Icon(Icons.add), child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods. ),
); );
} }
} }

View File

@ -18,13 +18,30 @@ import 'model/wk_card_content.dart';
class WKIM { class WKIM {
WKIM._privateConstructor(); WKIM._privateConstructor();
int deviceFlagApp = 0;
static final WKIM _instance = WKIM._privateConstructor(); static final WKIM _instance = WKIM._privateConstructor();
static WKIM get shared => _instance; static WKIM get shared => _instance;
///
int deviceFlagApp = 0;
/// 使
@Deprecated('Use Options deviceFlag')
void setDeviceFlag(int deviceFlag) {
deviceFlagApp = deviceFlag;
}
///
Model runMode = Model.app; Model runMode = Model.app;
/// - APP
bool isApp() {
return runMode == Model.app;
}
///
Options options = Options(); Options options = Options();
///
Future<bool> setup(Options opts) async { Future<bool> setup(Options opts) async {
options = opts; options = opts;
deviceFlagApp = opts.deviceFlag; deviceFlagApp = opts.deviceFlag;
@ -39,6 +56,7 @@ class WKIM {
return true; return true;
} }
///
_initNormalMsgContent() { _initNormalMsgContent() {
messageManager.registerMsgContent(WkMessageContentType.text, messageManager.registerMsgContent(WkMessageContentType.text,
(dynamic data) { (dynamic data) {
@ -62,20 +80,24 @@ class WKIM {
}); });
} }
@Deprecated('Use Options deviceFlag') ///
void setDeviceFlag(int deviceFlag) {
deviceFlagApp = deviceFlag;
}
bool isApp() {
return runMode == Model.app;
}
WKWebConnectionManager connectionManager = WKWebConnectionManager.shared; WKWebConnectionManager connectionManager = WKWebConnectionManager.shared;
///
WKMessageManager messageManager = WKMessageManager.shared; WKMessageManager messageManager = WKMessageManager.shared;
///
WKConversationManager conversationManager = WKConversationManager.shared; WKConversationManager conversationManager = WKConversationManager.shared;
///
WKChannelManager channelManager = WKChannelManager.shared; WKChannelManager channelManager = WKChannelManager.shared;
///
WKChannelMemberManager channelMemberManager = WKChannelMemberManager.shared; WKChannelMemberManager channelMemberManager = WKChannelMemberManager.shared;
///
WKReminderManager reminderManager = WKReminderManager.shared; WKReminderManager reminderManager = WKReminderManager.shared;
///
WKCMDManager cmdManager = WKCMDManager.shared; WKCMDManager cmdManager = WKCMDManager.shared;
} }