fetchstory method
dynamic
fetchstory(
{ - bool refreshStroy = false,
})
Implementation
fetchstory({bool refreshStroy = false}) async {
if (storyproccess.value) {
return;
}
storyproccess.value = true;
StoryFetchListResponse response =
await service.storyServices.stories(page: 1);
if (!response.result.status) {
Future.delayed(const Duration(seconds: 1), () {
storyproccess.value = false;
fetchstory();
});
return;
}
storyList.value ??= [];
filteredStoryList.value ??= [];
if (refreshStroy) {
storyList.value = [];
}
// Eğer hiç paylaşım yoksa ve bellekteki paylaşımlar da boşsa, varsayılan bir paylaşım ekle
if (!storyList.value!
.any((story) => story.owner.userID == currentUser!.userID)) {
storyList.value!.add(
StoryList(
owner: User(
userID: currentUser!.userID,
userName: (SocialKeys.socialStory.tr).obs,
avatar: currentUser!.avatar,
),
story: null,
isView: true,
),
);
}
for (APIStoryList element in response.response!) {
if (!storyList.value!
.any((story) => story.owner.userID == element.oyuncuId)) {
storyList.value!.add(
StoryList(
owner: User(
userID: element.oyuncuId,
userName: Rx(element.oyuncuKadi),
displayName: Rx(element.oyuncuAdSoyad),
avatar: Media(
mediaID: 0,
mediaType: MediaType.image,
mediaURL: MediaURL(
bigURL: Rx(element.oyuncuAvatar.bigURL),
normalURL: Rx(element.oyuncuAvatar.normalURL),
minURL: Rx(
element.oyuncuAvatar.minURL,
),
),
),
),
story: element.hikayeIcerik
.map(
(e) => Story(
storyID: e.hikayeId,
ownerID: e.hikayeSahip,
ownerusername: element.oyuncuKadi,
owneravatar: element.oyuncuAvatar.minURL,
time: e.hikayeZaman,
media: e.hikayeMedya,
isLike: e.hikayeBenBegeni,
isView: e.hikayeBenGoruntulenme,
),
)
.toList(),
isView: false,
),
);
} else {
// Eğer paylaşım zaten varsa, güncelle
storyList.value!.firstWhere((story) => story.owner.userID == currentUser!.userID).story =
element.hikayeIcerik
.map(
(e) => Story(
storyID: e.hikayeId,
ownerID: e.hikayeSahip,
ownerusername: element.oyuncuKadi,
owneravatar: element.oyuncuAvatar.minURL,
time: e.hikayeZaman,
media: e.hikayeMedya,
isLike: e.hikayeBenBegeni,
isView: e.hikayeBenGoruntulenme,
),
)
.toList();
}
}
storyproccess.value = false;
updateStoryList();
if (response.response!.length < 30) {
// 10'dan azsa daha fazla yok demektir
storyEndproccess.value = true;
log("Daha fazla veri yok (StoryList)");
}
}