misc
This commit is contained in:
parent
3a984570da
commit
55bbcff131
|
@ -3120,6 +3120,51 @@ export default class ChatBubbles {
|
|||
savedPosition
|
||||
};
|
||||
|
||||
if(!samePeer) {
|
||||
this.ranks = undefined;
|
||||
this.processRanks = undefined;
|
||||
this.canShowRanks = false;
|
||||
|
||||
if(this.chat.isChannel) {
|
||||
this.canShowRanks = true;
|
||||
const processRanks = this.processRanks = new Set();
|
||||
|
||||
const promise = this.managers.acknowledged.appProfileManager.getParticipants(this.peerId.toChatId(), {_: 'channelParticipantsAdmins'}, 100);
|
||||
const ackedResult = await m(promise);
|
||||
const setRanksPromise = ackedResult.result.then((channelParticipants) => {
|
||||
if(this.processRanks !== processRanks) {
|
||||
return;
|
||||
}
|
||||
|
||||
const participants = channelParticipants.participants as (ChatParticipant.chatParticipantAdmin | ChannelParticipant.channelParticipantAdmin)[];
|
||||
this.ranks = new Map();
|
||||
participants.forEach((participant) => {
|
||||
const rank = getParticipantRank(participant);
|
||||
this.ranks.set(participant.user_id.toPeerId(), rank);
|
||||
});
|
||||
|
||||
getHeavyAnimationPromise().then(() => {
|
||||
if(this.processRanks !== processRanks) {
|
||||
return;
|
||||
}
|
||||
|
||||
processRanks.forEach((callback) => callback());
|
||||
this.processRanks = undefined;
|
||||
});
|
||||
}, (err) => {
|
||||
if((err as ApiError).type !== 'CHAT_ADMIN_REQUIRED') {
|
||||
this.log.error('ranks error', err);
|
||||
}
|
||||
|
||||
this.ranks = new Map();
|
||||
});
|
||||
|
||||
if(ackedResult.cached) {
|
||||
await m(setRanksPromise);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let result: Awaited<ReturnType<ChatBubbles['getHistory']>>;
|
||||
if(!savedPosition) {
|
||||
result = await m(this.getHistory1(lastMsgId, true, isJump, additionMsgId));
|
||||
|
@ -3147,45 +3192,6 @@ export default class ChatBubbles {
|
|||
this.preloader.attach(this.container);
|
||||
}
|
||||
|
||||
if(!samePeer) {
|
||||
this.ranks = undefined;
|
||||
this.processRanks = undefined;
|
||||
this.canShowRanks = false;
|
||||
|
||||
if(this.chat.isChannel) {
|
||||
this.canShowRanks = true;
|
||||
const promise = this.managers.acknowledged.appProfileManager.getParticipants(this.peerId.toChatId(), {_: 'channelParticipantsAdmins'}, 100);
|
||||
const ackedResult = await m(promise);
|
||||
const setRanksPromise = ackedResult.result.then((channelParticipants) => {
|
||||
const participants = channelParticipants.participants as (ChatParticipant.chatParticipantAdmin | ChannelParticipant.channelParticipantAdmin)[];
|
||||
this.ranks = new Map();
|
||||
participants.forEach((participant) => {
|
||||
const rank = getParticipantRank(participant);
|
||||
this.ranks.set(participant.user_id.toPeerId(), rank);
|
||||
});
|
||||
});
|
||||
|
||||
if(ackedResult.cached) {
|
||||
try {
|
||||
await setRanksPromise;
|
||||
} catch(err) {
|
||||
this.ranks = new Map();
|
||||
this.log.error('ranks error', err);
|
||||
}
|
||||
} else {
|
||||
const processRanks = this.processRanks = new Set();
|
||||
setRanksPromise.then(() => {
|
||||
if(this.processRanks !== processRanks) {
|
||||
return;
|
||||
}
|
||||
|
||||
processRanks.forEach((callback) => callback());
|
||||
this.processRanks = undefined;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* this.ladderDeferred && this.ladderDeferred.resolve();
|
||||
this.ladderDeferred = deferredPromise<void>(); */
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ declare global {
|
|||
'USER_ALREADY_PARTICIPANT' | 'USERNAME_INVALID' | 'USERNAME_PURCHASE_AVAILABLE' | 'USERNAMES_ACTIVE_TOO_MUCH' |
|
||||
'BOT_INVALID' | 'USERNAME_NOT_OCCUPIED' | 'PINNED_TOO_MUCH' | 'LOCATION_INVALID' |
|
||||
'FILE_ID_INVALID' | 'CHANNEL_FORUM_MISSING' | 'TRANSCRIPTION_FAILED' | 'USER_NOT_PARTICIPANT' |
|
||||
'PEER_ID_INVALID' | 'MSG_VOICE_MISSING';
|
||||
'PEER_ID_INVALID' | 'MSG_VOICE_MISSING' | 'CHAT_ADMIN_REQUIRED';
|
||||
|
||||
type ErrorType = LocalErrorType | ServerErrorType;
|
||||
|
||||
|
|
|
@ -352,16 +352,8 @@ export class AppProfileManager extends AppManager {
|
|||
limit = 200,
|
||||
offset = 0
|
||||
) {
|
||||
if(filter._ === 'channelParticipantsRecent') {
|
||||
const chat = this.appChatsManager.getChat(id);
|
||||
if(chat?.pFlags && (
|
||||
// chat.pFlags.kicked ||
|
||||
(chat as Chat.channel).pFlags.broadcast &&
|
||||
!(chat as Chat.channel).pFlags.creator &&
|
||||
!(chat as Chat.channel).admin_rights
|
||||
)) {
|
||||
throw makeError('PEER_ID_INVALID');
|
||||
}
|
||||
if(!this.appChatsManager.hasRights(id, 'view_participants')) {
|
||||
throw makeError('CHAT_ADMIN_REQUIRED');
|
||||
}
|
||||
|
||||
const result = this.apiManager.invokeApiCacheable('channels.getParticipants', {
|
||||
|
@ -376,31 +368,6 @@ export class AppProfileManager extends AppManager {
|
|||
this.appUsersManager.saveApiUsers((result as ChannelsChannelParticipants.channelsChannelParticipants).users);
|
||||
return result as ChannelsChannelParticipants.channelsChannelParticipants;
|
||||
});
|
||||
/* let maybeAddSelf = (participants: any[]) => {
|
||||
let chat = appChatsManager.getChat(id);
|
||||
let selfMustBeFirst = filter._ === 'channelParticipantsRecent' &&
|
||||
!offset &&
|
||||
!chat.pFlags.kicked &&
|
||||
!chat.pFlags.left;
|
||||
|
||||
if(selfMustBeFirst) {
|
||||
participants = copy(participants);
|
||||
let myID = appUsersManager.getSelf().id;
|
||||
let myIndex = participants.findIndex((p) => p.user_id === myID);
|
||||
let myParticipant;
|
||||
|
||||
if(myIndex !== -1) {
|
||||
myParticipant = participants[myIndex];
|
||||
participants.splice(myIndex, 1);
|
||||
} else {
|
||||
myParticipant = {_: 'channelParticipantSelf', user_id: myID};
|
||||
}
|
||||
|
||||
participants.unshift(myParticipant);
|
||||
}
|
||||
|
||||
return participants;
|
||||
} */
|
||||
}
|
||||
|
||||
public getChannelParticipant(id: ChatId, peerId: PeerId) {
|
||||
|
|
|
@ -43,6 +43,7 @@ export default abstract class ApiManagerMethods extends AppManager {
|
|||
promise: Promise<any>,
|
||||
fulfilled: boolean,
|
||||
result?: any,
|
||||
error?: any,
|
||||
timeout?: number,
|
||||
params: any
|
||||
}
|
||||
|
@ -215,7 +216,15 @@ export default abstract class ApiManagerMethods extends AppManager {
|
|||
const queryJSON = JSON.stringify(params);
|
||||
let item = cache[queryJSON];
|
||||
if(item && (!options.override || !item.fulfilled)) {
|
||||
return options.syncIfHasResult && item.hasOwnProperty('result') ? item.result : item.promise;
|
||||
if(options.syncIfHasResult) {
|
||||
if(item.hasOwnProperty('result')) {
|
||||
return item.result;
|
||||
} else if(item.hasOwnProperty('error')) {
|
||||
throw item.error;
|
||||
}
|
||||
}
|
||||
|
||||
return item.promise;
|
||||
}
|
||||
|
||||
if(options.override) {
|
||||
|
@ -243,7 +252,11 @@ export default abstract class ApiManagerMethods extends AppManager {
|
|||
item.result = result;
|
||||
};
|
||||
|
||||
promise.then(onResult, onResult);
|
||||
promise.then((result) => {
|
||||
item.result = result;
|
||||
}, (error) => {
|
||||
item.error = error;
|
||||
});
|
||||
|
||||
item = cache[queryJSON] = {
|
||||
timestamp: Date.now(),
|
||||
|
|
Loading…
Reference in New Issue