删除私信分支链路

This commit is contained in:
2026-08-23 13:42:35 +08:00
parent 1c5c6d86bb
commit c6c2c0af6d
39 changed files with 32 additions and 1465 deletions
-132
View File
@@ -53,53 +53,6 @@ class MessageController extends ControllerBase {
'callback' => [$this, 'mark_all_read'],
'permission_callback' => [$this, 'check_logged_in_permission'],
]);
// ── Private Messages / Conversations ──
// List conversations
register_rest_route(self::API_NAMESPACE, '/conversations', [
'methods' => 'GET',
'callback' => [$this, 'list_conversations'],
'permission_callback' => [$this, 'check_logged_in_permission'],
'args' => [
'limit' => ['default' => 20, 'sanitize_callback' => 'absint'],
],
]);
// Get thread messages
register_rest_route(self::API_NAMESPACE, '/conversations/(?P<id>\d+)/messages', [
'methods' => 'GET',
'callback' => [$this, 'get_thread'],
'permission_callback' => [$this, 'check_logged_in_permission'],
'args' => [
'page' => ['default' => 1, 'sanitize_callback' => 'absint'],
'per_page' => ['default' => 30, 'sanitize_callback' => 'absint'],
],
]);
// Send message in conversation
register_rest_route(self::API_NAMESPACE, '/conversations/(?P<id>\d+)/messages', [
'methods' => 'POST',
'callback' => [$this, 'send_message'],
'permission_callback' => [$this, 'check_logged_in_permission'],
'args' => [
'content' => ['required' => true, 'sanitize_callback' => 'sanitize_textarea_field'],
],
]);
// Create or get conversation with a user
register_rest_route(self::API_NAMESPACE, '/conversations/with/(?P<user_id>\d+)', [
'methods' => 'POST',
'callback' => [$this, 'get_or_create_conversation'],
'permission_callback' => [$this, 'check_logged_in_permission'],
]);
// Mark conversation read
register_rest_route(self::API_NAMESPACE, '/conversations/(?P<id>\d+)/read', [
'methods' => 'POST',
'callback' => [$this, 'mark_conversation_read'],
'permission_callback' => [$this, 'check_logged_in_permission'],
]);
}
// ── Notification handlers ──
@@ -160,91 +113,6 @@ class MessageController extends ControllerBase {
return $this->success(['data' => ['success' => $result]]);
}
// ── Conversation handlers ──
public function list_conversations(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$limit = min(50, (int) $request->get_param('limit'));
if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->success(['data' => []]);
}
$conversations = \AKSRT\Messages\PrivateMessage::get_instance()->get_conversations($user_id, $limit);
return $this->success(['data' => $conversations]);
}
public function get_thread(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$conv_id = (int) $request->get_param('id');
$page = max(1, (int) $request->get_param('page'));
$per_page = min(50, (int) $request->get_param('per_page'));
if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->error('not_available', '私信系统未启用。', 501);
}
$result = \AKSRT\Messages\PrivateMessage::get_instance()->get_thread($conv_id, $user_id, $page, $per_page);
if (is_wp_error($result)) {
return $this->error('thread_error', $result->get_error_message(), 403);
}
return $this->success(['data' => $result]);
}
public function send_message(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$conv_id = (int) $request->get_param('id');
$content = trim((string) $request->get_param('content'));
if (!$content) {
return $this->error('content_required', '消息内容不能为空。', 400);
}
if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->error('not_available', '私信系统未启用。', 501);
}
$result = \AKSRT\Messages\PrivateMessage::get_instance()->send($conv_id, $user_id, $content);
if (!$result['success']) {
return $this->error('send_failed', $result['message'] ?? '发送失败。', 500);
}
return $this->success(['data' => $result]);
}
public function get_or_create_conversation(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$other_id = (int) $request->get_param('user_id');
if ($user_id === $other_id) {
return $this->error('self_message', '不能与自己创建对话。', 400);
}
if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->error('not_available', '私信系统未启用。', 501);
}
$conv_id = \AKSRT\Messages\PrivateMessage::get_instance()->get_or_create_conversation($user_id, $other_id);
if (is_wp_error($conv_id)) {
return $this->error('create_failed', $conv_id->get_error_message(), 500);
}
return $this->success(['data' => ['conversation_id' => $conv_id]]);
}
public function mark_conversation_read(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$conv_id = (int) $request->get_param('id');
if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->error('not_available', '私信系统未启用。', 501);
}
\AKSRT\Messages\PrivateMessage::get_instance()->mark_conversation_read($conv_id, $user_id);
return $this->success(['data' => ['success' => true]]);
}
public function check_logged_in_permission(): bool {
return is_user_logged_in();
}
-7
View File
@@ -25,7 +25,6 @@ class GlobalSchema {
['key' => 'lazy_avatar', 'label' => '头像懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_posts_content', 'label' => '文章内容图片懒加载', 'type' => 'switch', 'default' => false],
['key' => 'lazy_comment', 'label' => '评论内容图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_private', 'label' => '私信聊天图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_sider', 'label' => '幻灯片图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_cover', 'label' => '封面图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_other', 'label' => '其它图片懒加载', 'type' => 'switch', 'default' => true],
@@ -383,12 +382,6 @@ class GlobalSchema {
['label' => '纯文本', 'value' => 'plain'],
['label' => 'HTML', 'value' => 'html'],
]],
['key' => 'email_private_receive_limit', 'label' => '私信邮件接收组', 'type' => 'select', 'default' => 'all', 'options' => [
['label' => '所有用户', 'value' => 'all'],
['label' => 'VIP 及以上', 'value' => 'vip'],
['label' => 'VIP2 及以上', 'value' => 'vip2'],
['label' => '仅管理员', 'value' => 'admin'],
], 'help' => '限制哪些用户组可以收到私信邮件通知'],
]],
['key' => 'branding', 'title' => '邮件品牌', 'fields' => [
['key' => 'mail_showname', 'label' => '发件人名称', 'type' => 'input', 'default' => '', 'help' => '覆盖系统默认发件人名称'],
-13
View File
@@ -277,21 +277,9 @@ class SchemaUsers {
['label' => '认证回复', 'value' => 'auth_apply_reply'],
['label' => '下载通知', 'value' => 'download'],
['label' => '积分变动', 'value' => 'credits'],
['label' => '私信', 'value' => 'private'],
['label' => '举报反馈', 'value' => 'report'],
]],
]],
['key' => 'private', 'title' => '私信设置', 'fields' => [
['key' => 'private_s', 'label' => '启用私信功能', 'type' => 'switch', 'default' => true],
['key' => 'private_smilie_s', 'label' => '支持表情', 'type' => 'switch', 'default' => true],
['key' => 'private_code_s', 'label' => '支持代码', 'type' => 'switch', 'default' => false],
['key' => 'private_image_s', 'label' => '支持图片', 'type' => 'switch', 'default' => true],
['key' => 'private_upload_img', 'label' => '支持上传图片', 'type' => 'switch', 'default' => false],
['key' => 'private_quick_s', 'label' => '快捷回复', 'type' => 'switch', 'default' => true],
['key' => 'private_quick_often', 'label' => '常用快捷回复', 'type' => 'textarea', 'default' => "你好,请问有什么可以帮你的?\n感谢你的反馈\n已处理,请查收", 'desc' => '一行一条快捷回复文案'],
['key' => 'private_submit_text', 'label' => '发送按钮文案', 'type' => 'input', 'default' => '发送'],
['key' => 'private_placeholder', 'label' => '输入占位符', 'type' => 'input', 'default' => '请输入消息...'],
]],
],
],
'oauth' => [
@@ -580,7 +568,6 @@ class SchemaUsers {
['key' => 'user_cover_img', 'label' => '默认封面', 'type' => 'media', 'default' => ''],
['key' => 'user_rewrite_slug', 'label' => '用户页slug', 'type' => 'input', 'default' => 'user'],
['key' => 'user_follow_s', 'label' => '启用关注功能', 'type' => 'switch', 'default' => true],
['key' => 'user_message_s', 'label' => '启用私信功能', 'type' => 'switch', 'default' => true],
['key' => 'user_online_s', 'label' => '显示在线状态', 'type' => 'switch', 'default' => true],
['key' => 'user_last_active_s', 'label' => '显示最后活跃', 'type' => 'switch', 'default' => true],
]],
@@ -151,11 +151,6 @@ trait UserControllerAuthPhoneOperations {
return $this->error('未登录', 401);
}
$unread = 0;
if (class_exists('\AKSRT\Messages\PrivateMessage')) {
$unread = \AKSRT\Messages\PrivateMessage::get_instance()->get_unread_count($user->ID);
}
$credits = 0;
if (class_exists('\AKSRT\Credits\Credits')) {
$credits = \AKSRT\Credits\Credits::balance($user->ID);
@@ -170,7 +165,6 @@ trait UserControllerAuthPhoneOperations {
? aksrt_get_avatar_url($user->ID, ['size' => 48])
: get_avatar_url($user->ID, ['size' => 48]),
'is_admin' => current_user_can('manage_options'),
'unread' => $unread,
'credits' => $credits,
],
]);