mirror of
https://github.com/WuKongIM/WuKongIMFlutterSDK
synced 2025-05-24 11:22:20 +00:00
fix: 修改频道和频道成员及提醒项扩展字段保存错误问题
This commit is contained in:
parent
66fb59ac67
commit
95f07c5add
@ -127,4 +127,6 @@
|
||||
### 1.6.3
|
||||
* fix: 优化在未收到服务端心跳消息时主动断开重连
|
||||
### 1.6.4
|
||||
* fix: 新增监听头像改变事件
|
||||
* fix: 新增监听头像改变事件###
|
||||
### 1.6.5
|
||||
* fix: 修改频道和频道成员及提醒项扩展字段保存错误问题
|
@ -1,3 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
@ -21,7 +22,8 @@ class HttpUtils {
|
||||
if (_dio == null) {
|
||||
final httpClient = HttpClient();
|
||||
httpClient.badCertificateCallback =
|
||||
(X509Certificate cert, String host, int port) => true; // Trust all certificates
|
||||
(X509Certificate cert, String host, int port) =>
|
||||
true; // Trust all certificates
|
||||
|
||||
_dio = Dio(BaseOptions(
|
||||
baseUrl: apiURL,
|
||||
@ -73,8 +75,8 @@ class HttpUtils {
|
||||
return '';
|
||||
}
|
||||
|
||||
static Future<void> syncConversation(String lastSsgSeqs, int msgCount, int version,
|
||||
Function(WKSyncConversation) back) async {
|
||||
static Future<void> syncConversation(String lastSsgSeqs, int msgCount,
|
||||
int version, Function(WKSyncConversation) back) async {
|
||||
try {
|
||||
// 检查是否已登录
|
||||
if (UserInfo.uid.isEmpty) {
|
||||
@ -272,6 +274,9 @@ class HttpUtils {
|
||||
var channel = WKChannel(uid, WKChannelType.personal);
|
||||
channel.channelName = json['name'];
|
||||
channel.avatar = json['avatar'];
|
||||
// 测试扩展数据
|
||||
// channel.remoteExtraMap = jsonEncode({"name": "xx", "sex": 1});
|
||||
// channel.localExtra = jsonEncode({"name1": "xx", "sex1": 1, "t": "2"});
|
||||
WKIM.shared.channelManager.addOrUpdateChannel(channel);
|
||||
} else {
|
||||
print('获取用户信息失败: HTTP ${response.statusCode}');
|
||||
@ -285,8 +290,8 @@ class HttpUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<bool> revokeMsg(String clientMsgNo, String channelId, int channelType,
|
||||
int msgSeq, String msgId) async {
|
||||
static Future<bool> revokeMsg(String clientMsgNo, String channelId,
|
||||
int channelType, int msgSeq, String msgId) async {
|
||||
try {
|
||||
// 检查必要参数
|
||||
if (clientMsgNo.isEmpty || channelId.isEmpty || msgId.isEmpty) {
|
||||
@ -325,8 +330,8 @@ class HttpUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<bool> deleteMsg(String clientMsgNo, String channelId, int channelType,
|
||||
int msgSeq, String msgId) async {
|
||||
static Future<bool> deleteMsg(String clientMsgNo, String channelId,
|
||||
int channelType, int msgSeq, String msgId) async {
|
||||
try {
|
||||
// 检查必要参数
|
||||
if (clientMsgNo.isEmpty || channelId.isEmpty || msgId.isEmpty) {
|
||||
@ -365,7 +370,8 @@ class HttpUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> syncMsgExtra(String channelId, int channelType, int version) async {
|
||||
static Future<void> syncMsgExtra(
|
||||
String channelId, int channelType, int version) async {
|
||||
try {
|
||||
final response = await dio.post('/message/extra/sync', data: {
|
||||
'login_uid': UserInfo.uid,
|
||||
|
@ -51,6 +51,8 @@ class ChatListDataState extends State<ChatList> {
|
||||
.then((channel) {
|
||||
WKIM.shared.channelManager.fetchChannelInfo(channelID, channelType);
|
||||
title = '${channel?.channelName}';
|
||||
print("扩展:${channel?.localExtra}");
|
||||
print("扩展1:${channel?.remoteExtraMap}");
|
||||
});
|
||||
}
|
||||
List<UIMsg> msgList = [];
|
||||
@ -506,7 +508,7 @@ Widget _buildItem(UIMsg uiMsg, BuildContext context) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChatPage(),
|
||||
builder: (context) => const ChatPage(),
|
||||
settings: RouteSettings(
|
||||
arguments: ChatChannel(
|
||||
uiMsg.wkMsg.channelID,
|
||||
|
@ -1,6 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:example/const.dart';
|
||||
import 'package:example/http.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wukongimfluttersdk/db/const.dart';
|
||||
import 'package:wukongimfluttersdk/entity/conversation.dart';
|
||||
import 'package:wukongimfluttersdk/entity/reminder.dart';
|
||||
import 'package:wukongimfluttersdk/type/const.dart';
|
||||
@ -140,7 +143,8 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
|
||||
/// 对会话列表按时间戳排序,最新的会话排在前面
|
||||
void _sortMessagesByTimestamp() {
|
||||
msgList.sort((a, b) => b.msg.lastMsgTimestamp.compareTo(a.msg.lastMsgTimestamp));
|
||||
msgList.sort(
|
||||
(a, b) => b.msg.lastMsgTimestamp.compareTo(a.msg.lastMsgTimestamp));
|
||||
}
|
||||
|
||||
void _getDataList() {
|
||||
@ -183,8 +187,16 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
if (uiConversation.reminders![i].type ==
|
||||
WKMentionType.wkReminderTypeMentionMe &&
|
||||
uiConversation.reminders![i].done == 0) {
|
||||
content = uiConversation.reminders![i].data;
|
||||
content = '[有人@你]';
|
||||
var d = uiConversation.reminders![i].data;
|
||||
if (d is Map) {
|
||||
content = d['type'];
|
||||
} else if (d is String && WKDBConst.isJsonString(d)) {
|
||||
var obj = jsonDecode(d);
|
||||
content = obj['type'];
|
||||
} else {
|
||||
content = d;
|
||||
}
|
||||
// content = uiConversation.reminders![i].data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -441,13 +453,16 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
WKReminder reminder = WKReminder();
|
||||
reminder.needUpload = 0;
|
||||
reminder.type = WKMentionType.wkReminderTypeMentionMe;
|
||||
reminder.data = '[有人@你]';
|
||||
// reminder.data = '[有人@你]';
|
||||
reminder.done = 0;
|
||||
reminder.reminderID = 11;
|
||||
reminder.version = 1;
|
||||
reminder.publisher = "uid_1";
|
||||
reminder.channelID = uiMsg.msg.channelID;
|
||||
reminder.channelType = uiMsg.msg.channelType;
|
||||
// 这两种都可以
|
||||
reminder.data = "[有人@你]";
|
||||
// reminder.data = jsonEncode({"type": "[有人@你]"});
|
||||
list.add(reminder);
|
||||
WKIM.shared.reminderManager.saveOrUpdateReminders(list);
|
||||
}));
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:wukongimfluttersdk/db/const.dart';
|
||||
@ -216,12 +215,8 @@ class ChannelDB {
|
||||
data['device_flag'] = channel.deviceFlag;
|
||||
data['parent_channel_id'] = channel.parentChannelID;
|
||||
data['parent_channel_type'] = channel.parentChannelType;
|
||||
if (channel.remoteExtraMap != null) {
|
||||
data['remote_extra'] = jsonEncode(channel.remoteExtraMap);
|
||||
}
|
||||
if (channel.localExtra != null) {
|
||||
data['extra'] = jsonEncode(channel.localExtra);
|
||||
}
|
||||
data['remote_extra'] = channel.remoteExtraMap?.toString() ?? "";
|
||||
data['extra'] = channel.localExtra?.toString() ?? "";
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
import '../entity/channel_member.dart';
|
||||
@ -152,9 +150,7 @@ class ChannelMemberDB {
|
||||
map['forbidden_expiration_time'] = member.forbiddenExpirationTime;
|
||||
map['created_at'] = member.createdAt;
|
||||
map['updated_at'] = member.updatedAt;
|
||||
if (member.extraMap != null) {
|
||||
map['extra'] = jsonEncode(member.extraMap);
|
||||
}
|
||||
map['extra'] = member.extraMap?.toString() ?? "";
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:wukongimfluttersdk/db/const.dart';
|
||||
@ -180,12 +179,13 @@ class ReminderDB {
|
||||
map['done'] = reminder.done;
|
||||
map['need_upload'] = reminder.needUpload;
|
||||
map['publisher'] = reminder.publisher;
|
||||
if (reminder.data != null) {
|
||||
map['data'] = jsonEncode(reminder.data);
|
||||
// 可以有错误数据
|
||||
var len = reminder.data?.toString().length ?? 0;
|
||||
if (len < 1000000) {
|
||||
map['data'] = reminder.data?.toString() ?? "";
|
||||
} else {
|
||||
map['data'] = '';
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ description: wukong IM flutter sdk
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.6.4
|
||||
version: 1.6.5
|
||||
homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK
|
||||
|
||||
environment:
|
||||
|
43
test/json_encode_test.dart
Normal file
43
test/json_encode_test.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'dart:convert';
|
||||
|
||||
void main() {
|
||||
// 测试 dynamic 类型的空数据
|
||||
dynamic emptyList = [];
|
||||
print('Empty list: ${jsonEncode(emptyList)}');
|
||||
|
||||
dynamic emptyMap = {};
|
||||
print('Empty map: ${jsonEncode(emptyMap)}');
|
||||
|
||||
// 测试其他类型的空数据
|
||||
dynamic emptyInt = 0;
|
||||
print('Empty int (0): ${jsonEncode(emptyInt)}');
|
||||
|
||||
dynamic emptyDouble = 0.0;
|
||||
print('Empty double (0.0): ${jsonEncode(emptyDouble)}');
|
||||
|
||||
dynamic emptyBool = false;
|
||||
print('Empty bool (false): ${jsonEncode(emptyBool)}');
|
||||
|
||||
// 测试 null
|
||||
print('Null value: ${jsonEncode(null)}');
|
||||
|
||||
// 测试空字符串
|
||||
String emptyString = '';
|
||||
print('Empty string: ${jsonEncode(emptyString)}');
|
||||
|
||||
// 测试普通字符串
|
||||
String normalString = 'Hello World';
|
||||
print('Normal string: ${jsonEncode(normalString)}');
|
||||
|
||||
// 测试包含特殊字符的字符串
|
||||
String specialString = 'Hello "World" with \'quotes\' and \\backslash\\';
|
||||
print('Special string: ${jsonEncode(specialString)}');
|
||||
|
||||
// 测试包含换行符的字符串
|
||||
String multilineString = 'Line 1\nLine 2\nLine 3';
|
||||
print('Multiline string: ${jsonEncode(multilineString)}');
|
||||
|
||||
// 测试包含Unicode字符的字符串
|
||||
String unicodeString = '你好,世界!';
|
||||
print('Unicode string: ${jsonEncode(unicodeString)}');
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user