BP\u REST\u消息\u端点::为\u响应准备\u项\u(消息线程$thread,WP_REST_Request$request)

准备线程数据作为对象返回。

描述

参数

$thread

(消息线程)(必选)线程对象。

$request

(WP_REST_Request)(必选)有关请求的完整详细信息。

返回

(WP_REST_Response)

文件:bp messages/classes/class-bp-rest-messages-endpoint.php

公共函数为响应($thread,$request){global$wpdb;$content='';if(''==$content){if(!empty($thread->messages)){foreach($thread->messages as$thread\u messages){$content=trim(wp\u strip\u all\u标记(do\u shortcode($thread\u message->message));if('=$content){$thread->last_message_content=$thread_message->message;$thread->last_message_subject=$thread_message->subject;break;}}}}}}$last_message=reset($thread->messages);if(!empty($last_message)){$thread->last_message id=$last_message->id;}$extract='';if(isset($thread->last_message内容)){$extract=wp_strip_all_标记(bp_create_extract($thread->last_messages_content,75))}$group_id=bp_messages_get_meta($thread->last_messages_id,'group_id',true);$first_messages=(方法_存在('bp_messages_thread thread,'get_first_messages')?bp_messages->get_first_messages($thread get_id:'')“”);if(!empty($group_id)&&&!empty($first_message)){$group_id=(int)bp_messages_get_meta($first_message->id,'group_id',true)}如果((int)$group_id>0&!empty($group_messages_thread_id=bp_messages_get_meta($first_messages->id,'group_messages_thread id',true)//group.$group_id=(int)bp_messages_get_meta($first_message->id,'group_id',true);$message_users=bp_messages_get_meta($first_message->id,'group_messages_users',true);//所有-个人。$message_type=bp_messages_get_meta($first_message->id,'group_message_type',true);//打开-私有。$messages_from=bp_messages_get_meta($first_messages->id,'messages,'message from',true)//组。如果(bp_处于活动状态('groups'){$group_name=bp_get_group_name(groups_get_group($group_id));$group_link=bp_get_group_permalink(groups_get_group('group_id))}否则,{$prefix=apply_过滤器('bp_core_get_table_table_prefix',$wpdb->base_prefix);$groups\u table=$prefix.'bp\u groups'.//phpcs:ignore$groups\u name=$wpdb->get\u var(“从`{$groups\u table}`中选择`name`,其中`id`='{$groups\u id}'”;//db调用确定;无缓存确定;$groups\u链接='''.}$groups\u name=(空($groups\u name))?\u('Deleted group','buddyboss):$groupu name;}如果(isset($message FROM)&&&“组”==$message\u from&&isset($group\u message\u thread\u id)&&&$thread->thread\u id===(int)$group\u message\u thread\u id&&isset($message\u users)&&isset($message\u type)&&“all”==$message\u users&“open”==$message\u type){$is\u组线程=1;}如果(isset($is\u group\u thread)&$is\u thread)&$is\u线程){$avatar=array('thumb'=>bp\u core\u fetch\u头像(数组('html'=>false,'object'=>'group','item\u id'=>$group\id','type'=>'thumb',),'full'=>bp\u core\u fetch\u头像(数组('html'=>false,'object'=>'group','item\u id'=>'group\id','type'=>'full'),),),);}其他{$recents=$threads=$threads=>recipents;$curren user\u用户id($request[]&&!empty($request['user\u id'])?$request['user\u id']:bp\u current\u user\u id());如果(!empty($recepients)和数组密钥存在($curren\u user\u id,$recepients)){未设置($recepients[$curren\u user\u id])}如果(!empty($recepients)和计数($recepients)>1){$avatar=array('full'=>bp\u core\u fetch('item\u id'=>$thread->last\u sender\u id,'html'=>false,'type'=>'full','object'=>'user',),'thumb'=>bp\u core\u fetch\u avatar(数组('item\u id'=>$thread->last\u sender\u id,'html'=>false,'object'=>'user',),),;}其他{$avatar\u user=!empty($recepients)&!empty($reset($recepients)?)重置($recepients)->用户id:$curren\u user\u id;$avatar=array('full'=>bp\u core\u fetch\u avatar(array('item\u id'=>$avatar\u user,'html'=>false,'type'=>'full','object'=>'user',),'thumb'=>bp\u core\u fetch\u avatar(array('item\u id'=>$avatar\u user,'html'=>false,'object=>'user',),),;}$data=array('id'=>$thread->thread\u id,'message\u id'=>$thread->last\u message\u id,'last\u sender\u id'=>$thread->last\u sender\u id,'subject'=>数组('raw'=>$thread->$thread->last\u message\u subject,'rendered'=>应用过滤器('bp\u get\u message\u thread\u主题,'wp\u statize\u表情('thread->last\u message\u subject)),),),'extract'=>数组('raw'=>$extract','rendered'=>apply_filters('bp_-get_-message_-thread_-extract',$extract),'message'=>array('raw'=>$thread->last_-message_-content','rendered'=>apply_filters('bp_-get_-message_-thread_-thread_-content','wp_-statize_-emojie_('thread->last_-message_-chs->_-content)),'date),'date=>bp_-rest,“开始日期”=>bp\U休息准备日期响应($isset($thread->first\U message\U date)“$thread->first\U message\U date:$thread->last\U message\U date”),“未读计数”=>!empty($thread->未读计数)“$thread->未读计数:0,$thread\U id'=>$thread->发件人\U id,'current\U user\U user'=>,“当前用户”=>(isset($request($request['user\U id')['user\U id')id)?$request['user_id']:bp_loggedin_user_id()),'avatar'=>$avatar','is_group'=>(!empty($group_id)?$group_id:false ), 'is_group_thread' => ( isset( $is_group_thread ) ? $is_group_thread : false ), 'group_name' => ( isset( $group_name ) ? $group_name : '' ), 'group_link' => ( isset( $group_link ) ? $group_link : '' ), 'group_message_users' => ( isset( $message_users ) ? $message_users : '' ), 'group_message_type' => ( isset( $message_type ) ? $message_type : '' ), 'group_message_from' => ( isset( $message_from ) ? $message_from : '' ), 'recipients_count' => ( ( isset( $thread->recipients ) && count( $thread->recipients ) > 1 ) ? count( $thread->recipients ) - ( isset( $request['user_id'] ) && ! empty( $request['user_id'] ) ? 1 : 0 ) : 0 ), 'recipients' => array(), 'messages' => array(), ); if ( $thread->messages ) { // update order of the message to latest one at the end. $thread_messages = array_reverse( $thread->messages ); $thread->messages = $thread_messages; // Loop through messages to prepare them for the response. foreach ( $thread->messages as $message ) { $data['messages'][] = $this->prepare_message_for_response( $message, $request ); } } if ( $thread->recipients ) { // Loop through recipients to prepare them for the response. foreach ( $thread->recipients as $recipient ) { $data['recipients'][ $recipient->user_id ] = $this->prepare_recipient_for_response( $recipient, $request ); } } $data['avatar'] = $this->bp_rest_messages_get_avatars( $thread->thread_id ); // Pluck starred message ids. $data['starred_message_ids'] = array_keys( array_filter( wp_list_pluck( $data['messages'], 'is_starred', 'id' ) ) ); $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); $response->add_links( $this->prepare_links( $thread ) ); /** * Filter a thread value returned from the API. * * @param WP_REST_Response $response Response generated by the request. * @param WP_REST_Request $request Request used to generate the response. * @param BP_Messages_Thread $thread The thread object. * * @since 0.1.0 */ return apply_filters( 'bp_rest_messages_prepare_value', $response, $request, $thread ); }

变更日志

变更日志
版本 描述
0.1.0 介绍。

问题?

我们随时乐意为您提供代码或其他问题的帮助!搜索我们的开发者文档,联络支持,或与我们联系销售团队.