Hi guys,
Here's an interesting one. I am trying to change the Toolset messaging system in a way that I have one page that displays all messages as 'chats' in a sidebar. Then when you click on any of these in the main div there's a view of this chat with a post form to add new content (a new message) to this chat. What I need help with is to connect the different views and post form to each other, or if there is a smarter way then I'll be interested to hear it. The attached image shows how far I've come.
The chats portion displays the latest message per conversation. I created a view for this that is similar to the 'messages received' view from the Toolset messaging module with an addition to also show outgoing messages. I then used the same function to filter for most recent messages.
The 'thread' portion is a view that displays all messages that have a custom field 'first message id' equal to a dropdown option filter. This way I can see all different conversations by selecting a different first message id.
The new message form sits inside the thread view but not inside the view loop. It doesn't work properly yet. Here's the form code:
[credform class='form-dark']
<div class="hidden">[cred_field field='post_title' post='message' value='[wpv-post-title]' urlparam='' class='form-control' output='bootstrap']</div>
[wpv-conditional if="( $(wpcf-message-from) ne '[wpv-current-user info="id"]' )"]
[cred_generic_field field='wpcf-message-to' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"user_id",
"default":"[types field='message-from' output='raw'][/types]"
}
[/cred_generic_field]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-message-from) eq '[wpv-current-user info="id"]' )"]
[cred_generic_field field='wpcf-message-to' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"user_id",
"default":"[types field='message-to' output='raw'][/types]"
}
[/cred_generic_field]
[/wpv-conditional]
[cred_generic_field field='wpcf-message-from' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"user_id",
"default":"[wpv-current-user info='id']"
}
[/cred_generic_field]
[cred_generic_field field='wpcf-first-message-id' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[types field='first-message-id']"
}
[/cred_generic_field]
[cred_generic_field field='wpcf-initial-post-id' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"post_id",
"default":"[types field='initial-post-id']"
}
[/cred_generic_field]
<div class="row align-items-end mt-40">
<div class="col-md-10">
[cred_generic_field field='post_content' type='textarea' placeholder='Schrijf een bericht' urlparam='']
{
"required":1,
"validate_format":0,
"default":""
}
[/cred_generic_field]
</div>
<div class="col-md-2">
[cred_field field='form_submit' value='Verzenden' urlparam='' class='button-secondary']
</div>
</div>
[/credform]
So all I need now is two things:
1. Add some logic so that when clicking a chat in the chat block in the sidebar the related conversation opens in the thread div.
2. Add logic so that the reply message form creates a new message post that has the correct first message id and the right message to.
What would be the smartest way to accomplish this?
Thanks again,
Rens