hii
it's me again
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
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.
@Tessa sorry for the tags and thank you for the support
is this gonna work if the client move the time on his phone ?
Phone time will not affect
Because this is done server sided
Phone = client side Appwrite = server side
but this line of code takes the date from the client side?
DateTime currentDateTime = DateTime.now().toUtc();
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
i get it
thank you
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?
not at the moment
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 <:appwritepeepo:1156975874852270110>
okk
thank you
you guys are awesome !
[SOLVED] Button Clickable every 24h
Recommended threads
- Error: User (role: guests) missing scope...
I want to send a verification code to the user and the given phone number and check it and create a session right after the user entered the secret. For me that...
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...