Skip to content

Commit 03641fe

Browse files
committed
🗃Update notification , following and followers db schema.
1.🗃Change in db schema. 2.:children_crossing: Last notificaiton on top implementation. #26
1 parent e9dd955 commit 03641fe

File tree

9 files changed

+148
-182
lines changed

9 files changed

+148
-182
lines changed

lib/helper/enum.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ enum NotificationType{
2525
Reply,
2626
Retweet,
2727
Follow,
28-
Mention
28+
Mention,
29+
Like
2930
}

lib/model/feedModel.dart

Lines changed: 79 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import 'package:flutter_twitter_clone/model/user.dart';
32

43
class FeedModel {
@@ -8,140 +7,104 @@ class FeedModel {
87
String description;
98
String userId;
109
int likeCount;
11-
List<LikeList> likeList;
10+
List<String> likeList;
1211
int commentCount;
1312
int retweetCount;
1413
String createdAt;
1514
String imagePath;
1615
List<String> tags;
1716
List<String> replyTweetKeyList;
1817
User user;
19-
FeedModel({
20-
this.key,
21-
this.description,
22-
this.userId,
23-
this.likeCount,
24-
this.commentCount,
25-
this.retweetCount,
26-
this.createdAt,
27-
this.imagePath,
28-
this.likeList,
29-
this.tags,
30-
this.user,
31-
this.replyTweetKeyList,
32-
this.parentkey,
33-
this.childRetwetkey
34-
});
18+
FeedModel(
19+
{this.key,
20+
this.description,
21+
this.userId,
22+
this.likeCount,
23+
this.commentCount,
24+
this.retweetCount,
25+
this.createdAt,
26+
this.imagePath,
27+
this.likeList,
28+
this.tags,
29+
this.user,
30+
this.replyTweetKeyList,
31+
this.parentkey,
32+
this.childRetwetkey});
3533
toJson() {
36-
Map<dynamic,dynamic> map;
37-
if(likeList != null && likeList.length > 0){
38-
map = Map.fromIterable(likeList, key: (v) =>v.key, value: (v){
39-
var list = LikeList(key: v.key, userId: v.userId);
40-
return list.toJson();
41-
});
42-
}
4334
return {
4435
"userId": userId,
4536
"description": description,
46-
"likeCount":likeCount,
47-
"commentCount":commentCount ?? 0,
37+
"likeCount": likeCount,
38+
"commentCount": commentCount ?? 0,
4839
"retweetCount": retweetCount ?? 0,
49-
"createdAt":createdAt,
50-
"imagePath":imagePath,
51-
"likeList":map,
52-
"tags":tags,
53-
"replyTweetKeyList":replyTweetKeyList,
54-
"user":user == null ? null : user.toJson(),
40+
"createdAt": createdAt,
41+
"imagePath": imagePath,
42+
"likeList": likeList,
43+
"tags": tags,
44+
"replyTweetKeyList": replyTweetKeyList,
45+
"user": user == null ? null : user.toJson(),
5546
"parentkey": parentkey,
56-
"childRetwetkey":childRetwetkey
47+
"childRetwetkey": childRetwetkey
5748
};
5849
}
59-
dynamic getLikeList(List<String> list){
60-
if(list != null && list.length > 0){
61-
var result = Map.fromIterable(list, key: (v) =>'userId', value: (v) => v[0]);
62-
return result;
63-
}
64-
}
50+
6551
FeedModel.fromJson(Map<dynamic, dynamic> map) {
66-
if(likeList == null){
52+
key = map['key'];
53+
description = map['description'];
54+
userId = map['userId'];
55+
// name = map['name'];
56+
// profilePic = map['profilePic'];
57+
likeCount = map['likeCount'];
58+
commentCount = map['commentCount'];
59+
retweetCount = map["retweetCount"] ?? 0;
60+
imagePath = map['imagePath'];
61+
createdAt = map['createdAt'];
62+
imagePath = map['imagePath'];
63+
// username = map['username'];
64+
user = User.fromJson(map['user']);
65+
parentkey = map['parentkey'];
66+
childRetwetkey = map['childRetwetkey'];
67+
if (map['tags'] != null) {
68+
tags = List<String>();
69+
map['tags'].forEach((value) {
70+
tags.add(value);
71+
});
72+
}
73+
if (map["likeList"] != null) {
74+
likeList = List<String>();
75+
map['likeList'].forEach((value) {
76+
likeList.add(value);
77+
});
78+
likeCount = likeList.length;
79+
} else {
6780
likeList = [];
81+
likeCount = 0;
82+
}
83+
if (map['replyTweetKeyList'] != null) {
84+
map['replyTweetKeyList'].forEach((value) {
85+
replyTweetKeyList = List<String>();
86+
map['replyTweetKeyList'].forEach((value) {
87+
replyTweetKeyList.add(value);
88+
});
89+
});
90+
commentCount = replyTweetKeyList.length;
91+
} else {
92+
replyTweetKeyList = [];
93+
commentCount = 0;
6894
}
69-
key = map['key'];
70-
description = map['description'];
71-
userId = map['userId'];
72-
// name = map['name'];
73-
// profilePic = map['profilePic'];
74-
likeCount = map['likeCount'];
75-
commentCount = map['commentCount'];
76-
retweetCount = map["retweetCount"] ?? 0;
77-
imagePath = map['imagePath'];
78-
createdAt = map['createdAt'];
79-
imagePath = map['imagePath'];
80-
// username = map['username'];
81-
user = User.fromJson(map['user']);
82-
parentkey = map['parentkey'];
83-
childRetwetkey = map['childRetwetkey'];
84-
if(map['tags'] != null){
85-
tags = List<String>();
86-
map['tags'].forEach((value){
87-
tags.add(value);
88-
});
89-
}
90-
if(map['likeList'] != null){
91-
map['likeList'].forEach((key,value){
92-
if(value.containsKey('userId')){
93-
LikeList list = LikeList(key:key,userId: value['userId']);
94-
likeList.add(list);
95-
}
96-
});
97-
likeCount = likeList.length;
98-
}
99-
else{
100-
likeList = [];
101-
likeCount = 0;
102-
}
103-
if(map['replyTweetKeyList'] != null){
104-
map['replyTweetKeyList'].forEach((value){
105-
replyTweetKeyList = List<String>();
106-
map['replyTweetKeyList'].forEach((value){
107-
replyTweetKeyList.add(value);
108-
});
109-
});
110-
commentCount = replyTweetKeyList.length;
111-
}
112-
else{
113-
replyTweetKeyList = [];
114-
commentCount = 0;
115-
}
11695
}
11796

118-
bool get isValidTweet {
119-
bool isValid =false;
120-
if(description != null
121-
&& description.isNotEmpty
122-
&& this.user != null
123-
&& this.user.userName != null
124-
&& this.user.userName.isNotEmpty
125-
){
126-
isValid = true;
127-
}
128-
else{
129-
print("Invalid Tweet found. Id:- $key");
130-
}
131-
return isValid;
132-
}
133-
}
134-
class LikeList{
135-
String key;
136-
String userId;
137-
LikeList({this.key,this.userId});
138-
LikeList.fromJson(Map<dynamic, dynamic> map,{String key}) {
139-
key = key;
140-
userId = map['userId'];
141-
}
142-
toJson(){
143-
return {
144-
'userId':userId
145-
};
97+
bool get isValidTweet {
98+
bool isValid = false;
99+
if (description != null &&
100+
description.isNotEmpty &&
101+
this.user != null &&
102+
this.user.userName != null &&
103+
this.user.userName.isNotEmpty) {
104+
isValid = true;
105+
} else {
106+
print("Invalid Tweet found. Id:- $key");
107+
}
108+
return isValid;
146109
}
147110
}

lib/model/notificationModel.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
class NotificationModel {
22
String tweetKey;
3+
String updatedAt;
4+
String type;
35

46
NotificationModel({
57
this.tweetKey,
68
});
79

8-
NotificationModel.fromJson(String tweetId) {
10+
NotificationModel.fromJson(String tweetId, String updatedAt,String type) {
911
tweetKey = tweetId;
12+
this.updatedAt = updatedAt;
13+
this.type = type;
1014
}
1115

1216
Map<String, dynamic> toJson() => {

lib/model/user.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class User {
9090
'location': location,
9191
'createdAt': createdAt,
9292
'followers': followersList != null ? followersList.length : null,
93-
'following': followersList!= null ? followersList.length : null,
93+
'following': followingList!= null ? followingList.length : null,
9494
'userName': userName,
9595
'webSite': webSite,
9696
'isVerified': isVerified ?? false,

lib/page/notification/notificationPage.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class NotificationPageBody extends StatelessWidget {
113113
class NotificationTile extends StatelessWidget {
114114
final FeedModel model;
115115
const NotificationTile({Key key, this.model}) : super(key: key);
116-
Widget _userList(BuildContext context, List<LikeList> list) {
116+
Widget _userList(BuildContext context, List<String> list) {
117117
// List<String> names = [];
118118
var length = list.length;
119119
List<Widget> avaterList = [];
@@ -122,8 +122,8 @@ class NotificationTile extends StatelessWidget {
122122
if (list != null && list.length > 5) {
123123
list = list.take(5).toList();
124124
}
125-
avaterList = list.map((x) {
126-
return _userAvater(x.userId, state, (name) {
125+
avaterList = list.map((userId) {
126+
return _userAvater(userId, state, (name) {
127127
// names.add(name);
128128
});
129129
}).toList();

lib/state/authState.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,16 @@ class AuthState extends AppState {
436436
profileUserModel.followers = profileUserModel.followersList.length;
437437
// update logged-in user's following count
438438
userModel.following = userModel.followingList.length;
439-
440439
kDatabase
441440
.child('profile')
442441
.child(profileUserModel.userId)
443-
.set(profileUserModel.toJson());
442+
.child('followerList')
443+
.set(profileUserModel.followersList);
444444
kDatabase
445445
.child('profile')
446446
.child(userModel.userId)
447-
.set(userModel.toJson());
447+
.child('followingList')
448+
.set(userModel.followingList);
448449
cprint('user added to following list', event: 'add_follow');
449450
notifyListeners();
450451
} catch (error) {

0 commit comments

Comments
 (0)