Skip to content

Commit f32f1aa

Browse files
committed
add checking peer user chatting with to avoid unnecessary push notification
1 parent 7acecbc commit f32f1aa

File tree

3 files changed

+61
-62
lines changed

3 files changed

+61
-62
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package="com.dfa.flutterchatdemo">
33

44
<uses-permission android:name="android.permission.INTERNET" />
5+
<uses-permission android:name="android.permission.VIBRATE" />
56

67
<application
78
android:name="io.flutter.app.FlutterApplication"

lib/chat.dart

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class ChatScreenState extends State<ChatScreen> {
9797
groupChatId = '$peerId-$id';
9898
}
9999

100+
Firestore.instance.collection('users').document(id).updateData({'chattingWith': peerId});
101+
100102
setState(() {});
101103
}
102104

@@ -190,31 +192,31 @@ class ChatScreenState extends State<ChatScreen> {
190192
child: Material(
191193
child: CachedNetworkImage(
192194
placeholder: (context, url) => Container(
193-
child: CircularProgressIndicator(
194-
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
195-
),
196-
width: 200.0,
197-
height: 200.0,
198-
padding: EdgeInsets.all(70.0),
199-
decoration: BoxDecoration(
200-
color: greyColor2,
201-
borderRadius: BorderRadius.all(
202-
Radius.circular(8.0),
203-
),
204-
),
195+
child: CircularProgressIndicator(
196+
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
197+
),
198+
width: 200.0,
199+
height: 200.0,
200+
padding: EdgeInsets.all(70.0),
201+
decoration: BoxDecoration(
202+
color: greyColor2,
203+
borderRadius: BorderRadius.all(
204+
Radius.circular(8.0),
205205
),
206+
),
207+
),
206208
errorWidget: (context, url, error) => Material(
207-
child: Image.asset(
208-
'images/img_not_available.jpeg',
209-
width: 200.0,
210-
height: 200.0,
211-
fit: BoxFit.cover,
212-
),
213-
borderRadius: BorderRadius.all(
214-
Radius.circular(8.0),
215-
),
216-
clipBehavior: Clip.hardEdge,
217-
),
209+
child: Image.asset(
210+
'images/img_not_available.jpeg',
211+
width: 200.0,
212+
height: 200.0,
213+
fit: BoxFit.cover,
214+
),
215+
borderRadius: BorderRadius.all(
216+
Radius.circular(8.0),
217+
),
218+
clipBehavior: Clip.hardEdge,
219+
),
218220
imageUrl: document['content'],
219221
width: 200.0,
220222
height: 200.0,
@@ -249,14 +251,14 @@ class ChatScreenState extends State<ChatScreen> {
249251
? Material(
250252
child: CachedNetworkImage(
251253
placeholder: (context, url) => Container(
252-
child: CircularProgressIndicator(
253-
strokeWidth: 1.0,
254-
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
255-
),
256-
width: 35.0,
257-
height: 35.0,
258-
padding: EdgeInsets.all(10.0),
259-
),
254+
child: CircularProgressIndicator(
255+
strokeWidth: 1.0,
256+
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
257+
),
258+
width: 35.0,
259+
height: 35.0,
260+
padding: EdgeInsets.all(10.0),
261+
),
260262
imageUrl: peerAvatar,
261263
width: 35.0,
262264
height: 35.0,
@@ -284,31 +286,31 @@ class ChatScreenState extends State<ChatScreen> {
284286
child: Material(
285287
child: CachedNetworkImage(
286288
placeholder: (context, url) => Container(
287-
child: CircularProgressIndicator(
288-
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
289-
),
290-
width: 200.0,
291-
height: 200.0,
292-
padding: EdgeInsets.all(70.0),
293-
decoration: BoxDecoration(
294-
color: greyColor2,
295-
borderRadius: BorderRadius.all(
296-
Radius.circular(8.0),
297-
),
298-
),
289+
child: CircularProgressIndicator(
290+
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
291+
),
292+
width: 200.0,
293+
height: 200.0,
294+
padding: EdgeInsets.all(70.0),
295+
decoration: BoxDecoration(
296+
color: greyColor2,
297+
borderRadius: BorderRadius.all(
298+
Radius.circular(8.0),
299299
),
300+
),
301+
),
300302
errorWidget: (context, url, error) => Material(
301-
child: Image.asset(
302-
'images/img_not_available.jpeg',
303-
width: 200.0,
304-
height: 200.0,
305-
fit: BoxFit.cover,
306-
),
307-
borderRadius: BorderRadius.all(
308-
Radius.circular(8.0),
309-
),
310-
clipBehavior: Clip.hardEdge,
311-
),
303+
child: Image.asset(
304+
'images/img_not_available.jpeg',
305+
width: 200.0,
306+
height: 200.0,
307+
fit: BoxFit.cover,
308+
),
309+
borderRadius: BorderRadius.all(
310+
Radius.circular(8.0),
311+
),
312+
clipBehavior: Clip.hardEdge,
313+
),
312314
imageUrl: document['content'],
313315
width: 200.0,
314316
height: 200.0,
@@ -372,6 +374,7 @@ class ChatScreenState extends State<ChatScreen> {
372374
isShowSticker = false;
373375
});
374376
} else {
377+
Firestore.instance.collection('users').document(id).updateData({'chattingWith': null});
375378
Navigator.pop(context);
376379
}
377380

lib/login.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class LoginScreenState extends State<LoginScreen> {
9595
'nickname': firebaseUser.displayName,
9696
'photoUrl': firebaseUser.photoUrl,
9797
'id': firebaseUser.uid,
98-
'createdAt': DateTime.now().millisecondsSinceEpoch.toString()
98+
'createdAt': DateTime.now().millisecondsSinceEpoch.toString(),
99+
'chattingWith': null
99100
});
100101

101102
// Write data to local
@@ -115,13 +116,7 @@ class LoginScreenState extends State<LoginScreen> {
115116
isLoading = false;
116117
});
117118

118-
Navigator.push(
119-
context,
120-
MaterialPageRoute(
121-
builder: (context) => MainScreen(
122-
currentUserId: firebaseUser.uid,
123-
)),
124-
);
119+
Navigator.push(context, MaterialPageRoute(builder: (context) => MainScreen(currentUserId: firebaseUser.uid)));
125120
} else {
126121
Fluttertoast.showToast(msg: "Sign in fail");
127122
this.setState(() {

0 commit comments

Comments
 (0)