Skip to content
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

Open
hoppula opened this issue Dec 6, 2016 · 3 comments
Open
Labels

Comments

@hoppula
Copy link
Owner

hoppula commented Dec 6, 2016

Thread timestamp isn't updated now when last post gets deleted.

@hoppula hoppula added the bug label Dec 6, 2016
@tograd
Copy link

tograd commented Mar 26, 2017

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});
      });
    }
  });
});

@hoppula
Copy link
Owner Author

hoppula commented Mar 27, 2017

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 threads/${threadKey}/posts and fetch corresponding posts from posts/${postKey} and from that collection find the maximum value for createdAt field and set that as new value for threads/${threadKey}/lastPostAt.

This also needs to run in a separate transaction after the post deletion is complete. deletePost in src/updates.js also needs some extra logic to only run this extra step if last post in the thread is deleted.

@tograd
Copy link

tograd commented Mar 27, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants