Browse Source

Local forward first

Delay for connection status change
master
Eduard Kuzmenko 4 years ago
parent
commit
6de93c6fd9
  1. 2
      src/components/chat/bubbles.ts
  2. 2
      src/components/chat/messageRender.ts
  3. 1
      src/layer.d.ts
  4. 78
      src/lib/appManagers/appDialogsManager.ts
  5. 50
      src/lib/appManagers/appMessagesManager.ts
  6. 1
      src/scripts/in/schema_additional_params.json

2
src/components/chat/bubbles.ts

@ -2442,7 +2442,7 @@ export default class ChatBubbles {
bubble.classList.add('is-thread-starter', 'is-group-last'); 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'); const goto = document.createElement('div');
goto.classList.add('bubble-beside-button', 'goto-original', 'tgico-arrow_next'); goto.classList.add('bubble-beside-button', 'goto-original', 'tgico-arrow_next');
bubbleContainer.append(goto); bubbleContainer.append(goto);

2
src/components/chat/messageRender.ts

@ -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'); bubble.classList.add('is-edited');
time = '<i class="edited">edited</i> ' + time; time = '<i class="edited">edited</i> ' + time;
} }

1
src/layer.d.ts vendored

@ -832,6 +832,7 @@ export namespace Message {
deleted?: boolean, deleted?: boolean,
peerId?: number, peerId?: number,
fromId?: number, fromId?: number,
random_id?: string,
rReply?: string rReply?: string
}; };

78
src/lib/appManagers/appDialogsManager.ts

@ -45,6 +45,8 @@ const testScroll = false;
let testTopSlice = 1; let testTopSlice = 1;
class ConnectionStatusComponent { class ConnectionStatusComponent {
public static CHANGE_STATE_DELAY = 1000;
private statusContainer: HTMLElement; private statusContainer: HTMLElement;
private statusEl: HTMLElement; private statusEl: HTMLElement;
private statusPreloader: ProgressivePreloader; private statusPreloader: ProgressivePreloader;
@ -56,6 +58,9 @@ class ConnectionStatusComponent {
private log: ReturnType<typeof logger>; private log: ReturnType<typeof logger>;
private setFirstConnectionTimeout: number;
private setStateTimeout: number;
constructor(chatsContainer: HTMLElement) { constructor(chatsContainer: HTMLElement) {
this.log = logger('CS'); this.log = logger('CS');
@ -73,53 +78,29 @@ class ConnectionStatusComponent {
const status = e; const status = e;
console.log(status); console.log(status);
setConnectionStatus(); this.setConnectionStatus();
}); });
rootScope.on('state_synchronizing', (e) => { rootScope.on('state_synchronizing', (e) => {
const channelId = e; const channelId = e;
if(!channelId) { if(!channelId) {
this.updating = true; this.updating = true;
this.log('updating', this.updating); DEBUG && this.log('updating', this.updating);
this.setState(); this.setState();
} }
}); });
rootScope.on('state_synchronized', (e) => { rootScope.on('state_synchronized', (e) => {
const channelId = e; const channelId = e;
this.log('state_synchronized', channelId); DEBUG && this.log('state_synchronized', channelId);
if(!channelId) { if(!channelId) {
this.updating = false; this.updating = false;
this.log('updating', this.updating); DEBUG && this.log('updating', this.updating);
this.setState(); this.setState();
} }
}); });
const setConnectionStatus = () => { this.setFirstConnectionTimeout = window.setTimeout(this.setConnectionStatus, ConnectionStatusComponent.CHANGE_STATE_DELAY + 1e3);
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);
/* let bool = true; /* let bool = true;
document.addEventListener('dblclick', () => { 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) => { private setStatusText = (text: string) => {
if(this.currentText === text) return; if(this.currentText === text) return;
this.statusEl.innerText = this.currentText = text; this.statusEl.innerText = this.currentText = text;
@ -142,15 +147,26 @@ class ConnectionStatusComponent {
}; };
private setState = () => { private setState = () => {
const timeout = ConnectionStatusComponent.CHANGE_STATE_DELAY;
if(this.connecting) { if(this.connecting) {
this.setStatusText('Waiting for network...'); this.setStatusText('Waiting for network...');
} else if(this.updating) { } else if(this.updating) {
this.setStatusText('Updating...'); this.setStatusText('Updating...');
} }
this.log('setState', this.connecting || this.updating); DEBUG && this.log('setState', this.connecting || this.updating);
window.requestAnimationFrame(() => { 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(); */
}); });
}; };
} }

50
src/lib/appManagers/appMessagesManager.ts

@ -1445,6 +1445,31 @@ export class AppMessagesManager {
return pFlags; 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]) { public setDialogTopMessage(message: MyMessage, dialog: MTDialog.dialog = this.getDialogByPeerId(message.peerId)[0]) {
if(dialog) { if(dialog) {
dialog.top_message = message.mid; 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, withMyScore: true,
silent: true, silent: true,
scheduleDate: number scheduleDate: number
}> = {}) { }> = {}) {
peerId = appPeersManager.getPeerMigratedTo(peerId) || peerId; 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 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];
});
const randomIds: string[] = msgIds.map(() => randomLong()); this.beforeMessageSending(message, {
isScheduled: !!options.scheduleDate || undefined
});
return message;
});
const sentRequestOptions: InvokeApiOptions = {}; const sentRequestOptions: InvokeApiOptions = {};
if(this.pendingAfterMsgs[peerId]) { if(this.pendingAfterMsgs[peerId]) {
@ -1717,13 +1756,14 @@ export class AppMessagesManager {
const promise = apiManager.invokeApiAfter('messages.forwardMessages', { const promise = apiManager.invokeApiAfter('messages.forwardMessages', {
from_peer: appPeersManager.getInputPeerById(fromPeerId), from_peer: appPeersManager.getInputPeerById(fromPeerId),
id: msgIds, id: mids.map(mid => this.getServerMessageId(mid)),
random_id: randomIds, random_id: newMessages.map(message => message.random_id),
to_peer: appPeersManager.getInputPeerById(peerId), to_peer: appPeersManager.getInputPeerById(peerId),
with_my_score: options.withMyScore, with_my_score: options.withMyScore,
silent: options.silent, silent: options.silent,
schedule_date: options.scheduleDate schedule_date: options.scheduleDate
}, sentRequestOptions).then((updates) => { }, sentRequestOptions).then((updates) => {
this.log('forwardMessages updates:', updates);
apiUpdatesManager.processUpdateMessage(updates); apiUpdatesManager.processUpdateMessage(updates);
}).finally(() => { }).finally(() => {
if(this.pendingAfterMsgs[peerId] === sentRequestOptions) { if(this.pendingAfterMsgs[peerId] === sentRequestOptions) {

1
src/scripts/in/schema_additional_params.json

@ -69,6 +69,7 @@
{"name": "peerId", "type": "number"}, {"name": "peerId", "type": "number"},
{"name": "fromId", "type": "number"}, {"name": "fromId", "type": "number"},
{"name": "grouped_id", "type": "string"}, {"name": "grouped_id", "type": "string"},
{"name": "random_id", "type": "string"},
{"name": "unread", "type": "true"}, {"name": "unread", "type": "true"},
{"name": "is_outgoing", "type": "true"}, {"name": "is_outgoing", "type": "true"},
{"name": "rReply", "type": "string"} {"name": "rReply", "type": "string"}

Loading…
Cancel
Save