Local forward first
Delay for connection status change
This commit is contained in:
parent
d24dc657a4
commit
6de93c6fd9
@ -2442,7 +2442,7 @@ export default class ChatBubbles {
|
||||
bubble.classList.add('is-thread-starter', 'is-group-last');
|
||||
}
|
||||
|
||||
if(savedFrom && message.fwd_from.saved_from_msg_id && this.peerId !== REPLIES_PEER_ID) {
|
||||
if(savedFrom && (this.chat.type === 'pinned' || message.fwd_from.saved_from_msg_id) && this.peerId !== REPLIES_PEER_ID) {
|
||||
const goto = document.createElement('div');
|
||||
goto.classList.add('bubble-beside-button', 'goto-original', 'tgico-arrow_next');
|
||||
bubbleContainer.append(goto);
|
||||
|
@ -35,7 +35,7 @@ export namespace MessageRender {
|
||||
}
|
||||
}
|
||||
|
||||
if(message.edit_date && chat.type !== 'scheduled') {
|
||||
if(message.edit_date && chat.type !== 'scheduled' && !message.pFlags.edit_hide) {
|
||||
bubble.classList.add('is-edited');
|
||||
time = '<i class="edited">edited</i> ' + time;
|
||||
}
|
||||
|
1
src/layer.d.ts
vendored
1
src/layer.d.ts
vendored
@ -832,6 +832,7 @@ export namespace Message {
|
||||
deleted?: boolean,
|
||||
peerId?: number,
|
||||
fromId?: number,
|
||||
random_id?: string,
|
||||
rReply?: string
|
||||
};
|
||||
|
||||
|
@ -45,6 +45,8 @@ const testScroll = false;
|
||||
let testTopSlice = 1;
|
||||
|
||||
class ConnectionStatusComponent {
|
||||
public static CHANGE_STATE_DELAY = 1000;
|
||||
|
||||
private statusContainer: HTMLElement;
|
||||
private statusEl: HTMLElement;
|
||||
private statusPreloader: ProgressivePreloader;
|
||||
@ -56,6 +58,9 @@ class ConnectionStatusComponent {
|
||||
|
||||
private log: ReturnType<typeof logger>;
|
||||
|
||||
private setFirstConnectionTimeout: number;
|
||||
private setStateTimeout: number;
|
||||
|
||||
constructor(chatsContainer: HTMLElement) {
|
||||
this.log = logger('CS');
|
||||
|
||||
@ -73,53 +78,29 @@ class ConnectionStatusComponent {
|
||||
const status = e;
|
||||
console.log(status);
|
||||
|
||||
setConnectionStatus();
|
||||
this.setConnectionStatus();
|
||||
});
|
||||
|
||||
rootScope.on('state_synchronizing', (e) => {
|
||||
const channelId = e;
|
||||
if(!channelId) {
|
||||
this.updating = true;
|
||||
this.log('updating', this.updating);
|
||||
DEBUG && this.log('updating', this.updating);
|
||||
this.setState();
|
||||
}
|
||||
});
|
||||
|
||||
rootScope.on('state_synchronized', (e) => {
|
||||
const channelId = e;
|
||||
this.log('state_synchronized', channelId);
|
||||
DEBUG && this.log('state_synchronized', channelId);
|
||||
if(!channelId) {
|
||||
this.updating = false;
|
||||
this.log('updating', this.updating);
|
||||
DEBUG && this.log('updating', this.updating);
|
||||
this.setState();
|
||||
}
|
||||
});
|
||||
|
||||
const setConnectionStatus = () => {
|
||||
sessionStorage.get('dc').then(baseDcId => {
|
||||
if(!baseDcId) {
|
||||
baseDcId = App.baseDcId;
|
||||
}
|
||||
|
||||
if(setFirstConnectionTimeout) {
|
||||
clearTimeout(setFirstConnectionTimeout);
|
||||
setFirstConnectionTimeout = 0;
|
||||
}
|
||||
|
||||
const status = rootScope.connectionStatus['NET-' + baseDcId];
|
||||
const online = status && status.online;
|
||||
|
||||
if(this.connecting && online) {
|
||||
apiUpdatesManager.forceGetDifference();
|
||||
}
|
||||
|
||||
this.connecting = !online;
|
||||
this.log('connecting', this.connecting);
|
||||
this.setState();
|
||||
});
|
||||
};
|
||||
|
||||
let setFirstConnectionTimeout = window.setTimeout(setConnectionStatus, 2e3);
|
||||
this.setFirstConnectionTimeout = window.setTimeout(this.setConnectionStatus, ConnectionStatusComponent.CHANGE_STATE_DELAY + 1e3);
|
||||
|
||||
/* let bool = true;
|
||||
document.addEventListener('dblclick', () => {
|
||||
@ -135,6 +116,30 @@ class ConnectionStatusComponent {
|
||||
}); */
|
||||
}
|
||||
|
||||
private setConnectionStatus = () => {
|
||||
sessionStorage.get('dc').then(baseDcId => {
|
||||
if(!baseDcId) {
|
||||
baseDcId = App.baseDcId;
|
||||
}
|
||||
|
||||
if(this.setFirstConnectionTimeout) {
|
||||
clearTimeout(this.setFirstConnectionTimeout);
|
||||
this.setFirstConnectionTimeout = 0;
|
||||
}
|
||||
|
||||
const status = rootScope.connectionStatus['NET-' + baseDcId];
|
||||
const online = status && status.online;
|
||||
|
||||
if(this.connecting && online) {
|
||||
apiUpdatesManager.forceGetDifference();
|
||||
}
|
||||
|
||||
this.connecting = !online;
|
||||
DEBUG && this.log('connecting', this.connecting);
|
||||
this.setState();
|
||||
});
|
||||
};
|
||||
|
||||
private setStatusText = (text: string) => {
|
||||
if(this.currentText === text) return;
|
||||
this.statusEl.innerText = this.currentText = text;
|
||||
@ -142,15 +147,26 @@ class ConnectionStatusComponent {
|
||||
};
|
||||
|
||||
private setState = () => {
|
||||
const timeout = ConnectionStatusComponent.CHANGE_STATE_DELAY;
|
||||
if(this.connecting) {
|
||||
this.setStatusText('Waiting for network...');
|
||||
} else if(this.updating) {
|
||||
this.setStatusText('Updating...');
|
||||
}
|
||||
|
||||
this.log('setState', this.connecting || this.updating);
|
||||
DEBUG && this.log('setState', this.connecting || this.updating);
|
||||
window.requestAnimationFrame(() => {
|
||||
SetTransition(this.statusContainer, 'is-shown', this.connecting || this.updating, 200);
|
||||
if(this.setStateTimeout) clearTimeout(this.setStateTimeout);
|
||||
|
||||
const cb = () => {
|
||||
SetTransition(this.statusContainer, 'is-shown', this.connecting || this.updating, 200);
|
||||
this.setStateTimeout = 0;
|
||||
DEBUG && this.log('setState: isShown:', this.connecting || this.updating);
|
||||
};
|
||||
|
||||
this.setStateTimeout = window.setTimeout(cb, timeout);
|
||||
/* if(timeout) this.setStateTimeout = window.setTimeout(cb, timeout);
|
||||
else cb(); */
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -1445,6 +1445,31 @@ export class AppMessagesManager {
|
||||
return pFlags;
|
||||
}
|
||||
|
||||
private generateForwardHeader(peerId: number, originalMessage: Message.message) {
|
||||
const fwdHeader: MessageFwdHeader.messageFwdHeader = {
|
||||
_: 'messageFwdHeader',
|
||||
flags: 0,
|
||||
date: originalMessage.date,
|
||||
from_id: appPeersManager.getOutputPeer(originalMessage.fromId)
|
||||
};
|
||||
|
||||
if(appPeersManager.isBroadcast(originalMessage.peerId)) {
|
||||
if(originalMessage.post_author) {
|
||||
fwdHeader.post_author = originalMessage.post_author;
|
||||
}
|
||||
|
||||
fwdHeader.channel_post = originalMessage.id;
|
||||
}
|
||||
|
||||
// * there is no way to detect whether user profile is hidden
|
||||
if(peerId === appUsersManager.getSelf().id) {
|
||||
fwdHeader.saved_from_msg_id = originalMessage.id;
|
||||
fwdHeader.saved_from_peer = appPeersManager.getOutputPeer(originalMessage.peerId);
|
||||
}
|
||||
|
||||
return fwdHeader;
|
||||
}
|
||||
|
||||
public setDialogTopMessage(message: MyMessage, dialog: MTDialog.dialog = this.getDialogByPeerId(message.peerId)[0]) {
|
||||
if(dialog) {
|
||||
dialog.top_message = message.mid;
|
||||
@ -1700,15 +1725,29 @@ export class AppMessagesManager {
|
||||
});
|
||||
}
|
||||
|
||||
public forwardMessages(peerId: number, fromPeerId: number, msgIds: number[], options: Partial<{
|
||||
public forwardMessages(peerId: number, fromPeerId: number, mids: number[], options: Partial<{
|
||||
withMyScore: true,
|
||||
silent: true,
|
||||
scheduleDate: number
|
||||
}> = {}) {
|
||||
peerId = appPeersManager.getPeerMigratedTo(peerId) || peerId;
|
||||
msgIds = msgIds.slice().sort((a, b) => a - b).map(mid => this.getServerMessageId(mid));
|
||||
mids = mids.slice().sort((a, b) => a - b);
|
||||
|
||||
const randomIds: string[] = msgIds.map(() => randomLong());
|
||||
const newMessages = mids.map(mid => {
|
||||
const originalMessage = this.getMessageByPeer(fromPeerId, mid);
|
||||
const message = this.generateOutgoingMessage(peerId, options);
|
||||
message.fwd_from = this.generateForwardHeader(peerId, originalMessage);
|
||||
|
||||
(['entities', 'forwards', 'message', 'media', 'reply_markup', 'views'] as any as Array<keyof MyMessage>).forEach(key => {
|
||||
message[key] = originalMessage[key];
|
||||
});
|
||||
|
||||
this.beforeMessageSending(message, {
|
||||
isScheduled: !!options.scheduleDate || undefined
|
||||
});
|
||||
|
||||
return message;
|
||||
});
|
||||
|
||||
const sentRequestOptions: InvokeApiOptions = {};
|
||||
if(this.pendingAfterMsgs[peerId]) {
|
||||
@ -1717,13 +1756,14 @@ export class AppMessagesManager {
|
||||
|
||||
const promise = apiManager.invokeApiAfter('messages.forwardMessages', {
|
||||
from_peer: appPeersManager.getInputPeerById(fromPeerId),
|
||||
id: msgIds,
|
||||
random_id: randomIds,
|
||||
id: mids.map(mid => this.getServerMessageId(mid)),
|
||||
random_id: newMessages.map(message => message.random_id),
|
||||
to_peer: appPeersManager.getInputPeerById(peerId),
|
||||
with_my_score: options.withMyScore,
|
||||
silent: options.silent,
|
||||
schedule_date: options.scheduleDate
|
||||
}, sentRequestOptions).then((updates) => {
|
||||
this.log('forwardMessages updates:', updates);
|
||||
apiUpdatesManager.processUpdateMessage(updates);
|
||||
}).finally(() => {
|
||||
if(this.pendingAfterMsgs[peerId] === sentRequestOptions) {
|
||||
|
@ -69,6 +69,7 @@
|
||||
{"name": "peerId", "type": "number"},
|
||||
{"name": "fromId", "type": "number"},
|
||||
{"name": "grouped_id", "type": "string"},
|
||||
{"name": "random_id", "type": "string"},
|
||||
{"name": "unread", "type": "true"},
|
||||
{"name": "is_outgoing", "type": "true"},
|
||||
{"name": "rReply", "type": "string"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user