Browse Source

Fix top_message after deleting

Fix deleting pinned message
master
morethanwords 4 years ago
parent
commit
2db5fadcf9
  1. 2
      src/lib/appManagers/AppInlineBotsManager.ts
  2. 1
      src/lib/appManagers/appChatsManager.ts
  3. 12
      src/lib/appManagers/appImManager.ts
  4. 86
      src/lib/appManagers/appMessagesManager.ts
  5. 17
      src/lib/appManagers/appWebPagesManager.ts
  6. 1
      src/scss/partials/_chatBubble.scss

2
src/lib/appManagers/AppInlineBotsManager.ts

@ -275,7 +275,6 @@ export class AppInlineBotsManager {
let peerID = appMessagesManager.getMessagePeer(message); let peerID = appMessagesManager.getMessagePeer(message);
return apiManagerProxy.invokeApi('messages.getBotCallbackAnswer', { return apiManagerProxy.invokeApi('messages.getBotCallbackAnswer', {
flags: 1,
peer: appPeersManager.getInputPeerByID(peerID), peer: appPeersManager.getInputPeerByID(peerID),
msg_id: appMessagesIDsManager.getMessageLocalID(mid), msg_id: appMessagesIDsManager.getMessageLocalID(mid),
data: button.data data: button.data
@ -293,7 +292,6 @@ export class AppInlineBotsManager {
var peerID = AppMessagesManager.getMessagePeer(message) var peerID = AppMessagesManager.getMessagePeer(message)
return MtpApiManager.invokeApi('messages.getBotCallbackAnswer', { return MtpApiManager.invokeApi('messages.getBotCallbackAnswer', {
flags: 2,
peer: AppPeersManager.getInputPeerByID(peerID), peer: AppPeersManager.getInputPeerByID(peerID),
msg_id: AppMessagesIDsManager.getMessageLocalID(id) msg_id: AppMessagesIDsManager.getMessageLocalID(id)
}, {timeout: 1, stopTime: -1, noErrorBox: true}).then(function (callbackAnswer) { }, {timeout: 1, stopTime: -1, noErrorBox: true}).then(function (callbackAnswer) {

1
src/lib/appManagers/appChatsManager.ts

@ -390,7 +390,6 @@ export class AppChatsManager {
public createChannel(title: string, about: string): Promise<number> { public createChannel(title: string, about: string): Promise<number> {
return apiManager.invokeApi('channels.createChannel', { return apiManager.invokeApi('channels.createChannel', {
flags: 1,
broadcast: true, broadcast: true,
title: title, title: title,
about: about about: about

12
src/lib/appManagers/appImManager.ts

@ -221,10 +221,10 @@ export class AppImManager {
}); });
$rootScope.$on('history_multiappend', (e) => { $rootScope.$on('history_multiappend', (e) => {
let msgIDsByPeer = e.detail; const msgIDsByPeer = e.detail;
if(!(this.peerID in msgIDsByPeer)) return; if(!(this.peerID in msgIDsByPeer)) return;
let msgIDs = msgIDsByPeer[this.peerID]; const msgIDs = msgIDsByPeer[this.peerID];
this.renderNewMessagesByIDs(msgIDs); this.renderNewMessagesByIDs(msgIDs);
appSidebarRight.sharedMediaTab.renderNewMessages(msgIDs); appSidebarRight.sharedMediaTab.renderNewMessages(msgIDs);
@ -321,6 +321,12 @@ export class AppImManager {
bubble.dataset.mid = '' + mid; bubble.dataset.mid = '' + mid;
this.bubbleGroups.removeBubble(bubble, tempID); this.bubbleGroups.removeBubble(bubble, tempID);
if(message.media?.webpage && !bubble.querySelector('.box.web')) {
const mounted = this.getMountedBubble(mid);
if(!mounted) return;
this.renderMessage(mounted.message, true, false, mounted.bubble, false);
}
delete this.bubbles[tempID]; delete this.bubbles[tempID];
} else { } else {
@ -334,7 +340,7 @@ export class AppImManager {
}); });
$rootScope.$on('message_edit', (e) => { $rootScope.$on('message_edit', (e) => {
let {peerID, mid, id, justMedia} = e.detail; const {peerID, mid} = e.detail;
if(peerID != this.peerID) return; if(peerID != this.peerID) return;
const mounted = this.getMountedBubble(mid); const mounted = this.getMountedBubble(mid);

86
src/lib/appManagers/appMessagesManager.ts

@ -454,7 +454,7 @@ type MyInputMessagesFilter = 'inputMessagesFilterEmpty'
export class AppMessagesManager { export class AppMessagesManager {
public messagesStorage: {[mid: string]: any} = {}; public messagesStorage: {[mid: string]: any} = {};
public messagesStorageByPeerID: {[peerID: string]: AppMessagesManager['messagesStorage']} = {}; public messagesStorageByPeerID: {[peerID: string]: AppMessagesManager['messagesStorage']} = {};
public groupedMessagesStorage: {[groupID: string]: any} = {}; // will be used for albums public groupedMessagesStorage: {[groupID: string]: {[mid: string]: any}} = {}; // will be used for albums
public historiesStorage: { public historiesStorage: {
[peerID: string]: HistoryStorage [peerID: string]: HistoryStorage
} = {}; } = {};
@ -747,6 +747,10 @@ export class AppMessagesManager {
const splitted = splitStringByLength(text, MAX_LENGTH); const splitted = splitStringByLength(text, MAX_LENGTH);
text = splitted[0]; text = splitted[0];
if(splitted.length > 1) {
delete options.webPage;
}
for(let i = 1; i < splitted.length; ++i) { for(let i = 1; i < splitted.length; ++i) {
setTimeout(() => { setTimeout(() => {
this.sendText(peerID, splitted[i], options); this.sendText(peerID, splitted[i], options);
@ -1033,11 +1037,8 @@ export class AppMessagesManager {
apiFileName = 'video.mp4'; apiFileName = 'video.mp4';
actionName = 'sendMessageUploadVideoAction'; actionName = 'sendMessageUploadVideoAction';
let flags = 1;
if(options.isRoundMessage) flags |= 2;
let videoAttribute: DocumentAttribute.documentAttributeVideo = { let videoAttribute: DocumentAttribute.documentAttributeVideo = {
_: 'documentAttributeVideo', _: 'documentAttributeVideo',
flags: flags,
pFlags: { // that's only for client, not going to telegram pFlags: { // that's only for client, not going to telegram
supports_streaming: true, supports_streaming: true,
round_message: options.isRoundMessage || undefined round_message: options.isRoundMessage || undefined
@ -1139,14 +1140,12 @@ export class AppMessagesManager {
id: messageID, id: messageID,
from_id: appPeersManager.getOutputPeer(fromID), from_id: appPeersManager.getOutputPeer(fromID),
peer_id: appPeersManager.getOutputPeer(peerID), peer_id: appPeersManager.getOutputPeer(peerID),
flags: flags,
pFlags: pFlags, pFlags: pFlags,
date: date, date: date,
message: caption, message: caption,
media: isDocument ? { media: isDocument ? {
_: 'messageMediaDocument', _: 'messageMediaDocument',
pFlags: {}, pFlags: {},
flags: 1,
document: file document: file
} : media, } : media,
random_id: randomIDS, random_id: randomIDS,
@ -1364,10 +1363,8 @@ export class AppMessagesManager {
}; };
if(file.type.indexOf('video/') === 0) { if(file.type.indexOf('video/') === 0) {
let flags = 1;
let videoAttribute: DocumentAttribute.documentAttributeVideo = { let videoAttribute: DocumentAttribute.documentAttributeVideo = {
_: 'documentAttributeVideo', _: 'documentAttributeVideo',
flags: flags,
pFlags: { // that's only for client, not going to telegram pFlags: { // that's only for client, not going to telegram
supports_streaming: true supports_streaming: true
}, },
@ -1422,7 +1419,6 @@ export class AppMessagesManager {
from_id: appPeersManager.getOutputPeer(fromID), from_id: appPeersManager.getOutputPeer(fromID),
grouped_id: groupID, grouped_id: groupID,
peer_id: appPeersManager.getOutputPeer(peerID), peer_id: appPeersManager.getOutputPeer(peerID),
flags: flags,
pFlags: pFlags, pFlags: pFlags,
date: date, date: date,
message: caption, message: caption,
@ -1532,7 +1528,6 @@ export class AppMessagesManager {
mime_type: file.type, mime_type: file.type,
attributes: [{ attributes: [{
_: 'documentAttributeVideo', _: 'documentAttributeVideo',
flags: 2,
supports_streaming: true, supports_streaming: true,
duration: details.duration, duration: details.duration,
w: details.width, w: details.width,
@ -2860,16 +2855,18 @@ export class AppMessagesManager {
else delete message.pFlags.unread; else delete message.pFlags.unread;
} }
if(this.historiesStorage[peerID] === undefined/* && !message.deleted */) { // warning let historyStorage = this.historiesStorage[peerID];
const historyStorage: HistoryStorage = {count: null, history: [], pending: []}; if(historyStorage === undefined/* && !message.deleted */) { // warning
historyStorage = this.historiesStorage[peerID] = {count: null, history: [], pending: []};
historyStorage[mid > 0 ? 'history' : 'pending'].push(mid); historyStorage[mid > 0 ? 'history' : 'pending'].push(mid);
/* if(mid < 0 && message.pFlags.unread) { /* if(mid < 0 && message.pFlags.unread) {
dialog.unread_count++; dialog.unread_count++;
} */ } */
this.historiesStorage[peerID] = historyStorage;
if(this.mergeReplyKeyboard(historyStorage, message)) { if(this.mergeReplyKeyboard(historyStorage, message)) {
$rootScope.$broadcast('history_reply_markup', {peerID}); $rootScope.$broadcast('history_reply_markup', {peerID});
} }
} else if(!historyStorage.history.length && !historyStorage.pending.length) {
historyStorage[mid > 0 ? 'history' : 'pending'].push(mid);
} }
if(channelID && dialog.pts) { if(channelID && dialog.pts) {
@ -3270,13 +3267,8 @@ export class AppMessagesManager {
}); });
}); });
} else { } else {
let flags = 0;
if(revoke) {
flags |= 1;
}
promise = apiManager.invokeApi('messages.deleteMessages', { promise = apiManager.invokeApi('messages.deleteMessages', {
flags: flags, revoke: revoke || undefined,
id: msgIDs id: msgIDs
}).then((affectedMessages) => { }).then((affectedMessages) => {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processUpdateMessage({
@ -3865,9 +3857,9 @@ export class AppMessagesManager {
const channelID: number = (update as Update.updateDeleteChannelMessages).channel_id; const channelID: number = (update as Update.updateDeleteChannelMessages).channel_id;
const messages = (update as any as Update.updateDeleteChannelMessages).messages; const messages = (update as any as Update.updateDeleteChannelMessages).messages;
for(let i = 0; i < messages.length; i++) { for(const _messageID of messages) {
const messageID = appMessagesIDsManager.getFullMessageID(messages[i], channelID); const mid = appMessagesIDsManager.getFullMessageID(_messageID, channelID);
const message: MyMessage = this.messagesStorage[messageID]; const message: MyMessage = this.messagesStorage[mid];
if(message) { if(message) {
const peerID = this.getMessagePeer(message); const peerID = this.getMessagePeer(message);
const history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}}); const history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}});
@ -3878,7 +3870,7 @@ export class AppMessagesManager {
const smth = c.photo || c.document; const smth = c.photo || c.document;
if(smth?.file_reference) { if(smth?.file_reference) {
referenceDatabase.deleteContext(smth.file_reference, {type: 'message', messageID}); referenceDatabase.deleteContext(smth.file_reference, {type: 'message', messageID: mid});
} }
} }
@ -3886,21 +3878,31 @@ export class AppMessagesManager {
history.unread++; history.unread++;
} }
history.count++; history.count++;
history.msgs[messageID] = true; history.msgs[mid] = true;
message.deleted = true message.deleted = true;
this.messagesStorage[messageID] = {
deleted: true, delete this.messagesStorage[mid];
id: messageID, delete this.messagesStorageByPeerID[peerID][mid];
from_id: message.from_id,
peer_id: message.peer_id, if(message._ != 'messageService' && message.grouped_id) {
pFlags: message.pFlags, const groupedStorage = this.groupedMessagesStorage[message.grouped_id];
date: message.date if(groupedStorage) {
}; delete groupedStorage[mid];
if(!Object.keys(groupedStorage).length) {
delete this.groupedMessagesStorage[message.grouped_id];
}
}
}
if(this.pinnedMessages[peerID] == mid) {
this.savePinnedMessage(peerID, 0);
}
const peerMessagesToHandle = this.newMessagesToHandle[peerID]; const peerMessagesToHandle = this.newMessagesToHandle[peerID];
if(peerMessagesToHandle && peerMessagesToHandle.length) { if(peerMessagesToHandle && peerMessagesToHandle.length) {
const peerMessagesHandlePos = peerMessagesToHandle.indexOf(messageID); const peerMessagesHandlePos = peerMessagesToHandle.indexOf(mid);
if(peerMessagesHandlePos != -1) { if(peerMessagesHandlePos != -1) {
peerMessagesToHandle.splice(peerMessagesHandlePos); peerMessagesToHandle.splice(peerMessagesHandlePos);
} }
@ -3913,13 +3915,8 @@ export class AppMessagesManager {
const updatedData = historiesUpdated[peerID]; const updatedData = historiesUpdated[peerID];
const historyStorage = this.historiesStorage[peerID]; const historyStorage = this.historiesStorage[peerID];
if(historyStorage !== undefined) { if(historyStorage !== undefined) {
const newHistory: number[] = []; const newHistory = historyStorage.history.filter(mid => !updatedData.msgs[mid]);
const newPending: number[] = []; const newPending = historyStorage.pending.filter(mid => !updatedData.msgs[mid]);
for(let i = 0; i < historyStorage.history.length; i++) {
if(!updatedData.msgs[historyStorage.history[i]]) {
newHistory.push(historyStorage.history[i]);
}
}
historyStorage.history = newHistory; historyStorage.history = newHistory;
if(updatedData.count && if(updatedData.count &&
historyStorage.count !== null && historyStorage.count !== null &&
@ -3930,11 +3927,6 @@ export class AppMessagesManager {
} }
} }
for(const mid of historyStorage.pending) {
if(!updatedData.msgs[mid]) {
newPending.push(mid);
}
}
historyStorage.pending = newPending; historyStorage.pending = newPending;
$rootScope.$broadcast('history_delete', {peerID, msgs: updatedData.msgs}); $rootScope.$broadcast('history_delete', {peerID, msgs: updatedData.msgs});

17
src/lib/appManagers/appWebPagesManager.ts

@ -11,7 +11,7 @@ class AppWebPagesManager {
constructor() { constructor() {
$rootScope.$on('apiUpdate', (e) => { $rootScope.$on('apiUpdate', (e) => {
let update = e.detail; const update = e.detail;
switch(update._) { switch(update._) {
case 'updateWebPage': case 'updateWebPage':
@ -39,27 +39,25 @@ class AppWebPagesManager {
delete apiWebPage.document; delete apiWebPage.document;
} }
var siteName = apiWebPage.site_name; const siteName = apiWebPage.site_name;
var shortTitle = apiWebPage.title || apiWebPage.author || siteName || ''; let shortTitle = apiWebPage.title || apiWebPage.author || siteName || '';
if(siteName && shortTitle == siteName) { if(siteName && shortTitle == siteName) {
delete apiWebPage.site_name; delete apiWebPage.site_name;
} }
if(shortTitle.length > 100) { shortTitle = limitSymbols(shortTitle, 80, 100);
shortTitle = shortTitle.substr(0, 80) + '...';
}
apiWebPage.rTitle = RichTextProcessor.wrapRichText(shortTitle, {noLinks: true, noLinebreaks: true}); apiWebPage.rTitle = RichTextProcessor.wrapRichText(shortTitle, {noLinks: true, noLinebreaks: true});
var contextHashtag = ''; let contextHashtag = '';
if(siteName == 'GitHub') { if(siteName == 'GitHub') {
var matches = apiWebPage.url.match(/(https?:\/\/github\.com\/[^\/]+\/[^\/]+)/); const matches = apiWebPage.url.match(/(https?:\/\/github\.com\/[^\/]+\/[^\/]+)/);
if(matches) { if(matches) {
contextHashtag = matches[0] + '/issues/{1}'; contextHashtag = matches[0] + '/issues/{1}';
} }
} }
// delete apiWebPage.description // delete apiWebPage.description
var shortDescriptionText = limitSymbols(apiWebPage.description || '', 150, 180); const shortDescriptionText = limitSymbols(apiWebPage.description || '', 150, 180);
apiWebPage.rDescription = RichTextProcessor.wrapRichText(shortDescriptionText, { apiWebPage.rDescription = RichTextProcessor.wrapRichText(shortDescriptionText, {
contextSite: siteName || 'external', contextSite: siteName || 'external',
contextHashtag: contextHashtag contextHashtag: contextHashtag
@ -80,7 +78,6 @@ class AppWebPagesManager {
} }
this.pendingWebPages[apiWebPage.id][messageID] = true; this.pendingWebPages[apiWebPage.id][messageID] = true;
this.webpages[apiWebPage.id] = apiWebPage;
} }
if(this.webpages[apiWebPage.id] === undefined) { if(this.webpages[apiWebPage.id] === undefined) {

1
src/scss/partials/_chatBubble.scss

@ -679,6 +679,7 @@ $bubble-margin: .25rem;
.box.web { .box.web {
.quote { .quote {
display: flex; display: flex;
justify-content: space-between;
} }
.preview-resizer { .preview-resizer {

Loading…
Cancel
Save