fetchsocailposts method
Future<void>
fetchsocailposts(
{ - bool refreshPost = false,
})
Implementation
Future<void> fetchsocailposts({bool refreshPost = false}) async {
if (postsProccess.value) {
return;
}
postsProccess.value = true;
if (refreshPost) {
postscount.value = 1;
postsList.value = null;
}
PostFetchListResponse response = await service.postsServices.getPosts(
userID: userID,
username: username,
category: category,
page: postscount.value,
);
if (!response.result.status) {
postsProccess.value = false;
return;
}
postsList.value ??= [];
//Eğer en baştan veriler çekiliyorsa listeyi sıfıla
if (postscount.value == 1) {
postsList.value = [];
}
for (APIPostList element in response.response!) {
postsList.value!.add(
Post(
postID: element.postID,
content: element.content,
postDate: element.date,
postDateCountdown: element.datecounting,
sharedDevice: element.postdevice,
likesCount: element.likeCount,
isLikeme: element.didilikeit == 1 ? true : false,
commentsCount: element.commentCount,
iscommentMe: element.didicommentit == 1 ? true : false,
owner: User(
userID: element.postOwner.ownerID,
userName: Rx(element.postOwner.username),
displayName: Rx(element.postOwner.displayName),
avatar: Media(
mediaID: 0,
mediaType: MediaType.image,
mediaURL: MediaURL(
bigURL: Rx(element.postOwner.avatar.bigURL),
normalURL: Rx(element.postOwner.avatar.normalURL),
minURL: Rx(element.postOwner.avatar.minURL),
),
),
),
media: element.media == null
? []
: element.media!
.map(
(media) => Media(
mediaID: media.mediaID,
ownerID: media.owner!.userID,
owneravatar: media.owner!.avatar.minURL,
ownerusername: media.owner!.displayname,
mediaType: media.mediaType!.split("/")[0] == "video"
? MediaType.video
: MediaType.image,
mediaDirection: media.mediaDirection,
mediaTime: media.mediaTime,
mediaURL: MediaURL(
bigURL: Rx(media.mediaURL.bigURL),
normalURL: Rx(media.mediaURL.normalURL),
minURL: Rx(media.mediaURL.minURL),
),
),
)
.toList(),
firstthreecomment: element.firstcomments
?.map(
(comments) => Comment(
commentID: comments.commentID,
postID: comments.postID,
user: User(
userID: comments.postcommenter.userID,
userName: Rx(comments.postcommenter.username),
displayName: Rx(comments.postcommenter.displayname),
avatar: Media(
mediaID: 0,
mediaType: MediaType.image,
mediaURL: MediaURL(
bigURL: Rx(comments.postcommenter.avatar.bigURL),
normalURL: Rx(comments.postcommenter.avatar.normalURL),
minURL: Rx(comments.postcommenter.avatar.minURL),
),
),
),
content: comments.commentContent,
likeCount: comments.likeCount,
didIlike: comments.isLikedByMe,
date: comments.commentTime,
),
)
.toList(),
firstthreelike: element.firstlikers
?.map(
(likers) => Like(
likeID: likers.likerID,
user: User(
userID: likers.likerID,
userName: Rx(likers.likerusername),
displayName: Rx(likers.likerdisplayname),
avatar: Media(
mediaID: 0,
mediaType: MediaType.image,
mediaURL: MediaURL(
bigURL: Rx(likers.likeravatar.bigURL),
normalURL: Rx(likers.likeravatar.normalURL),
minURL: Rx(likers.likeravatar.minURL),
),
),
),
date: likers.likedate,
),
)
.toList(),
location: element.location,
),
);
}
postsList.refresh();
//Verileri Belleğe Aktar
cachedpostsList = postsList.value;
updatePostsList();
postscount.value++;
postsProccess.value = false;
return;
}