“Like” a post in ruby?


(Joe Seyfried) #1

Hey all,

I’d like to add some functionality to my phpBB importer - one of my modifications in my original forum was a “user thank you” mod and I’d like to transfer the data from this mod to Discourse “likes”. For this, I’d need a ruby method that takes a user (ID), a post ID and adds a like for that post from the specified user. The only thing I came across is update_like_count() - but I’m not really sure this is the right method since I couldn’t find any invocation of that method? Also, this does not seem to update the post data, but only user statistics?

TIA,
Joe


(Neil Lalonde) #2

You can create a PostAction like this:

PostAction.act(user, post, PostActionType.types[:like])

The act method will update all the counts and other models.


(Joe Seyfried) #3

Cool, I’ll go from there. I guess this is not really material of general interest, since there are gazillions of phpBB mods out there, so there should be no point in integrating this with the standard importer? If anyone’s interested, they can still contact me directly…


(Kane York) #4

Eh, just put it behind a feature flag in the config section. HAVE_MOD_USER_LIKES = false.


(Joe Seyfried) #5

You think there’s more people that would want this feature?

The current code would even be so robust to ditch the import if it doesn’t find the corresponding table - but I’m not sure if the code I wrote is ready to be published… Let me see if I can package this into something I can ship after I am finished with all the other specialities of my forum.