XF 1.5 Getting Last Message from $conversation

king8084

Well-known member
I'm toying with my inbox dropdown (conversation_list_popup_item) and would ideally like to be able to display a portion of the last message in that conversation...

i only have $conversation to work with from here, and it's unclear how to pass/access the $message var where the message contents are stored from here.
 
Can you dump $conversation?
yep.

Code:
array(85) {


  ["conversation_id"] => int(79875)


  ["title"] => string(6) "Wolves"


  ["user_id"] => int(27098317)


  ["username"] => string(6) "coleqm"


  ["start_date"] => int(1482883535)


  ["open_invite"] => int(0)


  ["conversation_open"] => int(1)


  ["reply_count"] => int(2)


  ["recipient_count"] => int(2)


  ["first_message_id"] => int(246625)


  ["last_message_date"] => int(1482960965)


  ["last_message_id"] => int(246829)


  ["last_message_user_id"] => int(27098317)


  ["last_message_username"] => string(6) "coleqm"


  ["recipients"] => string(64) "a:1:{i:164;a:2:{s:7:"user_id";i:164;s:8:"username";s:4:"Slyk";}}"


  ["owner_user_id"] => int(164)


  ["is_unread"] => int(0)


  ["is_starred"] => int(1)


  ["email"] => string(16) "coleqm@gmail.com"


  ["gender"] => string(0) ""


  ["custom_title"] => string(13) "/r/KanyeLeaks"


  ["language_id"] => int(1)


  ["style_id"] => int(8)


  ["timezone"] => string(16) "America/New_York"


  ["visible"] => int(1)


  ["activity_visible"] => int(1)


  ["user_group_id"] => int(2)


  ["secondary_group_ids"] => string(2) "34"


  ["display_style_group_id"] => int(2)


  ["permission_combination_id"] => int(182)


  ["message_count"] => int(82)


  ["conversations_unread"] => int(0)


  ["register_date"] => int(1467167557)


  ["last_activity"] => int(1488769488)


  ["trophy_points"] => int(665)


  ["alerts_unread"] => int(1)


  ["avatar_date"] => int(1488131767)


  ["avatar_width"] => int(192)


  ["avatar_height"] => int(192)


  ["gravatar"] => string(0) ""


  ["user_state"] => string(5) "valid"


  ["is_moderator"] => int(0)


  ["is_admin"] => int(0)


  ["is_banned"] => int(0)


  ["like_count"] => int(167)


  ["warning_points"] => int(0)


  ["is_staff"] => int(0)


  ["user_title_waindigo"] => string(0) ""


  ["nsfw_options"] => NULL


  ["ignore_node"] => NULL


  ["credits"] => string(6) "0.0000"


  ["brc_points"] => string(6) "0.0000"


  ["weekly_digest_opt_out"] => int(0)


  ["nqrp_is_via_quick_reply"] => int(0)


  ["favorite_badge"] => string(0) ""


  ["auto_feature_badge"] => int(0)


  ["feature_badge_slide_options"] => string(0) ""


  ["sportsbook_cash"] => string(7) "1000.00"


  ["brrs_referral_count"] => int(0)


  ["brrs_referral_user_id"] => int(0)


  ["brrs_referral_valid"] => int(0)


  ["xfa_cui_type"] => int(0)


  ["xfa_cui_noanim"] => int(0)


  ["xfa_cui_params"] => NULL


  ["subaccount_parent_user_id"] => int(0)


  ["subaccount_parent_state"] => string(8) "disabled"


  ["subaccount_user_ids"] => NULL


  ["subaccount_parent_email"] => string(0) ""


  ["subaccount_parent_user_group_id"] => int(0)


  ["subaccount_parent_secondary_group_ids"] => string(0) ""


  ["subaccount_alerts_unread"] => int(0)


  ["sign_image_date"] => int(0)


  ["recipient_state"] => string(6) "active"


  ["last_read_date"] => int(1482960965)


  ["last_message_avatar_date"] => int(1488131767)


  ["last_message_gender"] => string(0) ""


  ["last_message_gravatar"] => string(0) ""


  ["isNew"] => bool(false)


  ["lastPageNumbers"] => bool(false)


  ["last_message"] => array(7) {


    ["message_id"] => int(246829)


    ["message_date"] => int(1482960965)


    ["user_id"] => int(27098317)


    ["username"] => string(6) "coleqm"


    ["avatar_date"] => int(1488131767)


    ["gender"] => string(0) ""


    ["gravatar"] => string(0) ""


  }


  ["customFields"] => array(0) {


  }


  ["externalAuth"] => array(0) {


  }


  ["isTrusted"] => bool(false)


  ["isIgnored"] => bool(false)


  ["recipientNames"] => array(1) {


    [164] => array(2) {


      ["user_id"] => int(164)


      ["username"] => string(4) "Slyk"


    }


  }


}
 
