( target: TargetChat, user: Api.User, lockedSeatSet: Set<string>, )
| 547 | const name = getUserDisplayName(user); |
| 548 | const onlineDays = getLastOnlineDays(user); |
| 549 | const participant = (user as any).participant as |
| 550 | | Api.ChatParticipantAdmin |
| 551 | | Api.ChatParticipantCreator |
| 552 | | Api.ChannelParticipantAdmin |
| 553 | | Api.ChannelParticipantCreator |
| 554 | | undefined; |
| 555 | |
| 556 | await setCachedUserInfo(target, user); |
| 557 | |
| 558 | const adminRankText = participant?.rank?.trim() || "无"; |
| 559 | const lastSeenDaysText = onlineDays === null ? "N/A" : `${onlineDays}`; |
| 560 | |
| 561 | let avgPerDayText = "N/A"; |
| 562 | let sortAvgPerDay = -1; |
| 563 | |
| 564 | try { |
| 565 | const cachedEntry = await getCachedAvgEntry(target, userId); |
| 566 | |
| 567 | if (cachedEntry && typeof cachedEntry.avgPerDay === "number") { |
| 568 | sortAvgPerDay = cachedEntry.avgPerDay; |
| 569 | avgPerDayText = formatAvgPerDay(cachedEntry.avgPerDay); |
| 570 | } else { |
| 571 | const fromEntity = await client.getInputEntity(user as any); |
| 572 | const searchResult: any = await client.invoke( |
| 573 | new Api.messages.Search({ |
| 574 | peer: target.entity as any, |
| 575 | q: "", |
| 576 | filter: new Api.InputMessagesFilterEmpty(), |
| 577 | minDate: Math.floor(Date.now() / 1000) - WEEK_SECONDS, |
| 578 | maxDate: undefined as any, |
| 579 | offsetId: 0, |
| 580 | addOffset: 0, |
| 581 | limit: 1, |
| 582 | maxId: 0, |
| 583 | minId: 0, |
| 584 | hash: 0 as any, |
| 585 | fromId: fromEntity, |
| 586 | }), |
| 587 | ); |
| 588 | |
| 589 | const count = Number( |
| 590 | "count" in searchResult |
| 591 | ? searchResult.count |
| 592 | : searchResult.messages?.length || 0, |
| 593 | ); |
| 594 | |
| 595 | if (Number.isFinite(count)) { |
| 596 | sortAvgPerDay = count / 7; |
| 597 | avgPerDayText = formatAvgPerDay(sortAvgPerDay); |
| 598 | await setCachedAvgEntry(target, userId, sortAvgPerDay); |
| 599 | } |
| 600 | } |
| 601 | } catch (error) { |
| 602 | console.warn(`[admin_board] 获取最近一周消息数失败: ${userId}`, error); |
| 603 | } |
| 604 | |
| 605 | let lastMessageText = "无记录"; |
| 606 | let sortLastMessageTs = 0; |
no test coverage detected