group chat message carries avatar, nickname and remark in group chat
parent
fa81ae090d
commit
dbfb24defc
|
@ -11,12 +11,12 @@ class FriendSetting {
|
||||||
}
|
}
|
||||||
|
|
||||||
class GroupChatSetting {
|
class GroupChatSetting {
|
||||||
String nameRemark = '';
|
String groupChatRemark = '';
|
||||||
String myRemark = '';
|
String remarkInGroupChat = '';
|
||||||
|
|
||||||
GroupChatSetting.fromJson(Map<String, dynamic> json) {
|
GroupChatSetting.fromJson(Map<String, dynamic> json) {
|
||||||
nameRemark = json['nameRemark'] ?? '';
|
groupChatRemark = json['groupChatRemark'] ?? '';
|
||||||
myRemark = json['myRemark'] ?? '';
|
remarkInGroupChat = json['remarkInGroupChat'] ?? '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class Contact extends ChangeNotifier {
|
||||||
|
|
||||||
void addGroupChat(String groupChatId) {
|
void addGroupChat(String groupChatId) {
|
||||||
groupChats[groupChatId] =
|
groupChats[groupChatId] =
|
||||||
GroupChatSetting.fromJson({'nameRemark': '', 'myRemark': ''});
|
GroupChatSetting.fromJson({'groupChatRemark': '', 'remarkInGroupChat': ''});
|
||||||
groupChatCount += 1;
|
groupChatCount += 1;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
@ -93,11 +93,11 @@ class Contact extends ChangeNotifier {
|
||||||
String newValue,
|
String newValue,
|
||||||
) {
|
) {
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
case 'nameRemark':
|
case 'groupChatRemark':
|
||||||
groupChats[groupChatId]!.nameRemark = newValue;
|
groupChats[groupChatId]!.groupChatRemark = newValue;
|
||||||
break;
|
break;
|
||||||
case 'myRemark':
|
case 'remarkInGroupChat':
|
||||||
groupChats[groupChatId]!.myRemark = newValue;
|
groupChats[groupChatId]!.remarkInGroupChat = newValue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,12 +171,12 @@ class GroupChatProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
class GroupChatMemberNameAvatar {
|
class GroupChatMemberNameAvatar {
|
||||||
String remark = '';
|
String remarkInGroupChat = '';
|
||||||
String nickname = '';
|
String nickname = '';
|
||||||
String avatar = '';
|
String avatar = '';
|
||||||
|
|
||||||
GroupChatMemberNameAvatar.fromJson(Map<String, dynamic> json) {
|
GroupChatMemberNameAvatar.fromJson(Map<String, dynamic> json) {
|
||||||
remark = json['remark'] ?? '';
|
remarkInGroupChat = json['remarkInGroupChat'] ?? '';
|
||||||
nickname = json['nickname'] ?? '';
|
nickname = json['nickname'] ?? '';
|
||||||
avatar = json['avatar'] ?? '';
|
avatar = json['avatar'] ?? '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,6 +347,16 @@ void receiveGroupChatMsg(
|
||||||
ChatSetting? chatSetting = chatSettingBox.get(groupChatId);
|
ChatSetting? chatSetting = chatSettingBox.get(groupChatId);
|
||||||
DateTime dateTime = DateTime.parse(msg['dateTime'] as String);
|
DateTime dateTime = DateTime.parse(msg['dateTime'] as String);
|
||||||
|
|
||||||
|
getIt.get<ContactAccountProfile>().addGroupChatMemberProfile(
|
||||||
|
groupChatId,
|
||||||
|
msg['senderId'],
|
||||||
|
{
|
||||||
|
'avatar': msg['avatar'],
|
||||||
|
'nickname': msg['nickname'],
|
||||||
|
'remarkInGroupChat': msg['remarkInGroupChat'],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (chatSetting == null) {
|
if (chatSetting == null) {
|
||||||
chatSettingBox.put(
|
chatSettingBox.put(
|
||||||
groupChatId,
|
groupChatId,
|
||||||
|
@ -393,39 +403,17 @@ void receiveGroupChatMsg(
|
||||||
late String name;
|
late String name;
|
||||||
|
|
||||||
if (getIt.get<Contact>().friends.containsKey(senderId)) {
|
if (getIt.get<Contact>().friends.containsKey(senderId)) {
|
||||||
name = getIt.get<Contact>().friends[senderId]!.friendRemark.isEmpty
|
if (getIt.get<Contact>().friends[senderId]!.friendRemark.isNotEmpty) {
|
||||||
? getIt.get<ContactAccountProfile>().friends[senderId]!.nickname
|
name = getIt.get<Contact>().friends[senderId]!.friendRemark;
|
||||||
: getIt.get<Contact>().friends[senderId]!.friendRemark;
|
} else if ((msg['remarkInGroupChat'] as String).isNotEmpty) {
|
||||||
} else if (getIt
|
name = msg['remarkInGroupChat'];
|
||||||
.get<ContactAccountProfile>()
|
} else {
|
||||||
.grouChatMemberProfiles
|
name = msg['nickname'];
|
||||||
.containsKey(groupChatId)) {
|
|
||||||
if (getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[groupChatId]!
|
|
||||||
.containsKey(senderId)) {
|
|
||||||
name = getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[groupChatId]![senderId]!
|
|
||||||
.remark
|
|
||||||
.isEmpty
|
|
||||||
? getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[groupChatId]![senderId]!
|
|
||||||
.nickname
|
|
||||||
.isEmpty
|
|
||||||
? senderId.substring(0, 6)
|
|
||||||
: getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[groupChatId]![senderId]!
|
|
||||||
.nickname
|
|
||||||
: getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[groupChatId]![senderId]!
|
|
||||||
.remark;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
name = senderId.substring(0, 6);
|
name = (msg['remarkInGroupChat'] as String).isNotEmpty
|
||||||
|
? msg['remarkInGroupChat']
|
||||||
|
: msg['nickname'];
|
||||||
}
|
}
|
||||||
|
|
||||||
String routeName = getIt.get<RouteState>().currentPathName;
|
String routeName = getIt.get<RouteState>().currentPathName;
|
||||||
|
|
|
@ -295,9 +295,9 @@ class NotificationAPI {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
String groupChatName =
|
String groupChatName =
|
||||||
getIt.get<Contact>().groupChats[groupChatId]!.nameRemark.isEmpty
|
getIt.get<Contact>().groupChats[groupChatId]!.groupChatRemark.isEmpty
|
||||||
? getIt.get<ContactAccountProfile>().groupChats[groupChatId]!.name
|
? getIt.get<ContactAccountProfile>().groupChats[groupChatId]!.name
|
||||||
: getIt.get<Contact>().groupChats[groupChatId]!.nameRemark;
|
: getIt.get<Contact>().groupChats[groupChatId]!.groupChatRemark;
|
||||||
messagingStyle = MessagingStyleInformation(
|
messagingStyle = MessagingStyleInformation(
|
||||||
person,
|
person,
|
||||||
messages: messages[groupChatId]!.$2,
|
messages: messages[groupChatId]!.$2,
|
||||||
|
|
|
@ -187,7 +187,7 @@ final contactRouter = GoRoute(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return ChangeGroupChatRemarkScreen(
|
return ChangeGroupChatRemarkScreen(
|
||||||
groupChatId: state.queryParameters['groupChatId']!,
|
groupChatId: state.queryParameters['groupChatId']!,
|
||||||
nameRemark: state.queryParameters['nameRemark']!,
|
nameRemark: state.queryParameters['groupChatRemark']!,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -198,7 +198,7 @@ final contactRouter = GoRoute(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return ChangeMyRemarkScreen(
|
return ChangeMyRemarkScreen(
|
||||||
groupChatId: state.queryParameters['groupChatId']!,
|
groupChatId: state.queryParameters['groupChatId']!,
|
||||||
myRemark: state.queryParameters['myRemark']!,
|
myRemark: state.queryParameters['remarkInGroupChat']!,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
@ -38,14 +38,14 @@ class GroupChatChatTile extends StatefulWidget {
|
||||||
class _GroupChatChatTileState extends State<GroupChatChatTile> {
|
class _GroupChatChatTileState extends State<GroupChatChatTile> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
Box<ChatSetting> chatSettingBox = Hive.box('chat_setting');
|
||||||
|
ChatSetting chatSetting = chatSettingBox.getAt(widget.index)!;
|
||||||
return Slidable(
|
return Slidable(
|
||||||
key: const ValueKey(0),
|
key: const ValueKey(0),
|
||||||
endActionPane: ActionPane(
|
endActionPane: ActionPane(
|
||||||
motion: const BehindMotion(),
|
motion: const BehindMotion(),
|
||||||
dismissible: DismissiblePane(
|
dismissible: DismissiblePane(
|
||||||
onDismissed: () {
|
onDismissed: () {
|
||||||
Box<ChatSetting> chatSettingBox = Hive.box('chat_setting');
|
|
||||||
ChatSetting chatSetting = chatSettingBox.getAt(widget.index)!;
|
|
||||||
chatSetting.isOpen = false;
|
chatSetting.isOpen = false;
|
||||||
chatSettingBox.put(widget.contactId, chatSetting);
|
chatSettingBox.put(widget.contactId, chatSetting);
|
||||||
},
|
},
|
||||||
|
@ -59,11 +59,14 @@ class _GroupChatChatTileState extends State<GroupChatChatTile> {
|
||||||
label: '置顶',
|
label: '置顶',
|
||||||
),
|
),
|
||||||
SlidableAction(
|
SlidableAction(
|
||||||
onPressed: (BuildContext context) {},
|
onPressed: (BuildContext context) {
|
||||||
|
chatSetting.isHideMsg = !chatSetting.isHideMsg;
|
||||||
|
chatSettingBox.put(widget.contactId, chatSetting);
|
||||||
|
},
|
||||||
foregroundColor: kContentColorDark,
|
foregroundColor: kContentColorDark,
|
||||||
backgroundColor: kPrimaryColor,
|
backgroundColor: kPrimaryColor,
|
||||||
icon: Icons.remove_red_eye,
|
icon: Icons.remove_red_eye,
|
||||||
label: '隐藏消息',
|
label: chatSetting.isHideMsg ? '显示消息' : '隐藏消息',
|
||||||
flex: 1,
|
flex: 1,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -102,7 +105,7 @@ class _GroupChatChatTileState extends State<GroupChatChatTile> {
|
||||||
getIt
|
getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.contactId]!
|
.groupChats[widget.contactId]!
|
||||||
.nameRemark
|
.groupChatRemark
|
||||||
.isEmpty
|
.isEmpty
|
||||||
? getIt
|
? getIt
|
||||||
.get<ContactAccountProfile>()
|
.get<ContactAccountProfile>()
|
||||||
|
@ -111,7 +114,7 @@ class _GroupChatChatTileState extends State<GroupChatChatTile> {
|
||||||
: getIt
|
: getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.contactId]!
|
.groupChats[widget.contactId]!
|
||||||
.nameRemark,
|
.groupChatRemark,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -39,9 +39,16 @@ class GroupChatTile extends StatelessWidget {
|
||||||
width: 10.0,
|
width: 10.0,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
getIt.get<Contact>().groupChats[groupChatId]!.nameRemark.isEmpty
|
getIt
|
||||||
|
.get<Contact>()
|
||||||
|
.groupChats[groupChatId]!
|
||||||
|
.groupChatRemark
|
||||||
|
.isEmpty
|
||||||
? getIt<ContactAccountProfile>().groupChats[groupChatId]!.name
|
? getIt<ContactAccountProfile>().groupChats[groupChatId]!.name
|
||||||
: getIt.get<Contact>().groupChats[groupChatId]!.nameRemark,
|
: getIt
|
||||||
|
.get<Contact>()
|
||||||
|
.groupChats[groupChatId]!
|
||||||
|
.groupChatRemark,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: const TextStyle(fontSize: 17),
|
style: const TextStyle(fontSize: 17),
|
||||||
),
|
),
|
||||||
|
|
|
@ -106,7 +106,7 @@ class _ChangeGroupChatRemarkScreenState
|
||||||
).show(context);
|
).show(context);
|
||||||
|
|
||||||
getIt.get<Contact>().changeGroupChatSetting(
|
getIt.get<Contact>().changeGroupChatSetting(
|
||||||
'nameRemark',
|
'groupChatRemark',
|
||||||
widget.groupChatId,
|
widget.groupChatId,
|
||||||
_controller.text,
|
_controller.text,
|
||||||
);
|
);
|
||||||
|
|
|
@ -104,7 +104,7 @@ class _ChangeMyRemarkScreenState extends State<ChangeMyRemarkScreen> {
|
||||||
).show(context);
|
).show(context);
|
||||||
|
|
||||||
getIt.get<Contact>().changeGroupChatSetting(
|
getIt.get<Contact>().changeGroupChatSetting(
|
||||||
'myRemark',
|
'remarkInGroupChat',
|
||||||
widget.groupChatId,
|
widget.groupChatId,
|
||||||
_controller.text,
|
_controller.text,
|
||||||
);
|
);
|
||||||
|
|
|
@ -82,7 +82,7 @@ class _GroupChatProfileScreenState extends State<GroupChatProfileScreen> {
|
||||||
getIt
|
getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.groupChatId]!
|
.groupChats[widget.groupChatId]!
|
||||||
.nameRemark
|
.groupChatRemark
|
||||||
.isEmpty
|
.isEmpty
|
||||||
? getIt
|
? getIt
|
||||||
.get<ContactAccountProfile>()
|
.get<ContactAccountProfile>()
|
||||||
|
@ -91,7 +91,7 @@ class _GroupChatProfileScreenState extends State<GroupChatProfileScreen> {
|
||||||
: getIt
|
: getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.groupChatId]!
|
.groupChats[widget.groupChatId]!
|
||||||
.nameRemark,
|
.groupChatRemark,
|
||||||
style: const TextStyle(fontSize: 18),
|
style: const TextStyle(fontSize: 18),
|
||||||
),
|
),
|
||||||
subtitle: Text(widget.groupChatId),
|
subtitle: Text(widget.groupChatId),
|
||||||
|
@ -206,10 +206,10 @@ class _GroupChatProfileScreenState extends State<GroupChatProfileScreen> {
|
||||||
onTap: () {
|
onTap: () {
|
||||||
final query = {
|
final query = {
|
||||||
'groupChatId': widget.groupChatId,
|
'groupChatId': widget.groupChatId,
|
||||||
'myRemark': getIt
|
'remarkInGroupChat': getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.groupChatId]!
|
.groupChats[widget.groupChatId]!
|
||||||
.myRemark,
|
.remarkInGroupChat,
|
||||||
};
|
};
|
||||||
context.pushNamed(
|
context.pushNamed(
|
||||||
'ChangeMyRemark',
|
'ChangeMyRemark',
|
||||||
|
@ -220,16 +220,16 @@ class _GroupChatProfileScreenState extends State<GroupChatProfileScreen> {
|
||||||
info: getIt
|
info: getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.groupChatId]!
|
.groupChats[widget.groupChatId]!
|
||||||
.myRemark,
|
.remarkInGroupChat,
|
||||||
),
|
),
|
||||||
GroupChatProfileTile(
|
GroupChatProfileTile(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
final query = {
|
final query = {
|
||||||
'groupChatId': widget.groupChatId,
|
'groupChatId': widget.groupChatId,
|
||||||
'nameRemark': getIt
|
'groupChatRemark': getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.groupChatId]!
|
.groupChats[widget.groupChatId]!
|
||||||
.nameRemark,
|
.groupChatRemark,
|
||||||
};
|
};
|
||||||
context.pushNamed(
|
context.pushNamed(
|
||||||
'ChangeGroupChatRemark',
|
'ChangeGroupChatRemark',
|
||||||
|
@ -240,7 +240,7 @@ class _GroupChatProfileScreenState extends State<GroupChatProfileScreen> {
|
||||||
info: getIt
|
info: getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.groupChatId]!
|
.groupChats[widget.groupChatId]!
|
||||||
.nameRemark,
|
.groupChatRemark,
|
||||||
),
|
),
|
||||||
const GroupChatProfileHeader(
|
const GroupChatProfileHeader(
|
||||||
header: '聊天记录',
|
header: '聊天记录',
|
||||||
|
|
|
@ -10,7 +10,6 @@ import 'package:together_mobile/database/box_type.dart';
|
||||||
import 'package:together_mobile/models/contact_model.dart';
|
import 'package:together_mobile/models/contact_model.dart';
|
||||||
import 'package:together_mobile/models/init_get_it.dart';
|
import 'package:together_mobile/models/init_get_it.dart';
|
||||||
import 'package:together_mobile/models/user_model.dart';
|
import 'package:together_mobile/models/user_model.dart';
|
||||||
import 'package:together_mobile/request/group_chat.dart';
|
|
||||||
import 'package:together_mobile/request/server.dart';
|
import 'package:together_mobile/request/server.dart';
|
||||||
|
|
||||||
class GroupChatMessageBubble extends StatefulWidget {
|
class GroupChatMessageBubble extends StatefulWidget {
|
||||||
|
@ -42,44 +41,44 @@ class _GroupChatMessageBubbleState extends State<GroupChatMessageBubble> {
|
||||||
final List<Timer> _timerList = [];
|
final List<Timer> _timerList = [];
|
||||||
late bool _isHideMsg;
|
late bool _isHideMsg;
|
||||||
|
|
||||||
Future<bool> _getMemberGroupChatProfile() async {
|
// Future<bool> _getMemberGroupChatProfile() async {
|
||||||
if (widget.senderId == getIt.get<UserAccount>().id) {
|
// if (widget.senderId == getIt.get<UserAccount>().id) {
|
||||||
// myself or already have profile
|
// // myself or already have profile
|
||||||
return Future(() => true);
|
// return Future(() => true);
|
||||||
}
|
// }
|
||||||
if (getIt
|
// if (getIt
|
||||||
.get<ContactAccountProfile>()
|
// .get<ContactAccountProfile>()
|
||||||
.grouChatMemberProfiles
|
// .grouChatMemberProfiles
|
||||||
.containsKey(widget.contactId) &&
|
// .containsKey(widget.contactId) &&
|
||||||
getIt
|
// getIt
|
||||||
.get<ContactAccountProfile>()
|
// .get<ContactAccountProfile>()
|
||||||
.grouChatMemberProfiles[widget.contactId]!
|
// .grouChatMemberProfiles[widget.contactId]!
|
||||||
.containsKey(widget.senderId)) {
|
// .containsKey(widget.senderId)) {
|
||||||
return Future(() => true);
|
// return Future(() => true);
|
||||||
} else {
|
// } else {
|
||||||
Map<String, dynamic> res;
|
// Map<String, dynamic> res;
|
||||||
if (getIt.get<Contact>().friends.containsKey(widget.senderId)) {
|
// if (getIt.get<Contact>().friends.containsKey(widget.senderId)) {
|
||||||
// my friend
|
// // my friend
|
||||||
res = await getGroupChatMemberNameAvatar(
|
// res = await getGroupChatMemberNameAvatar(
|
||||||
widget.contactId,
|
// widget.contactId,
|
||||||
widget.senderId,
|
// widget.senderId,
|
||||||
true,
|
// true,
|
||||||
);
|
// );
|
||||||
} else {
|
// } else {
|
||||||
res = await getGroupChatMemberNameAvatar(
|
// res = await getGroupChatMemberNameAvatar(
|
||||||
widget.contactId,
|
// widget.contactId,
|
||||||
widget.senderId,
|
// widget.senderId,
|
||||||
false,
|
// false,
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
getIt.get<ContactAccountProfile>().addGroupChatMemberProfile(
|
// getIt.get<ContactAccountProfile>().addGroupChatMemberProfile(
|
||||||
widget.contactId,
|
// widget.contactId,
|
||||||
widget.senderId,
|
// widget.senderId,
|
||||||
res['data'],
|
// res['data'],
|
||||||
);
|
// );
|
||||||
return Future(() => true);
|
// return Future(() => true);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -128,15 +127,19 @@ class _GroupChatMessageBubbleState extends State<GroupChatMessageBubble> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
|
||||||
for (var element in _timerList) {
|
for (var element in _timerList) {
|
||||||
element.cancel();
|
element.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
bool isFriend = getIt.get<Contact>().friends.containsKey(widget.senderId);
|
bool isOther = widget.senderId != getIt.get<UserAccount>().id;
|
||||||
|
// Because myself is also in `friends` map
|
||||||
|
bool isFriend =
|
||||||
|
getIt.get<Contact>().friends.containsKey(widget.senderId) && isOther;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
|
@ -157,57 +160,20 @@ class _GroupChatMessageBubbleState extends State<GroupChatMessageBubble> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
textDirection: widget.senderId != getIt.get<UserAccount>().id
|
textDirection: isOther ? TextDirection.ltr : TextDirection.rtl,
|
||||||
? TextDirection.ltr
|
|
||||||
: TextDirection.rtl,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
widget.senderId != getIt.get<UserAccount>().id
|
_showAvatar(isOther),
|
||||||
? FutureBuilder(
|
|
||||||
future: _getMemberGroupChatProfile(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
return _showAvatar(snapshot, isFriend);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: getIt.get<UserProfile>().avatar.isNotEmpty
|
|
||||||
? CircleAvatar(
|
|
||||||
backgroundImage: CachedNetworkImageProvider(
|
|
||||||
'$userAvatarsUrl/${getIt.get<UserProfile>().avatar}',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const CircleAvatar(
|
|
||||||
backgroundImage:
|
|
||||||
AssetImage('assets/images/user_4.png'),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 10,
|
width: 10,
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment: isOther
|
||||||
widget.senderId != getIt.get<UserAccount>().id
|
|
||||||
? CrossAxisAlignment.start
|
? CrossAxisAlignment.start
|
||||||
: CrossAxisAlignment.end,
|
: CrossAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
widget.senderId == getIt.get<UserAccount>().id
|
_showName(isOther, isFriend),
|
||||||
? getIt
|
|
||||||
.get<Contact>()
|
|
||||||
.groupChats[widget.contactId]!
|
|
||||||
.myRemark
|
|
||||||
.isEmpty
|
|
||||||
? Text(getIt.get<UserProfile>().nickname)
|
|
||||||
: Text(
|
|
||||||
getIt
|
|
||||||
.get<Contact>()
|
|
||||||
.groupChats[widget.contactId]!
|
|
||||||
.myRemark,
|
|
||||||
)
|
|
||||||
: FutureBuilder(
|
|
||||||
future: _getMemberGroupChatProfile(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
return _showName(snapshot, isFriend);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 5,
|
height: 5,
|
||||||
),
|
),
|
||||||
|
@ -224,8 +190,10 @@ class _GroupChatMessageBubbleState extends State<GroupChatMessageBubble> {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
if (_isHideMsg) const Text('消息已隐藏'),
|
||||||
|
|
||||||
// text message content
|
// text message content
|
||||||
if (widget.text.isNotEmpty)
|
if (widget.text.isNotEmpty && !_isHideMsg)
|
||||||
Text(
|
Text(
|
||||||
widget.text,
|
widget.text,
|
||||||
textWidthBasis: TextWidthBasis.longestLine,
|
textWidthBasis: TextWidthBasis.longestLine,
|
||||||
|
@ -234,7 +202,7 @@ class _GroupChatMessageBubbleState extends State<GroupChatMessageBubble> {
|
||||||
height: 10,
|
height: 10,
|
||||||
),
|
),
|
||||||
// image content if have
|
// image content if have
|
||||||
if (widget.attachments.isNotEmpty)
|
if (widget.attachments.isNotEmpty && !_isHideMsg)
|
||||||
...List.generate(
|
...List.generate(
|
||||||
widget.attachments.length,
|
widget.attachments.length,
|
||||||
(int index) {
|
(int index) {
|
||||||
|
@ -287,21 +255,9 @@ class _GroupChatMessageBubbleState extends State<GroupChatMessageBubble> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CircleAvatar _showAvatar(AsyncSnapshot snapshot, bool isFriend) {
|
CircleAvatar _showAvatar(bool isOther) {
|
||||||
if (snapshot.hasData) {
|
if (isOther) {
|
||||||
if (isFriend) {
|
print(isOther);
|
||||||
String avatar =
|
|
||||||
getIt.get<ContactAccountProfile>().friends[widget.senderId]!.avatar;
|
|
||||||
return avatar.isEmpty
|
|
||||||
? CircleAvatar(
|
|
||||||
child: Image.asset('assets/images/user_4.png'),
|
|
||||||
)
|
|
||||||
: CircleAvatar(
|
|
||||||
backgroundImage: CachedNetworkImageProvider(
|
|
||||||
'$userAvatarsUrl/$avatar',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
String avatar = getIt
|
String avatar = getIt
|
||||||
.get<ContactAccountProfile>()
|
.get<ContactAccountProfile>()
|
||||||
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
||||||
|
@ -315,12 +271,8 @@ class _GroupChatMessageBubbleState extends State<GroupChatMessageBubble> {
|
||||||
'$userAvatarsUrl/$avatar',
|
'$userAvatarsUrl/$avatar',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// fix the bug that when the future return, the avatar will flash
|
String avatar = getIt.get<UserProfile>().avatar;
|
||||||
if (isFriend) {
|
|
||||||
String avatar =
|
|
||||||
getIt.get<ContactAccountProfile>().friends[widget.senderId]!.avatar;
|
|
||||||
return avatar.isEmpty
|
return avatar.isEmpty
|
||||||
? CircleAvatar(
|
? CircleAvatar(
|
||||||
child: Image.asset('assets/images/user_4.png'),
|
child: Image.asset('assets/images/user_4.png'),
|
||||||
|
@ -330,147 +282,52 @@ class _GroupChatMessageBubbleState extends State<GroupChatMessageBubble> {
|
||||||
'$userAvatarsUrl/$avatar',
|
'$userAvatarsUrl/$avatar',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
if (getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles
|
|
||||||
.containsKey(widget.contactId)) {
|
|
||||||
if (getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[widget.contactId]!
|
|
||||||
.containsKey(widget.senderId)) {
|
|
||||||
String avatar = getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
|
||||||
.avatar;
|
|
||||||
return avatar.isNotEmpty
|
|
||||||
? CircleAvatar(
|
|
||||||
backgroundImage: CachedNetworkImageProvider(
|
|
||||||
'$userAvatarsUrl/$avatar',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const CircleAvatar(
|
|
||||||
backgroundImage: AssetImage(
|
|
||||||
'assets/images/user_4.png',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return const CircleAvatar(
|
|
||||||
backgroundImage: AssetImage(
|
|
||||||
'assets/images/user_4.png',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return const CircleAvatar(
|
|
||||||
backgroundImage: AssetImage(
|
|
||||||
'assets/images/user_4.png',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text _showName(AsyncSnapshot snapshot, bool isFriend) {
|
Text _showName(bool isOther, bool isFriend) {
|
||||||
if (snapshot.hasData) {
|
|
||||||
if (isFriend) {
|
|
||||||
String friendRemark =
|
|
||||||
getIt.get<Contact>().friends[widget.senderId]!.friendRemark;
|
|
||||||
String remarkInGroupChat = getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
|
||||||
.remark;
|
|
||||||
|
|
||||||
return friendRemark.isEmpty
|
|
||||||
? remarkInGroupChat.isEmpty
|
|
||||||
? Text(
|
|
||||||
getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.friends[widget.senderId]!
|
|
||||||
.nickname,
|
|
||||||
)
|
|
||||||
: Text(remarkInGroupChat)
|
|
||||||
: Text(friendRemark);
|
|
||||||
} else {
|
|
||||||
String remarkInGroupChat = getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
|
||||||
.remark;
|
|
||||||
|
|
||||||
return remarkInGroupChat.isEmpty
|
|
||||||
? Text(
|
|
||||||
getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
|
||||||
.nickname,
|
|
||||||
)
|
|
||||||
: Text(remarkInGroupChat);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// fix the bug that when the future return, the name will flash
|
|
||||||
if (isFriend) {
|
if (isFriend) {
|
||||||
String friendRemark =
|
String friendRemark =
|
||||||
getIt.get<Contact>().friends[widget.senderId]!.friendRemark;
|
getIt.get<Contact>().friends[widget.senderId]!.friendRemark;
|
||||||
|
|
||||||
if (friendRemark.isNotEmpty) {
|
if (friendRemark.isNotEmpty) {
|
||||||
return Text(friendRemark);
|
return Text(friendRemark);
|
||||||
} else {
|
}
|
||||||
if (getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles
|
|
||||||
.containsKey(widget.contactId) &&
|
|
||||||
getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[widget.contactId]!
|
|
||||||
.containsKey(widget.senderId)) {
|
|
||||||
String remarkInGroupChat = getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
|
||||||
.remark;
|
|
||||||
String nickname = getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.friends[widget.senderId]!
|
|
||||||
.nickname;
|
|
||||||
|
|
||||||
return remarkInGroupChat.isEmpty
|
|
||||||
? Text(nickname)
|
|
||||||
: Text(remarkInGroupChat);
|
|
||||||
} else {
|
|
||||||
return Text(widget.senderId.substring(0, 5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles
|
|
||||||
.containsKey(widget.contactId)) {
|
|
||||||
if (getIt
|
|
||||||
.get<ContactAccountProfile>()
|
|
||||||
.grouChatMemberProfiles[widget.contactId]!
|
|
||||||
.containsKey(widget.senderId)) {
|
|
||||||
String remarkInGroupChat = getIt
|
String remarkInGroupChat = getIt
|
||||||
.get<ContactAccountProfile>()
|
.get<ContactAccountProfile>()
|
||||||
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
||||||
.remark;
|
.remarkInGroupChat;
|
||||||
String nickname = getIt
|
|
||||||
|
if (remarkInGroupChat.isNotEmpty) {
|
||||||
|
return Text(remarkInGroupChat);
|
||||||
|
} else {
|
||||||
|
return Text(remarkInGroupChat = getIt
|
||||||
.get<ContactAccountProfile>()
|
.get<ContactAccountProfile>()
|
||||||
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
||||||
.nickname;
|
.nickname);
|
||||||
|
}
|
||||||
|
} else if (isOther) {
|
||||||
|
String remarkInGroupChat = getIt
|
||||||
|
.get<ContactAccountProfile>()
|
||||||
|
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
||||||
|
.remarkInGroupChat;
|
||||||
|
|
||||||
|
if (remarkInGroupChat.isNotEmpty) {
|
||||||
|
return Text(remarkInGroupChat);
|
||||||
|
} else {
|
||||||
|
return Text(remarkInGroupChat = getIt
|
||||||
|
.get<ContactAccountProfile>()
|
||||||
|
.grouChatMemberProfiles[widget.contactId]![widget.senderId]!
|
||||||
|
.nickname);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String remarkInGroupChat =
|
||||||
|
getIt.get<Contact>().groupChats[widget.contactId]!.remarkInGroupChat;
|
||||||
|
|
||||||
return remarkInGroupChat.isNotEmpty
|
return remarkInGroupChat.isNotEmpty
|
||||||
? Text(remarkInGroupChat)
|
? Text(remarkInGroupChat)
|
||||||
: Text(nickname);
|
: Text(getIt.get<UserProfile>().nickname);
|
||||||
} else {
|
|
||||||
return Text(
|
|
||||||
widget.senderId.substring(0, 5),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Text(
|
|
||||||
widget.senderId.substring(0, 5),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,22 +272,9 @@ class _MessageInputBoxState extends State<MessageInputBox> {
|
||||||
'isShowTime': isShowTime,
|
'isShowTime': isShowTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
final msg2 = {
|
|
||||||
'type': 'text/multipart',
|
|
||||||
'msgId': msgId,
|
|
||||||
'senderId': senderId,
|
|
||||||
'text': text,
|
|
||||||
'attachments': attachments,
|
|
||||||
'dateTime': now.toString(),
|
|
||||||
'isShowTime': isShowTime,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (widget.chatType == 0) {
|
if (widget.chatType == 0) {
|
||||||
msg['event'] = 'friend-chat-msg';
|
msg['event'] = 'friend-chat-msg';
|
||||||
msg['receiverId'] = widget.contactId;
|
msg['receiverId'] = widget.contactId;
|
||||||
msg2['event'] = 'friend-chat-msg';
|
|
||||||
msg2['receiverId'] = getIt.get<UserAccount>().id;
|
|
||||||
// getIt.get<WebSocketManager>().channel.sink.add(json.encode(msg2));
|
|
||||||
getIt.get<WebSocketManager>().channel.sink.add(json.encode(msg));
|
getIt.get<WebSocketManager>().channel.sink.add(json.encode(msg));
|
||||||
if (attachments.isNotEmpty) {
|
if (attachments.isNotEmpty) {
|
||||||
String baseImageDir = getIt.get<UserProfile>().baseImageDir;
|
String baseImageDir = getIt.get<UserProfile>().baseImageDir;
|
||||||
|
@ -305,22 +292,6 @@ class _MessageInputBoxState extends State<MessageInputBox> {
|
||||||
for (final data in encodedDatas) {
|
for (final data in encodedDatas) {
|
||||||
getIt.get<WebSocketManager>().channel.sink.add(data);
|
getIt.get<WebSocketManager>().channel.sink.add(data);
|
||||||
}
|
}
|
||||||
// for (var i = 0; i < attachments.length; i++) {
|
|
||||||
// Uint8List bytes = await _imageFileList[i].readAsBytes();
|
|
||||||
// File file = File('$baseImageDir/${attachments[i]}');
|
|
||||||
// file.createSync(recursive: true);
|
|
||||||
// file.writeAsBytes(bytes);
|
|
||||||
// getIt.get<WebSocketManager>().channel.sink.add(
|
|
||||||
// json.encode(
|
|
||||||
// {
|
|
||||||
// 'event': 'friend-chat-image',
|
|
||||||
// 'receiverId': widget.contactId,
|
|
||||||
// 'filename': attachments[i],
|
|
||||||
// 'bytes': bytes,
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String baseImageDir = getIt.get<UserProfile>().baseImageDir;
|
String baseImageDir = getIt.get<UserProfile>().baseImageDir;
|
||||||
|
@ -332,6 +303,10 @@ class _MessageInputBoxState extends State<MessageInputBox> {
|
||||||
msg['event'] = 'group-chat-msg';
|
msg['event'] = 'group-chat-msg';
|
||||||
msg['groupChatId'] = widget.contactId;
|
msg['groupChatId'] = widget.contactId;
|
||||||
msg['receiverIds'] = receiverIds;
|
msg['receiverIds'] = receiverIds;
|
||||||
|
msg['nickname'] = getIt.get<UserProfile>().nickname;
|
||||||
|
msg['remarkInGroupChat'] =
|
||||||
|
getIt.get<Contact>().groupChats[widget.contactId]!.remarkInGroupChat;
|
||||||
|
msg['avatar'] = getIt.get<UserProfile>().avatar;
|
||||||
getIt.get<WebSocketManager>().channel.sink.add(json.encode(msg));
|
getIt.get<WebSocketManager>().channel.sink.add(json.encode(msg));
|
||||||
if (attachments.isNotEmpty) {
|
if (attachments.isNotEmpty) {
|
||||||
List<String> encodedDatas = await compute(
|
List<String> encodedDatas = await compute(
|
||||||
|
@ -348,24 +323,6 @@ class _MessageInputBoxState extends State<MessageInputBox> {
|
||||||
for (final data in encodedDatas) {
|
for (final data in encodedDatas) {
|
||||||
getIt.get<WebSocketManager>().channel.sink.add(data);
|
getIt.get<WebSocketManager>().channel.sink.add(data);
|
||||||
}
|
}
|
||||||
// String baseImageDir = getIt.get<UserProfile>().baseImageDir;
|
|
||||||
// for (var i = 0; i < attachments.length; i++) {
|
|
||||||
// Uint8List bytes = await _imageFileList[i].readAsBytes();
|
|
||||||
// File file = File('$baseImageDir/${attachments[i]}');
|
|
||||||
// file.createSync(recursive: true);
|
|
||||||
// file.writeAsBytes(bytes);
|
|
||||||
// getIt.get<WebSocketManager>().channel.sink.add(
|
|
||||||
// json.encode(
|
|
||||||
// {
|
|
||||||
// 'event': 'group-chat-image',
|
|
||||||
// 'groupChatId': widget.contactId,
|
|
||||||
// 'receiverIds': receiverIds,
|
|
||||||
// 'filename': attachments[i],
|
|
||||||
// 'bytes': bytes,
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class _GroupChatMessageScreenState extends State<GroupChatMessageScreen> {
|
||||||
title: getIt
|
title: getIt
|
||||||
.get<Contact>()
|
.get<Contact>()
|
||||||
.groupChats[widget.groupChatId]!
|
.groupChats[widget.groupChatId]!
|
||||||
.nameRemark
|
.groupChatRemark
|
||||||
.isEmpty
|
.isEmpty
|
||||||
? Text(
|
? Text(
|
||||||
getIt
|
getIt
|
||||||
|
@ -66,7 +66,10 @@ class _GroupChatMessageScreenState extends State<GroupChatMessageScreen> {
|
||||||
.name,
|
.name,
|
||||||
)
|
)
|
||||||
: Text(
|
: Text(
|
||||||
getIt.get<Contact>().groupChats[widget.groupChatId]!.nameRemark,
|
getIt
|
||||||
|
.get<Contact>()
|
||||||
|
.groupChats[widget.groupChatId]!
|
||||||
|
.groupChatRemark,
|
||||||
),
|
),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
actions: [
|
actions: [
|
||||||
|
|
Loading…
Reference in New Issue