ASPX templates
Version 6.x > ASPX templates > New thread creation event View modes: 
User avatar
Member
Member
vasiliy.ivanov1975-gmail - 12/29/2012 2:53:14 AM
   
New thread creation event
Hello,

I need to bind some activity to creation of a new forum thread. How can I implement this?
While digging the code, I found that new post and thread creation is handled in ~/CMSModules/Forums/Controls/NewPost.aspx.cs. There is the "newThread" variable:
bool newThread = (ForumContext.CurrentReplyThread == null);

which is set to "true" when new thread creation takes place and to "false" otherwise. But during editing an existing post (no matter is it first post in the thread or any other), after I made corrections and clicked OK, this variable is been set to "true", I see it in debugger and on my custom onThreadCreateActivity method starts.

Happy holidays to all!

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 12/31/2012 3:35:25 AM
   
RE:New thread creation event
Hello Vasiliy,

I'm not pretty sure if I undrestand the whole issue, but what I'm thinking about...

You can create a custom Data handler (CustomDataHandler class) and then set your custom activity to the OnAfterInsert event.

I hope this will at least guide you.

Happy holiday to you too!

Best regards,
Martin Danko

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 1/9/2013 12:00:57 AM
   
RE:New thread creation event
Hello Martin,
thank you for reply.

I need to handle new forum thread creation, but OnAfterInsert event is also fired on new post creation in the existing thread. So I need something else.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 1/18/2013 8:29:28 AM
   
RE:New thread creation event
Hi Vasiliy,

Ok, you're right so in the OnAfterInsert event you can check if the the post is first post (new thread is created) or it's just a reply post (not new thread).
You can check it with some condition, e.g.:
CurrentReplyThread == null
//or
PostParentID == null

I hope this will help you.

Best regards,
Martin Danko

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 1/21/2013 2:27:12 AM
   
RE:New thread creation event
Hello Martin,

Digging the code, I found the following solution:
if (ForumContext.CurrentState == ForumStateEnum.NewThread)

But thank you for your help anyway!

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 1/21/2013 5:26:56 AM
   
RE:New thread creation event
Hello Vasiliy,

Thanks for the post, Good to know that there is also another way to achieve this, great!

Best regards,
Martin Danko