-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set thread timestamp to new last post date when deleting last post #13
Comments
Did you ever figure out a way to handle this? feels like you'd need to do multiple requests where you check if it was the last post, what the new last post and populate lastPost again.. either with client or the new cloud functions. either way it's gonna cost got better idea? let _domain = this.domain;
let _subforum = this.subforumId;
let _thread = this.threadIdSansSlug;
let _post = this._lastPostId;
firebase.database().ref(`/forum/${_domain}/posts/${_subforum}/${_thread}/${_post}`).set(null).then(() => {
firebase.database().ref(`/forum/${_domain}/threads/${_subforum}/${_thread}/mostRecentPost/post`).once('value', (snapshot) => {
if(snapshot.val() == _post) {
firebase.database().ref(`/forum/${_domain}/posts/${_subforum}/${_thread}`).orderByChild('created').limitToLast(1).once('value', (_snapshot) => {
let newRecentPostId = Object.keys(_snapshot.val())[0]
let newRecentTimestamp = _snapshot.val()[newRecentPostId].created;
firebase.database().ref(`/forum/${_domain}/threads/${_subforum}/${_thread}/mostRecentPost`).set({created: newRecentTimestamp, post: newRecentPostId});
});
}
});
}); |
I haven't looked into this yet. I just glanced the code again for the first time in a while and I think you'd first need to get all the post keys under This also needs to run in a separate transaction after the post deletion is complete. |
Looks like what I figured as well. I've had second-thoughts though for my own project. I'm leaning towards making a github-like forum instead where threads simply are listed by creation timestamp and then people will have to use search and subscribe/@tag system to be reminded of relevant topics. Think it may fit better with firebase. Plus it's more of a utility board than a social forum anyway. Cheers |
Thread timestamp isn't updated now when last post gets deleted.
The text was updated successfully, but these errors were encountered: