Rank 1: Thread
hii
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 1: Thread
hii
Rank 1: Thread
it's me again
Rank 1: Thread
i started taking a look at function but i was wondering if this would work for separate user, supposing the user send an http post/get request at the function this would work for separate user or the same function would work for all the user
Rank 1: Thread
because i want this to be subjective for each user
no need to tag the entire company 🙂 We always see your messages here without being tagged 🤗 btw that is amazing you are starting developing early on, you will be very successful because of this :Fire6_Orange:
@D5 thank you for helping this person 🙂
In your case - as D5 suggested - you should use server-side code in an Appwrite Function to correctly send alerts to the users.
If you are storing the last time at which the user pressed the button in a document inside a database, what you can do is this:
Whenever the user starts the app, run a databases.getDocument call from your app and check if the time stored in the document is more than 24 hours ago. Something like this:
Future result = await databases.getDocument( databaseId: '[DATABASE_ID]', collectionId: '[COLLECTION_ID]', documentId: '[DOCUMENT_ID]',);
final lastUserTime = result.timeByUser; // timeByUser is the name of the attribute in the database's collection that holds the actual time
bool isMoreThan24HoursAgo(String isoTime) { DateTime dateTimeA = DateTime.parse(isoTime).toUtc(); DateTime currentDateTime = DateTime.now().toUtc();
Duration difference = currentDateTime.difference(dateTimeA);
return difference.inHours > 24;}This will return true if more than 24 hours have passed, and false if less than 24 hours have passed.
If the value returned by the isMoreThan24HoursAgo function is true, you can show the button.
Rank 1: Thread
@Tessa sorry for the tags and thank you for the support
Rank 1: Thread
is this gonna work if the client move the time on his phone ?
Moderator
Phone time will not affect
Moderator
Because this is done server sided
Moderator
Phone = client side
Appwrite = server side
Rank 1: Thread
but this line of code takes the date from the client side?
DateTime currentDateTime = DateTime.now().toUtc();
Moderator
When you click the button, you create a new database record or update existing. Database API or function will record existing creation/modification time from server side
Rank 1: Thread
i get it
Rank 1: Thread
thank you
Rank 1: Thread
hi, it's me again, do you guys think i can implement this logic to make a different "Cooldown" for every user?
in the code below if the parameter UserID (wich i've taken and stored in a variable) is not found on the collection of the database that contains the UserID and the timeByUser, he'll create a new one, otherwhise i will update the exsisting one.
i'm also not sure this is the best practice to do this, but i think can be work good right?
(edit: iv've inplemented this today and when the user clicks the button it checks if there is the UserID already in the document otherwhise he will create a new document with that specific user id, also the GetUserID() is a function to get the id of the user in the current session)
void getuser() async {
try {
final userId = await GetUserID();
Future<bool> userExist() async {
try {
final response = await databases.listDocuments(
databaseId: '651b24f731b2855ab92d',
collectionId: '651b253f714e3fb0c8a7',
queries: [Query.equal('UserID', userId)],
);
// Verifica se ci sono documenti nel risultato
return response.documents.isNotEmpty;
} catch (e) {
print(e.toString());
return false;
}
}
if (await userExist()) {
print('UserID already exists in the collection');
} else {
await databases.createDocument(
databaseId: '651b24f731b2855ab92d',
collectionId: '651b253f714e3fb0c8a7',
documentId: ID.unique(),
data: {
'UserID': userId,
'timeByUser': 'not_setted_yet',
},
);
print("Document created");
}
} catch (e) {
print(e.toString());
}
}
This code seems to the job of checking if user exists, and then either creating/updating document correctly
Is there anything else you want to do?
Rank 1: Thread
not at the moment
Rank 1: Thread
thank you for checking
If you have no more issues, I'll be marking this question as SOLVED.
Feel free to make a new post for any other issue you face 
Rank 1: Thread
okk
Rank 1: Thread
thank you
Rank 1: Thread
you guys are awesome !
[SOLVED] Button Clickable every 24h