Skip to content

Commit

Permalink
v1.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohit090301 committed Sep 5, 2021
1 parent 3eff987 commit 746eaa5
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 50 deletions.
12 changes: 10 additions & 2 deletions lib/services/database.dart
Expand Up @@ -202,6 +202,16 @@ class DataBaseMethods {
.update(chatRoomMap);
}

updateGroupChatRoom(String groupId, groupChatRoomMap) async {
await FirebaseFirestore.instance
.collection('groups').where("groupId", isEqualTo: groupId).get().then((value){
value.docs.forEach((element) async{
print(element.id);
await FirebaseFirestore.instance.collection('groups').doc(element.id).update(groupChatRoomMap);
});
});
}

getLastMessageSeen() async {
await FirebaseFirestore.instance.collection("ChatRoom").snapshots();
}
Expand All @@ -222,8 +232,6 @@ class DataBaseMethods {
} else {
urls[1] = url;
}
String n1 = Constants.myName + "height";
String n2 = Constants.myName + "width";
FirebaseFirestore.instance
.collection('ChatRoom')
.doc(element.id)
Expand Down
143 changes: 111 additions & 32 deletions lib/views/chatRoomsScreen.dart
Expand Up @@ -147,15 +147,21 @@ class _ChatRoomState extends State<ChatRoom>
itemBuilder: (context, index) {
print(snapshot.data.docs[index].data()["users"]);
return GroupTile(
groupName: snapshot.data.docs[index].data()["groupName"],
groupPicUrl:
snapshot.data.docs[index].data()["groupPicUrl"],
isWhite: isWhite,
groupId: snapshot.data.docs[index].data()["groupId"],
blackbg: blackbg,
whitebg: whitebg,
receivedBy: snapshot.data.docs[index].data()["users"],
);
groupName: snapshot.data.docs[index].data()["groupName"],
groupPicUrl:
snapshot.data.docs[index].data()["groupPicUrl"],
isWhite: isWhite,
groupId: snapshot.data.docs[index].data()["groupId"],
blackbg: blackbg,
whitebg: whitebg,
receivedBy: snapshot.data.docs[index].data()["users"],
isSoundEnabled: isSoundEnabled,
lastMsg: snapshot.data.docs[index].data()["lastMsg"],
lastMsgSendBy: snapshot.data.docs[index].data()["SendBy"],
lastMsgTime:
snapshot.data.docs[index].data()["lastMsgTime"],
lastMsgTimeStamp:
snapshot.data.docs[index].data()["lastMsgTimeStamp"]);
})
: Container();
},
Expand Down Expand Up @@ -272,7 +278,7 @@ class _ChatRoomState extends State<ChatRoom>
isSoundEnabled: isSoundEnabled,
))).then((value) {
if (mounted) {
print(isSoundEnabled.toString() + " sound");
print(isSoundEnabled.toString() + " sound");
setState(() {
isWhite = value[0];
whitebg = value[1] == "" ? whitebg : value[1];
Expand Down Expand Up @@ -304,7 +310,7 @@ class _ChatRoomState extends State<ChatRoom>
child: Container(
padding: EdgeInsets.symmetric(horizontal: 5),
child: Icon(
Icons.search,
Icons.search,
semanticLabel: "Search",
),
),
Expand All @@ -322,10 +328,9 @@ class _ChatRoomState extends State<ChatRoom>
child: Container(
padding: EdgeInsets.fromLTRB(0, 0, 12, 0),
child: Icon(
Icons.person_rounded,
Icons.person_rounded,
semanticLabel: "Profile",
)
),
)),
),
],
bottom: TabBar(
Expand Down Expand Up @@ -581,17 +586,18 @@ class _ChatRoomsTileState extends State<ChatRoomsTile> {
context,
MaterialPageRoute(
builder: (context) => ConversationScreen(
username: widget.username,
chatRoomId: widget.chatRoom,
imageUrl: widget.url,
mailid: widget.email,
isLastMsgSeen: widget.isSeen,
isWhite: widget.isWhite,
myUrl: widget.myUrl,
whitebg: widget.whitebg,
blackbg: widget.blackbg,
isSoundEnabled: widget.isSoundEnabled
))).then((value) async {
username: widget.username,
chatRoomId: widget.chatRoom,
imageUrl: widget.url,
mailid: widget.email,
isLastMsgSeen: widget.isSeen,
isWhite: widget.isWhite,
myUrl: widget.myUrl,
whitebg: widget.whitebg,
blackbg: widget.blackbg,
isSoundEnabled:
widget.isSoundEnabled))).then(
(value) async {
await dataBaseMethods
.getUserStatus(widget.username)
.then((val) {
Expand Down Expand Up @@ -744,6 +750,11 @@ class GroupTile extends StatefulWidget {
String blackbg;
String whitebg;
List<dynamic> receivedBy;
bool isSoundEnabled;
String lastMsg;
String lastMsgSendBy;
String lastMsgTime;
int lastMsgTimeStamp;

GroupTile(
{this.groupName,
Expand All @@ -752,7 +763,12 @@ class GroupTile extends StatefulWidget {
this.groupId,
this.whitebg,
this.blackbg,
this.receivedBy});
this.receivedBy,
this.isSoundEnabled,
this.lastMsg,
this.lastMsgTime,
this.lastMsgSendBy,
this.lastMsgTimeStamp});

@override
_GroupTileState createState() => _GroupTileState();
Expand All @@ -761,7 +777,29 @@ class GroupTile extends StatefulWidget {
class _GroupTileState extends State<GroupTile> {
@override
Widget build(BuildContext context) {
print("hi");
double width = MediaQuery.of(context).size.width - 50;

var lasMsgDate;
if (widget.lastMsgTimeStamp == null)
widget.lastMsgTimeStamp = 1630858069469;
lasMsgDate = DateTime.fromMillisecondsSinceEpoch(widget.lastMsgTimeStamp);
print("hi");
int diff = DateTime.now().difference(lasMsgDate).inDays;
print("hi");
String todaysDate = DateTimeFormat.format(DateTime.now())
.toString()
.substring(0, 10)
.split('-')
.reversed
.join('-');
String lmd =
lasMsgDate.toString().substring(0, 10).split('-').reversed.join('-');
if (diff == 1) diff = 2;
if (lmd == todaysDate) diff = 0;
if (diff == 0 && lmd != todaysDate) diff = 1;
print(widget.groupName);
print(width);
return Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Row(
Expand Down Expand Up @@ -825,6 +863,7 @@ class _GroupTileState extends State<GroupTile> {
whitebg: widget.whitebg,
isWhite: widget.isWhite,
receivedBy: widget.receivedBy,
isSoundEnabled: widget.isSoundEnabled,
)));
},
child: Container(
Expand All @@ -834,14 +873,54 @@ class _GroupTileState extends State<GroupTile> {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: width * 0.62,
child: Text(
widget.groupName,
style: TextStyle(
color:
widget.isWhite ? Colors.black87 : Colors.white,
fontSize: 19,
//fontWeight: FontWeight.w600
),
),
),
Container(
width: width * 0.29,
child: Text(
widget.lastMsgTime != null
? diff == 0
? widget.lastMsgTime
: diff == 1
? "Yesterday"
: lasMsgDate.format("d/m/y")
: "",
style: TextStyle(
fontSize: 12,
color:
widget.isWhite ? Colors.grey[700] : Colors.grey,
),
textAlign: TextAlign.end,
),
)
],
),
SizedBox(
height: 2,
),
Text(
widget.groupName,
widget.lastMsg == null
? "Null"
: widget.lastMsgSendBy == Constants.myName
? "Me: " + widget.lastMsg
: widget.lastMsgSendBy + ": " + widget.lastMsg,
style: TextStyle(
color: widget.isWhite ? Colors.black87 : Colors.white,
fontSize: 19,
//fontWeight: FontWeight.w600
),
),
color: Colors.grey,
fontSize: 14,
fontWeight: FontWeight.w400),
)
],
),
),
Expand Down
58 changes: 47 additions & 11 deletions lib/views/groupChatScreen.dart
Expand Up @@ -12,9 +12,11 @@ import 'package:flutter_chat_app/views/show_image.dart';
import 'package:image_picker/image_picker.dart';
import 'package:intl/intl.dart';
import 'dart:io';