There is nothing like that in there as you can see. You would need to modify the controller and pass the last message to the template.
 
Find the method in the controller (see our last thread: https://xenforo.com/community/threa...ations-in-inbox-dropdown.150820/#post-1269193).
There will be something like $message or $lastmessage or something similar I guess. You should be able to extract the message from that and pass it to the view.
the following are what's being returned by public function actionPopup() in Conversation.php:
Code:
        $viewParams = array(
            'conversationsUnread' => $conversationModel->prepareConversations($conversationsUnread),
            'conversationsRead' => $conversationModel->prepareConversations($conversationsRead)
        );

that said, i can't simply add either of these:
Code:
                'message' => $conversationModel->prepareMessage($message, $conversation)
or
Code:
            'messages' => $messages,
since actionPopup() doesn't have $messages to begin with... i'm guessing i'll need to identify which controller is calling into actionPopup() and then pass $messages along through the params (assuming it's available in what's calling actionPopup()?? or could there a way within here to simply grab $messages and return it via the $viewParams array?
 
You will need to find the method which returns $conversation into conversation_list_popup_item. actionPopup() results into conversation_list_popup and not conversation_list_popup_item.
 
You will need to find the method which returns $conversation into conversation_list_popup_item. actionPopup() results into conversation_list_popup and not conversation_list_popup_item.
i know you're being super helpful, and this is probably a dumb question, but is there even anything that results into conversation_list_popup_item? I've searched through all public controllers and have come up empty. conversation_list_popup calls into conversation_list_popup_item via a template include. When including a template, do you inherently receive all of the vars from the template you're jumping from (in this case, $messages, if i'm able to obtain that in conversation_list_popup)?
 
_item are the macro type templates in 1.5 IIRC. You will need to find out which template calls that and maybe even trace that back a bit more. Once you get the "parent" template which pumps everything into _item, you can modify the variable pushed into the _item template by modifying the "parent" template controller.
In conversation_list_popup
HTML:
<xen:foreach loop="$conversationsUnread" value="$conversation"><xen:include template="conversation_list_popup_item" /></xen:foreach>
So $conversation is actually a template variable assigned on-the-fly, that's why you won't find any controller reference.
This means you can modify $conversationsUnread or $conversationsRead within actionPopup(). Since they are arrays, you can easily attach your own values into that. And conversation_list_popup_item does not iterate over each value, so you won't get into trouble there aswell.
Retreiving those messages is another story, you will need to look through the code. Those conversation items should contain (read / unread) the conversation ID at least. So you can do sth like
PHP:
foreach($conversationsUnread as &$conversation) {
    $conversation['message'] = $conversationModel->getConversationMessageById($conversation["conversation_id"]); // sth like that
}
and the same for unread.
It would be way better if you could find out where $conversationsUnread is built and extend that method to contain the message from the beginning so you don't have to loop an extra time over the messages, but that's really some next lvl optimizing :D
 
Top Bottom