mirror of
https://github.com/kuaifan/dootask.git
synced 2026-09-10 14:08:57 +00:00
fix(messenger): 修复失效成员导致群人数变化
This commit is contained in:
parent
33a72d9d80
commit
098bea3d5b
@ -456,9 +456,13 @@ class WebSocketDialog extends AbstractModel
|
||||
*/
|
||||
public static function generatePeople($dialogId)
|
||||
{
|
||||
$counts = WebSocketDialogUser::whereDialogId($dialogId)
|
||||
->groupBy('bot')
|
||||
->selectRaw('bot, COUNT(*) as count')
|
||||
$counts = DB::table('web_socket_dialog_users as du')
|
||||
->join('users', 'users.userid', '=', 'du.userid')
|
||||
->where('du.dialog_id', $dialogId)
|
||||
->whereNull('users.disable_at')
|
||||
->groupBy('du.bot')
|
||||
->select('du.bot')
|
||||
->selectRaw('COUNT(*) as count')
|
||||
->pluck('count', 'bot');
|
||||
$userCount = $counts->get(0, 0); // 非机器人数量
|
||||
$botCount = $counts->get(1, 0); // 机器人数量
|
||||
|
||||
@ -21,7 +21,7 @@ negative:
|
||||
- 群主不能被踢,只能先转让群主再退群
|
||||
- 任务参与人、项目成员对应的群成员不能在群里直接移除,需到任务 / 项目里调整
|
||||
- 一次最多批量传 userids 数组,但接口未硬限制条数,前端按 200 人内体验最佳
|
||||
last_verified: v1.7.90
|
||||
last_verified: v1.8.89
|
||||
---
|
||||
|
||||
# 添加和移除群成员
|
||||
@ -49,6 +49,7 @@ last_verified: v1.7.90
|
||||
- 有群主时:仅群主 / 群管理员可加人或踢人
|
||||
- 没有群主(如旧群):任意成员可加人
|
||||
- 群主、任务参与人、项目成员对应的成员不可踢
|
||||
- 群成员列表和人数只统计当前有效账号;已离职或已删除账号不显示,也不计入人数
|
||||
|
||||
## 不支持
|
||||
|
||||
|
||||
53
tests/Feature/DialogPeopleCountTest.php
Normal file
53
tests/Feature/DialogPeopleCountTest.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\WebSocketDialog;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DialogPeopleCountTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private function makeUser(string $email, int $bot = 0): User
|
||||
{
|
||||
$user = User::createInstance([
|
||||
'email' => $email,
|
||||
'userimg' => '',
|
||||
'nickname' => 'TestUser',
|
||||
'profession' => '',
|
||||
'password' => md5('123456'),
|
||||
'bot' => $bot,
|
||||
]);
|
||||
$user->save();
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function test_generate_people_ignores_deleted_and_disabled_users(): void
|
||||
{
|
||||
$owner = $this->makeUser('people-owner@test.local');
|
||||
$active = $this->makeUser('people-active@test.local');
|
||||
$disabled = $this->makeUser('people-disabled@test.local');
|
||||
$deleted = $this->makeUser('people-deleted@test.local');
|
||||
$bot = $this->makeUser('people-bot@test.local', 1);
|
||||
$dialog = WebSocketDialog::createGroup(
|
||||
'People count',
|
||||
[$owner->userid, $active->userid, $disabled->userid, $deleted->userid, $bot->userid],
|
||||
'user',
|
||||
$owner->userid
|
||||
);
|
||||
|
||||
$disabled->disable_at = now();
|
||||
$disabled->save();
|
||||
DB::table('users')->where('userid', $deleted->userid)->delete();
|
||||
|
||||
$this->assertSame([
|
||||
'people' => 3,
|
||||
'people_user' => 2,
|
||||
'people_bot' => 1,
|
||||
], WebSocketDialog::generatePeople($dialog->id));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user