import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:url_launcher/url_launcher.dart';

IconData currentIcon = Icons.access_time_rounded;

class GroupChatScreen extends StatefulWidget {
final String groupId;
final String whitebg;
Expand All @@ -23,6 +25,7 @@ class GroupChatScreen extends StatefulWidget {
String groupPicUrl;
final bool isWhite;
final List<dynamic> receivedBy;
bool isSoundEnabled;

GroupChatScreen(
{this.groupId,
Expand All @@ -31,7 +34,8 @@ class GroupChatScreen extends StatefulWidget {
this.blackbg,
this.whitebg,
this.groupPicUrl,
this.receivedBy});
this.receivedBy,
this.isSoundEnabled});

@override
_GroupChatScreenState createState() => _GroupChatScreenState();
Expand Down Expand Up @@ -117,10 +121,16 @@ class _GroupChatScreenState extends State<GroupChatScreen> {

@override
sendMessage() async {
print("send messsage called");
List<String> receivedBy;

if (messageController.text.isNotEmpty) {
setState(() {
currentIcon = Icons.access_time_rounded;
});
if (widget.isSoundEnabled) {
await AssetsAudioPlayer.playAndForget(
Audio('assets/msg_sent_sound2.aac', playSpeed: 1.9),
volume: 1,
seek: Duration(seconds: 0));
}
int timeStamp = DateTime.now().millisecondsSinceEpoch;
Map<String, dynamic> messageMap = {
"message": messageController.text,
Expand All @@ -131,9 +141,21 @@ class _GroupChatScreenState extends State<GroupChatScreen> {
"msgDate": DateTimeFormat.format(dateTime),
"groupName": widget.groupName
};

messageController.text = "";
Map<String, dynamic> groupChatRoomMap = {
"lastMsgTimeStamp": timeStamp,
"lastMsgTime": DateFormat.jm().format(DateTime.now()).toString(),
"lastMsg": messageController.text,
"SendBy": Constants.myName,
"isImage": false,
"isVideo": false,
};
messageController.clear();
await dataBaseMethods.addGroupMessages(widget.groupId, messageMap);
await dataBaseMethods.updateGroupChatRoom(widget.groupId, groupChatRoomMap);
//await Future.delayed(Duration(seconds: 1));
setState(() {
currentIcon = CupertinoIcons.eye_fill;
});
}
}

Expand Down Expand Up @@ -203,9 +225,9 @@ class _GroupChatScreenState extends State<GroupChatScreen> {
chatMessageStream = value;
});
});
for(dynamic s in widget.receivedBy){
for (dynamic s in widget.receivedBy) {
int pos = 0;
if(s!=Constants.myName) {
if (s != Constants.myName) {
receivedByCopy.insert(pos, s);
pos++;
}
Expand Down Expand Up @@ -270,6 +292,14 @@ class _GroupChatScreenState extends State<GroupChatScreen> {
SizedBox(
height: 1,
),
Text(
"Tap for group info",
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w300
),
)
],
),
),
Expand Down Expand Up @@ -452,6 +482,7 @@ class MessageTile extends StatefulWidget {
this.sendBy,
this.receivedBy}) {
print("Message Tile called");
print(lastMsg);
if (compare != null && compare != "") {
compare = compare.substring(0, 10);
compare = compare.split('-').reversed.join('-');
Expand Down Expand Up @@ -730,8 +761,7 @@ class _MessageTileState extends State<MessageTile> {
builder: (context, snapshot) {
if (!widget.isLastMessageSeen) findSeen();
return Container(
width:
widget.message == widget.lastMsg ? 57 : 57,
width: 75,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expand All @@ -748,6 +778,12 @@ class _MessageTileState extends State<MessageTile> {
SizedBox(
width: 3,
),
Icon(
currentIcon,
size: widget.message == widget.lastMsg
? 13
: 0,
)
],
),
);
Expand Down

0 comments on commit 746eaa5

Please sign in to comment.