Browse Source

change convasion refresh range

wr_202303
zsw 4 months ago
parent
commit
5441937532
  1. 3
      lib/im/SocketClient.dart
  2. 19
      lib/im/chat_details_page.dart
  3. 185
      lib/im/im_view/im_page.dart
  4. 1
      lib/view_widget/classic_header.dart

3
lib/im/SocketClient.dart

@ -209,7 +209,6 @@ class SocketClient {
} }
Future<Message> sendMessage(String toId, String content, {String attach, int msgType = 1, replyId}) async { Future<Message> sendMessage(String toId, String content, {String attach, int msgType = 1, replyId}) async {
MsgType type = MsgType.values[msgType]; MsgType type = MsgType.values[msgType];
Uint8List data; Uint8List data;
if (type == MsgType.TEXT) { if (type == MsgType.TEXT) {
@ -254,8 +253,6 @@ class SocketClient {
return Message.fromJson(message); return Message.fromJson(message);
} }
checkSocket() { checkSocket() {
if (_socket == null) { if (_socket == null) {
reconnect(); reconnect();

19
lib/im/chat_details_page.dart

@ -422,8 +422,14 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
onTap: () { onTap: () {
setState(() { setState(() {
copyIndex = 0; copyIndex = 0;
FocusScope.of(context).requestFocus(FocusNode()); if (emojiShowing) {
emojiShowing = !emojiShowing;
}
if (moreShow) {
moreShow = !moreShow;
}
}); });
FocusScope.of(context).requestFocus(FocusNode());
}, },
child: chatDetailsItem(position), child: chatDetailsItem(position),
); );
@ -573,6 +579,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
padding: EdgeInsets.only(left: 17.w, right: 39.w), padding: EdgeInsets.only(left: 17.w, right: 39.w),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
@ -735,6 +742,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
padding: EdgeInsets.only(left: 36.w, right: 16.w), padding: EdgeInsets.only(left: 36.w, right: 16.w),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
if (messages[position].state == 3) if (messages[position].state == 3)
Container( Container(
@ -806,8 +814,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
Navigator.of(context).pushNamed('/router/personal_page', Navigator.of(context).pushNamed(
arguments: {"memberId": "0", "inletType": 1}); '/router/personal_page',
arguments: {
"memberId": "0",
"inletType": 1,
},
);
}, },
child: MImage( child: MImage(
userInfo?.headimg ?? "", userInfo?.headimg ?? "",

185
lib/im/im_view/im_page.dart

@ -74,7 +74,8 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
initSocketClient(); initSocketClient();
SharedPreferences.getInstance().then((value) { SharedPreferences.getInstance().then((value) {
apiService = ApiService(Dio(), token: value.getString("token"), context: context); apiService =
ApiService(Dio(), token: value.getString("token"), context: context);
queryMsgStats(); queryMsgStats();
}); });
} }
@ -118,9 +119,12 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
loadMessageList() async { loadMessageList() async {
messages = await hxDatabase.queryList(); messages = await hxDatabase.queryList();
lastMessageMap = messages.lGroupBy((p0) => p0.conversationId).mGroupItem(key: (p1) => num.parse(p1.time)); lastMessageMap = messages
.lGroupBy((p0) => p0.conversationId)
.mGroupItem(key: (p1) => num.parse(p1.time));
await queryImUserInfo(messages.map((e) => e.toId != selfUserId ? e.toId : e.fromId).toList()); await queryImUserInfo(
messages.map((e) => e.toId != selfUserId ? e.toId : e.fromId).toList());
await sortConversation(lastMessageMap); await sortConversation(lastMessageMap);
@ -132,11 +136,10 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
/// update conversation by time sort /// update conversation by time sort
sortConversation(lastMessageMap) async { sortConversation(lastMessageMap) async {
List<Message> sortMessages = lastMessageMap.values.toList(); List<Message> sortMessages = lastMessageMap.values.toList();
sortMessages.sort((a, b) => (num.parse(b.time)).compareTo(num.parse(a.time))); sortMessages
conversationIds = sortMessages .sort((a, b) => (num.parse(b.time)).compareTo(num.parse(a.time)));
.map((e) => e.conversationId) conversationIds =
.toSet() sortMessages.map((e) => e.conversationId).toSet().toList();
.toList();
} }
/// update conversation unreadcount /// update conversation unreadcount
@ -152,16 +155,20 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
await queryMemberInfo(userIds); await queryMemberInfo(userIds);
return; return;
} else { } else {
List<String> queryUserIds = userIds.where((u) => contacts.where((c) => c.mid == u).isEmpty).toList(); List<String> queryUserIds = userIds
.where((u) => contacts.where((c) => c.mid == u).isEmpty)
.toList();
if (queryUserIds.isNotEmpty) { if (queryUserIds.isNotEmpty) {
await queryMemberInfo(queryUserIds); await queryMemberInfo(queryUserIds);
return; return;
} }
} }
contactMap = contacts.lGroupBy((p0) => conversationId(p0.mid, selfUserId)).mGroupItem(); contactMap = contacts
List<String> topConversationIds = [],notTopUserIds = []; .lGroupBy((p0) => conversationId(p0.mid, selfUserId))
.mGroupItem();
List<String> topConversationIds = [], notTopUserIds = [];
contactMap.forEach((key, value) { contactMap.forEach((key, value) {
if(value.isTop == 1) if (value.isTop == 1)
topConversationIds.add(key); topConversationIds.add(key);
else else
notTopUserIds.add(key); notTopUserIds.add(key);
@ -173,7 +180,8 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
/// update one conversation last message ,and update conversation sort /// update one conversation last message ,and update conversation sort
void updateLastMessage(String conversationId) async { void updateLastMessage(String conversationId) async {
Message message = await hxDatabase.lastMessage(conversationId); Message message = await hxDatabase.lastMessage(conversationId);
debugPrint("lastmessage: $conversationId ${message?.content} ${message?.toJson()}"); debugPrint(
"lastmessage: $conversationId ${message?.content} ${message?.toJson()}");
if (message != null) { if (message != null) {
lastMessageMap[conversationId] = message; lastMessageMap[conversationId] = message;
await sortConversation(lastMessageMap); await sortConversation(lastMessageMap);
@ -187,7 +195,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
} }
refreshState() { refreshState() {
if(_refreshController.isRefresh)_refreshController.refreshCompleted(); if (_refreshController.isRefresh) _refreshController.refreshCompleted();
if (mounted) setState(() {}); if (mounted) setState(() {});
} }
@ -268,24 +276,6 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
stops: [0, 0.2, 0.4, 1], stops: [0, 0.2, 0.4, 1],
), ),
), ),
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
physics: BouncingScrollPhysics(),
footer: CustomFooter(
loadStyle: LoadStyle.ShowWhenLoading,
builder: (BuildContext context, LoadStatus mode) {
return (messages.length == 0) ? Container() : MyFooter(mode);
},
),
controller: _refreshController,
onRefresh: _refresh,
onLoading: () {
_refresh();
},
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column( child: Column(
children: [ children: [
Container( Container(
@ -312,7 +302,8 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
Navigator.of(context).pushNamed('/router/chat_friend_group') Navigator.of(context)
.pushNamed('/router/chat_friend_group')
.then((value) { .then((value) {
_refresh(); _refresh();
}); });
@ -335,61 +326,98 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
), ),
), ),
imPageSearch(), imPageSearch(),
Expanded(
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
physics: BouncingScrollPhysics(),
footer: CustomFooter(
loadStyle: LoadStyle.ShowWhenLoading,
builder: (BuildContext context, LoadStatus mode) {
return (messages.length == 0)
? Container()
: MyFooter(mode);
},
),
controller: _refreshController,
onRefresh: _refresh,
onLoading: () {
_refresh();
},
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: (){ onTap: () {
Navigator.of(context).pushNamed('/router/system_notice').then((value) { Navigator.of(context)
.pushNamed('/router/system_notice')
.then((value) {
setState(() { setState(() {
msgNumber["2"] = 0; msgNumber["2"] = 0;
msgNumber["3"] = 0; msgNumber["3"] = 0;
}); });
}); });
}, },
child:messageItem("assets/image/icon_system_message_new.webp", S.of(context).xitongxiaoxi, (msgNumber["2"]+msgNumber["3"]).toString()), child: messageItem(
"assets/image/icon_system_message_new.webp",
S.of(context).xitongxiaoxi,
(msgNumber["2"] + msgNumber["3"]).toString()),
), ),
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: (){ onTap: () {
Navigator.of(context).pushNamed('/router/system_details', Navigator.of(context).pushNamed(
'/router/system_details',
arguments: {"msgType": 4}).then((value) { arguments: {"msgType": 4}).then((value) {
setState(() { setState(() {
msgNumber["4"] = 0; msgNumber["4"] = 0;
}); });
}); });
}, },
child:messageItem("assets/image/icon_gz.webp", S.of(context).guanzhu,msgNumber["4"].toString()), child: messageItem("assets/image/icon_gz.webp",
S.of(context).guanzhu, msgNumber["4"].toString()),
), ),
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: (){ onTap: () {
Navigator.of(context).pushNamed('/router/system_details', Navigator.of(context).pushNamed(
'/router/system_details',
arguments: {"msgType": 6}).then((value) { arguments: {"msgType": 6}).then((value) {
setState(() { setState(() {
msgNumber["6"] = 0; msgNumber["6"] = 0;
}); });
}); });
}, },
child:messageItem("assets/image/icon_pl.webp", S.of(context).pinglun, msgNumber["6"].toString()), child: messageItem("assets/image/icon_pl.webp",
S.of(context).pinglun, msgNumber["6"].toString()),
), ),
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: (){ onTap: () {
Navigator.of(context).pushNamed('/router/system_details', Navigator.of(context).pushNamed(
'/router/system_details',
arguments: {"msgType": 5}).then((value) { arguments: {"msgType": 5}).then((value) {
setState(() { setState(() {
msgNumber["5"] = 0; msgNumber["5"] = 0;
}); });
}); });
}, },
child: messageItem("assets/image/icon_z.webp", S.of(context).dianzan, msgNumber["5"].toString()), child: messageItem("assets/image/icon_z.webp",
S.of(context).dianzan, msgNumber["5"].toString()),
), ),
chatList(), chatList(),
SizedBox(height:100.h) SizedBox(height: 100.h)
], ],
), ),
), ),
), ),
), ),
],
),
),
); );
} }
@ -397,7 +425,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Widget imPageSearch() { Widget imPageSearch() {
return GestureDetector( return GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap:(){ onTap: () {
Navigator.of(context).pushNamed('/router/im_search').then((value) { Navigator.of(context).pushNamed('/router/im_search').then((value) {
_refresh(); _refresh();
}); });
@ -429,8 +457,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
), ),
), ),
], ],
) )),
),
); );
} }
@ -443,7 +470,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
/// ///
Widget chatList() { Widget chatList() {
return ListView( return ListView(
padding: EdgeInsets.only(top:8.h), padding: EdgeInsets.only(top: 8.h),
shrinkWrap: true, shrinkWrap: true,
physics: NeverScrollableScrollPhysics(), physics: NeverScrollableScrollPhysics(),
children: conversationIds.map((e) { children: conversationIds.map((e) {
@ -458,10 +485,12 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
if (scrollController.offset > 0) { if (scrollController.offset > 0) {
if (lastScrollId != null && lastScrollId != e) if (lastScrollId != null && lastScrollId != e)
idsController[lastScrollId].jumpTo(0); idsController[lastScrollId].jumpTo(0);
if(lastScrollOffset < scrollController.offset){ if (lastScrollOffset < scrollController.offset) {
scrollController.jumpTo(scrollController.position.maxScrollExtent); scrollController
.jumpTo(scrollController.position.maxScrollExtent);
_isScrollOpen = true; _isScrollOpen = true;
}else if(lastScrollOffset > scrollController.offset && _isScrollOpen){ } else if (lastScrollOffset > scrollController.offset &&
_isScrollOpen) {
scrollController.jumpTo(0); scrollController.jumpTo(0);
} }
lastScrollId = e; lastScrollId = e;
@ -521,7 +550,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
), ),
), ),
), ),
onTap: () async{ onTap: () async {
// showDelDialog(conversationIds[position]); // showDelDialog(conversationIds[position]);
if (_isDelEnter) { if (_isDelEnter) {
await hxDatabase.deleteByUser(conversationIds[position]); await hxDatabase.deleteByUser(conversationIds[position]);
@ -550,7 +579,9 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Widget chatItem(conversationId) { Widget chatItem(conversationId) {
return Container( return Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: 16.w, right: 17.w, bottom: 18.h, left: 16.w,
right: 17.w,
bottom: 18.h,
), ),
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
child: Row( child: Row(
@ -620,7 +651,8 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
), ),
), ),
), ),
if (unreadCountMap[conversationId] != null && unreadCountMap[conversationId] > 0) if (unreadCountMap[conversationId] != null &&
unreadCountMap[conversationId] > 0)
Container( Container(
width: 16, width: 16,
height: 16, height: 16,
@ -649,7 +681,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Widget messageItem(img, title, messageNum) { Widget messageItem(img, title, messageNum) {
return Container( return Container(
padding: EdgeInsets.only(top:8.h,bottom:8.h, left:16.w,right:15.w), padding: EdgeInsets.only(top: 8.h, bottom: 8.h, left: 16.w, right: 15.w),
child: Column( child: Column(
children: [ children: [
Row( Row(
@ -670,9 +702,9 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
), ),
), ),
Spacer(), Spacer(),
if(messageNum != "0") if (messageNum != "0")
((double.tryParse(messageNum) < 100)? ((double.tryParse(messageNum) < 100)
Container( ? Container(
width: 16, width: 16,
height: 16, height: 16,
decoration: BoxDecoration( decoration: BoxDecoration(
@ -680,21 +712,22 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
color: Color(0xFFFF441A), color: Color(0xFFFF441A),
), ),
child: RoundButton( child: RoundButton(
text:messageNum, text: messageNum,
textColor: Colors.white, textColor: Colors.white,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A), backgroup: Color(0xFFFF441A),
fontSize: 10.sp, fontSize: 10.sp,
radius: 100, radius: 100,
)): ))
Container( : Container(
padding: EdgeInsets.symmetric(horizontal:4.w,vertical:2.h), padding: EdgeInsets.symmetric(
horizontal: 4.w, vertical: 2.h),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100), borderRadius: BorderRadius.circular(100),
color: Color(0xFFFF441A), color: Color(0xFFFF441A),
), ),
child: RoundButton( child: RoundButton(
text:"99+", text: "99+",
textColor: Colors.white, textColor: Colors.white,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A), backgroup: Color(0xFFFF441A),
@ -725,8 +758,9 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Expanded(child:Container( Expanded(
alignment:Alignment.center, child: Container(
alignment: Alignment.center,
child: Text( child: Text(
"删除并清空聊天记录", "删除并清空聊天记录",
style: TextStyle( style: TextStyle(
@ -739,9 +773,9 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
), ),
// Spacer(), // Spacer(),
Container( Container(
height:1.h, height: 1.h,
width: double.infinity, width: double.infinity,
color:Color(0xFFEDEDED), color: Color(0xFFEDEDED),
), ),
Row( Row(
children: [ children: [
@ -752,26 +786,21 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
child: Container( child: Container(
child: Text( child: Text("取消",
"取消",
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
color: Color(0xFF060606), color: Color(0xFF060606),
) ))))),
)
)
)
),
Container( Container(
height:45, height: 45,
width: 1.w, width: 1.w,
color: Color(0xFFEDEDED), color: Color(0xFFEDEDED),
), ),
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () async{ onTap: () async {
await hxDatabase.deleteByUser(conversationId); await hxDatabase.deleteByUser(conversationId);
_refresh(); _refresh();
Navigator.of(context).pop(); Navigator.of(context).pop();

1
lib/view_widget/classic_header.dart

@ -17,6 +17,7 @@ class MyHeader extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MyClassicHeader( return MyClassicHeader(
height: 80,
refreshStyle: RefreshStyle.Follow, refreshStyle: RefreshStyle.Follow,
completeText: S.of(context).shuaxinchenggong, completeText: S.of(context).shuaxinchenggong,
failedText: S.of(context).shuaxinshibai, failedText: S.of(context).shuaxinshibai,

Loading…
Cancel
Save