Telegram Web K with changes to work inside I2P https://web.telegram.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.7 KiB

4 years ago
export class AppMessagesIDsManager {
public channelLocals: {[channelID: string]: number} = {};
public channelsByLocals: {[localStart: string]: number} = {};
4 years ago
public channelCurLocal = 0;
public fullMsgIDModulus = 4294967296;
public getFullMessageID(msgID: number, channelID: number): number {
if(!channelID || msgID <= 0) {
return msgID;
}
4 years ago
msgID = this.getMessageLocalID(msgID);
let localStart = this.channelLocals[channelID];
4 years ago
if(!localStart) {
localStart = (++this.channelCurLocal) * this.fullMsgIDModulus;
this.channelsByLocals[localStart] = channelID;
this.channelLocals[channelID] = localStart;
}
return localStart + msgID;
}
public getMessageIDInfo(fullMsgID: number) {
if(fullMsgID < this.fullMsgIDModulus) {
4 years ago
return [fullMsgID, 0];
}
const msgID = fullMsgID % this.fullMsgIDModulus;
const channelID = this.channelsByLocals[fullMsgID - msgID];
4 years ago
return [msgID, channelID];
}
public getMessageLocalID(fullMsgID: number) {
return fullMsgID ? fullMsgID % this.fullMsgIDModulus : 0;
4 years ago
}
public splitMessageIDsByChannels(mids: number[]) {
const msgIDsByChannels: {[channelID: number]: number[]} = {};
const midsByChannels: {[channelID: number]: number[]} = {};
for(const mid of mids) {
const msgChannel = this.getMessageIDInfo(mid);
const channelID = msgChannel[1];
4 years ago
if(msgIDsByChannels[channelID] === undefined) {
msgIDsByChannels[channelID] = [];
midsByChannels[channelID] = [];
}
4 years ago
msgIDsByChannels[channelID].push(msgChannel[0]);
midsByChannels[channelID].push(mid);
}
return {
msgIDs: msgIDsByChannels,
mids: midsByChannels
};
}
}
export default new AppMessagesIDsManager();