From 5226e4ca95a3dd95c973d14f49b9c0bfa79595b5 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Wed, 8 Mar 2023 22:48:55 +0400 Subject: [PATCH] Participants rank in members tab Fix infinite history request in empty chats --- src/components/appSearchSuper..ts | 14 +++++++++++--- src/components/chat/bubbles.ts | 6 +++--- src/components/sortedUserList.ts | 13 +++++++++++-- src/config/app.ts | 2 +- src/lang.ts | 4 ++++ src/lib/appManagers/appMessagesManager.ts | 3 +++ .../appManagers/utils/chats/getParticipantRank.ts | 7 +++++++ src/scss/partials/_chatBubble.scss | 12 ++++++++---- 8 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/lib/appManagers/utils/chats/getParticipantRank.ts diff --git a/src/components/appSearchSuper..ts b/src/components/appSearchSuper..ts index 4477c4d5..b3f69c9b 100644 --- a/src/components/appSearchSuper..ts +++ b/src/components/appSearchSuper..ts @@ -78,6 +78,7 @@ import wrapMediaSpoiler, {onMediaSpoilerClick} from './wrappers/mediaSpoiler'; import filterAsync from '../helpers/array/filterAsync'; import ChatContextMenu from './chat/contextMenu'; import PopupElement from './popups'; +import getParticipantRank from '../lib/appManagers/utils/chats/getParticipantRank'; // const testScroll = false; @@ -1240,10 +1241,13 @@ export default class AppSearchSuper { return; } - return peerId; + return { + peerId, + rank: getParticipantRank(participant as ChannelParticipant) + }; }).filter(Boolean); - const filtered = await filterAsync(peerIds, async(peerId) => { + const filtered = await filterAsync(peerIds, async({peerId}) => { const peer: User | Chat = await this.managers.appPeersManager.getPeer(peerId); if(!middleware()) { return false; @@ -1256,7 +1260,11 @@ export default class AppSearchSuper { return true; }); - for(const peerId of filtered) { + for(const {peerId, rank} of filtered) { + if(rank) { + membersList.ranks.set(peerId, rank); + } + membersList.add(peerId); } }; diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 56580d59..be4e6111 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -3633,11 +3633,11 @@ export default class ChatBubbles { restoreScroll?.(); - pause(!this.chat.setPeerPromise ? 0 : 1000) - .then(() => getHeavyAnimationPromise()) + m(pause(!this.chat.setPeerPromise ? 0 : 1000)) + .then(() => m(getHeavyAnimationPromise())) .then(() => { this.lazyLoadQueue.setAllSeen(); - }); + }).catch(noop); // this.setStickyDateManually(); }; diff --git a/src/components/sortedUserList.ts b/src/components/sortedUserList.ts index 9a5b106b..3d5f25b4 100644 --- a/src/components/sortedUserList.ts +++ b/src/components/sortedUserList.ts @@ -16,6 +16,7 @@ import {AppManagers} from '../lib/appManagers/managers'; import getUserStatusString from './wrappers/getUserStatusString'; import type LazyLoadQueue from './lazyLoadQueue'; import getChatMembersString from './wrappers/getChatMembersString'; +import {i18n} from '../lib/langPack'; interface SortedUser extends SortedElementBase { dom: DialogDom @@ -24,6 +25,7 @@ interface SortedUser extends SortedElementBase { export default class SortedUserList extends SortedList { protected static SORT_INTERVAL = 30e3; public list: HTMLUListElement; + public ranks: Map = new Map(); protected lazyLoadQueue: LazyLoadQueue; protected avatarSize: DialogElementSize = 'abitbigger'; @@ -71,7 +73,7 @@ export default class SortedUserList extends SortedList { } }, onElementCreate: (base) => { - const {dom} = appDialogsManager.addDialogNew({ + const dialogElement = appDialogsManager.addDialogNew({ peerId: base.id, container: false, avatarSize: this.avatarSize, @@ -83,7 +85,14 @@ export default class SortedUserList extends SortedList { } }); - (base as SortedUser).dom = dom; + const rank = this.ranks.get(base.id); + if(rank) { + dialogElement.titleRight.replaceChildren(typeof(rank) === 'number' ? + i18n(rank === 1 ? 'Chat.OwnerBadge' : 'ChatAdmin') : + rank); + } + + (base as SortedUser).dom = dialogElement.dom; return base as SortedUser; }, updateElementWith: fastRaf, diff --git a/src/config/app.ts b/src/config/app.ts index dd795a14..c3e45151 100644 --- a/src/config/app.ts +++ b/src/config/app.ts @@ -21,7 +21,7 @@ const App = { version: process.env.VERSION, versionFull: process.env.VERSION_FULL, build: +process.env.BUILD, - langPackVersion: '1.0.4', + langPackVersion: '1.0.5', langPack: 'webk', langPackCode: 'en', domains: MAIN_DOMAINS, diff --git a/src/lang.ts b/src/lang.ts index fc5d8ab9..613b17b9 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -949,6 +949,7 @@ const lang = { 'ActionGiftOutbound': 'You have sent a gift for **un2**', 'ActionGiftPremiumTitle': 'Telegram Premium', 'ActionGiftPremiumSubtitle': 'for %1$s', + 'ChatAdmin': 'admin', // * macos 'AccountSettings.Filters': 'Chat Folders', @@ -1019,6 +1020,7 @@ const lang = { 'Chat.Context.ReactedFast': { 'other_value': '%d Reacted' }, + 'Chat.ChannelBadge': 'channel', 'Chat.Date.ScheduledFor': 'Scheduled for %@', 'Chat.Date.ScheduledForToday': 'Scheduled for today', 'Chat.DropTitle': 'Drop files here to send them', @@ -1026,6 +1028,7 @@ const lang = { 'Chat.DropAsFilesDesc': 'without compression', 'Chat.Edit.Cancel.Text': 'Are you sure you want to discard all changes?', 'Chat.Input.ReplyToAnswer': 'Reply to message in topics', + 'Chat.OwnerBadge': 'owner', 'Chat.SendVoice.PrivacyError': '%@ doesn\'t accept voice and video messages', 'Chat.Service.Call.Cancelled': 'Cancelled', 'Chat.Service.Call.Missed': 'Missed', @@ -1101,6 +1104,7 @@ const lang = { 'one_value': '%d Comment', 'other_value': '%d Comments' }, + 'Chat.TopicBadge': 'topic creator', 'ChatTitle.ReportMessages': 'Report Messages', 'Chat.Send.WithoutSound': 'Send Without Sound', 'Chat.Send.SetReminder': 'Set a Reminder', diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index dc45292c..b79d2b00 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -5950,6 +5950,9 @@ export class AppMessagesManager extends AppManager { if(isTopEnd || isBottomEnd) { offsetIdOffset = isTopEnd ? count - topLoaded : bottomLoaded; } + } else if(messages.length >= count) { + isTopEnd = true; + isBottomEnd = true; } offsetIdOffset ??= 0; diff --git a/src/lib/appManagers/utils/chats/getParticipantRank.ts b/src/lib/appManagers/utils/chats/getParticipantRank.ts new file mode 100644 index 00000000..7f743e9c --- /dev/null +++ b/src/lib/appManagers/utils/chats/getParticipantRank.ts @@ -0,0 +1,7 @@ +import {ChannelParticipant, ChatParticipant} from '../../../../layer'; + +export default function getParticipantRank(participant: ChannelParticipant | ChatParticipant) { + return (participant as ChannelParticipant.channelParticipantAdmin).rank || + (participant._ === 'channelParticipantAdmin' || participant._ === 'chatParticipantAdmin' ? 2 : + (participant._ === 'chatParticipantCreator' || participant._ === 'channelParticipantCreator' ? 1 : undefined)); +} diff --git a/src/scss/partials/_chatBubble.scss b/src/scss/partials/_chatBubble.scss index 934a369b..65717229 100644 --- a/src/scss/partials/_chatBubble.scss +++ b/src/scss/partials/_chatBubble.scss @@ -2492,10 +2492,14 @@ $bubble-border-radius-big: 12px; // } } -.timestamp.is-disabled { - color: inherit; - text-decoration: none !important; - cursor: inherit; +.timestamp { + text-decoration: underline; + + &.is-disabled { + color: inherit; + text-decoration: none !important; + cursor: inherit; + } } @keyframes audio-dots {