Browse Source

发消息修改

wr_202303
zsw 4 months ago
parent
commit
bf1345b13c
  1. 7
      lib/im/chat_details_page.dart
  2. 14
      lib/im/database/hx_database.dart
  3. 39
      lib/im/im_view/im_page.dart
  4. 10
      lib/retrofit/data/im_user.dart
  5. 6
      lib/retrofit/retrofit_api.dart
  6. 14
      lib/retrofit/retrofit_api.g.dart

7
lib/im/chat_details_page.dart

@ -9,7 +9,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/im/database/message.dart';
import 'package:huixiang/im/out/message.pb.dart';
import 'package:huixiang/main.dart';
import 'package:huixiang/retrofit/data/im_user_list.dart';
import 'package:huixiang/retrofit/data/im_user.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter/cupertino.dart';
@ -56,7 +56,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
String tex = "";
int copyIndex = 0;
String selfUserId = "";
ImUserList _toUser;
ImUser _toUser;
@override
void onMessage(txt) {
@ -66,7 +66,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
List<Message> messages = [];
loadMessageList() async {
selfUserId = (await SharedPreferences.getInstance()).getString("userId");
// unread msg 2 read state
await hxDatabase.readMessage(selfUserId, _toUser.mid);
messages = await hxDatabase.queryUList(_toUser.mid);
socketClient.addCallback(_toUser.mid, (Message message) {

14
lib/im/database/hx_database.dart

@ -4,7 +4,7 @@ import 'package:huixiang/im/database/message.dart';
import 'package:huixiang/im/database/migration.dart';
import 'package:sqflite/sqflite.dart';
import '../../retrofit/data/im_user_list.dart';
import '../../retrofit/data/im_user.dart';
class HxDatabase {
Database db;
@ -147,25 +147,25 @@ class HxDatabase {
where: 'mid = ?', whereArgs: [imUserMap['mid']]);
}
Future<List<ImUserList>> queryImUser(List<String> userIds) async {
Future<List<ImUser>> queryImUser(List<String> userIds) async {
if (db == null) {
return Future.value(<ImUserList>[]);
return Future.value(<ImUser>[]);
}
String query = 'SELECT * FROM ImUser WHERE mid IN (${userIds.map((mid) => "'$mid'").join(',')})';
return db.rawQuery(query).then((value) {
return value.map((e) => ImUserList.fromJson(e)).toList();
return value.map((e) => ImUser.fromJson(e)).toList();
}, onError: (error) {
debugPrint("ImUser_error: $error");
});
}
Future<ImUserList> queryImUserById(String userId) async {
Future<ImUser> queryImUserById(String userId) async {
if (db == null) {
return Future.value();
}
List<ImUserList> imUser = await db.query("ImUser",
List<ImUser> imUser = await db.query("ImUser",
distinct: true, where: "mid = ?", whereArgs: [userId]).then((value) {
return value.map((e) => ImUserList.fromJson(e)).toList();
return value.map((e) => ImUser.fromJson(e)).toList();
}, onError: (error) {
debugPrint("ImUser_error: $error");
});

39
lib/im/im_view/im_page.dart

@ -23,7 +23,7 @@ import 'package:intl/intl.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../retrofit/data/im_user_list.dart';
import '../../retrofit/data/im_user.dart';
import '../../utils/flutter_utils.dart';
import '../../view_widget/custom_image.dart';
import 'on_chat_message.dart';
@ -88,7 +88,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
List<String> userIds = [];
Map<String, Message> lastMessageMap = {};
Map<String, int> unreadCountMap = {};
Map<String, ImUserList> contactMap = {};
Map<String, ImUser> contactMap = {};
loadMessageList() async {
SharedPreferences shared = await SharedPreferences.getInstance();
@ -123,7 +123,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
.toSet()
.where((element) => element != userId)
.toList();
List<ImUserList> contacts = (await hxDatabase.queryImUser(userIds)) ?? [];
List<ImUser> contacts = (await hxDatabase.queryImUser(userIds)) ?? [];
unreadCountMap = await hxDatabase.messageUnreadCount(userIds, userId);
lastMessageMap = messages.lGroupBy((p0) => p0.toId != userId ? p0.toId : p0.fromId).mGroupItem;
@ -235,7 +235,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
if (mids.isEmpty) {
return;
}
BaseData<List<ImUserList>> baseData = await apiService.memberInfoByIds({
BaseData<List<ImUser>> baseData = await apiService.memberInfoByIds({
"mids": mids,
}).catchError((error) {
SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type),
@ -504,22 +504,23 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
),
),
),
Container(
width: 16,
height: 16,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xFFFF441A),
),
child: RoundButton(
text: "99",
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize: 10.sp,
radius: 100,
if (unreadCountMap[userId] != null && unreadCountMap[userId] > 0)
Container(
width: 16,
height: 16,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xFFFF441A),
),
child: RoundButton(
text: "${unreadCountMap[userId]}",
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize: 10.sp,
radius: 100,
),
),
),
],
),
],

10
lib/retrofit/data/im_user_list.dart → lib/retrofit/data/im_user.dart

@ -5,8 +5,8 @@
/// isFollow : null
/// createTime : null
class ImUserList {
ImUserList({
class ImUser {
ImUser({
String mid,
String nickname,
num isDelete,
@ -19,7 +19,7 @@ class ImUserList {
_phone = phone;
}
ImUserList.fromJson(dynamic json) {
ImUser.fromJson(dynamic json) {
_mid = json['mid'];
_nickname = json['nickname'];
_isDelete = json['isDelete'];
@ -31,12 +31,12 @@ class ImUserList {
num _isDelete;
String _avatar;
String _phone;
ImUserList copyWith({ String mid,
ImUser copyWith({ String mid,
String nickname,
num isDelete,
String avatar,
String phone,
}) => ImUserList( mid: mid ?? _mid,
}) => ImUser( mid: mid ?? _mid,
nickname: nickname ?? _nickname,
isDelete: isDelete ?? _isDelete,
avatar: avatar ?? _avatar,

6
lib/retrofit/retrofit_api.dart

@ -39,7 +39,7 @@ import 'data/goods_category.dart';
import 'data/headlines_list.dart';
import 'data/headlines_list_details.dart';
import 'data/home_rank.dart';
import 'data/im_user_list.dart';
import 'data/im_user.dart';
import 'data/invitation_list.dart';
import 'data/invoice_list.dart';
import 'data/invoices_detail_info.dart';
@ -657,11 +657,11 @@ abstract class ApiService {
///
@POST("/member/memberInfoByIds")
Future<BaseData<List<ImUserList>>> memberInfoByIds(@Body() Map<String, dynamic> param);
Future<BaseData<List<ImUser>>> memberInfoByIds(@Body() Map<String, dynamic> param);
///Im关键字搜索
@GET("/member/memberSearch?keyword={keyword}")
Future<BaseData<List<ImUserList>>> memberSearch(
Future<BaseData<List<ImUser>>> memberSearch(
@Path("keyword") String keyword);
}

14
lib/retrofit/retrofit_api.g.dart

@ -2530,7 +2530,7 @@ class _ApiService implements ApiService {
}
@override
Future<BaseData<List<ImUserList>>> memberInfoByIds(param) async {
Future<BaseData<List<ImUser>>> memberInfoByIds(param) async {
ArgumentError.checkNotNull(param, 'param');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
@ -2545,16 +2545,16 @@ class _ApiService implements ApiService {
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<List<ImUserList>>.fromJson(
final value = BaseData<List<ImUser>>.fromJson(
_result.data,
(json) => (json as List<dynamic>)
.map<ImUserList>((i) => ImUserList.fromJson(i as Map<String, dynamic>))
.map<ImUser>((i) => ImUser.fromJson(i as Map<String, dynamic>))
.toList());
return value;
}
@override
Future<BaseData<List<ImUserList>>> memberSearch(keyword) async {
Future<BaseData<List<ImUser>>> memberSearch(keyword) async {
ArgumentError.checkNotNull(keyword, 'keyword');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
@ -2568,11 +2568,11 @@ class _ApiService implements ApiService {
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<List<ImUserList>>.fromJson(
final value = BaseData<List<ImUser>>.fromJson(
_result.data,
(json) => (json as List<dynamic>)
.map<ImUserList>(
(i) => ImUserList.fromJson(i as Map<String, dynamic>))
.map<ImUser>(
(i) => ImUser.fromJson(i as Map<String, dynamic>))
.toList());
return value;
}

Loading…
Cancel
Save