The discussion revolves around a novice Discourse developer, tarek, attempting to develop a patch to allow for certain added functionality. They were trying to access the email address of the user who posted the topic within a specific function in lib/email/message_builder.rb.
tarek used the byebug tool, as suggested by Falco, to inspect the variables and found the @opts object, which contained the post ID. They then needed to find a function to retrieve the user’s email address using the post ID.
tarek eventually discovered that they could use the Post.find_by_id and User.find_by_id methods to achieve this, and Falco noted that Rails has a straightforward API.
tarek shared the solution they implemented, which was later improved upon by riking, suggesting that p.user.email could be used instead of multiple lines of code. tarek incorporated this suggestion into their patch.
What I would like is to access the email address of the user who posted the topic that the function is being accessed on.
Here is the code snipet, found in line 148 of lib/email/message_builder.rb:
if allow_reply_by_email?
result['X-Discourse-Reply-Key'] = reply_key
result['Reply-To'] = "test1@test.com"
result['CC'] = reply_by_email_address
else
result['Reply-To'] = from_value
end
I want to replace test1@test.com with the email address of the author of the topic.
I have found some documentation on API that seems very relevant, but no “list of functions” as such. I don’t believe that what I’m looking for is called a “hook”, and the list of hooks doesn’t appear relevant.
I understand that my question comes out of an incompetence in Rails programming, and I plan on studying Rails more over time. In PHP programming, which I am familiar with, I am able to access this information using some debugging tool like XDebug for PHP where I can ‘stop’ the code and see what variables are accessible. I haven’t figured out how to use such a tool for Rails yet.
and then typed in var all from sidekiq. This shows all of the variables, and @opts seemed the relevant one. However, it does not contain anything like the sender’s email address, though it does contain post id (14). I think the way to pull this is to:
Ask what the user who posted post_id 14
Ask what the email address of that user is
Export it as a variable.
Which brings me back to the original point that I have to figure out what function can do this..