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

1
src/lib/appManagers/appChatsManager.ts

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

12
src/lib/appManagers/appImManager.ts

@ -221,10 +221,10 @@ export class AppImManager { @@ -221,10 +221,10 @@ export class AppImManager {
});
$rootScope.$on('history_multiappend', (e) => {
let msgIDsByPeer = e.detail;
const msgIDsByPeer = e.detail;
if(!(this.peerID in msgIDsByPeer)) return;
let msgIDs = msgIDsByPeer[this.peerID];
const msgIDs = msgIDsByPeer[this.peerID];
this.renderNewMessagesByIDs(msgIDs);
appSidebarRight.sharedMediaTab.renderNewMessages(msgIDs);
@ -322,6 +322,12 @@ export class AppImManager { @@ -322,6 +322,12 @@ export class AppImManager {
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];
} else {
this.log.warn('message_sent there is no bubble', e.detail);
@ -334,7 +340,7 @@ export class AppImManager { @@ -334,7 +340,7 @@ export class AppImManager {
});
$rootScope.$on('message_edit', (e) => {
let {peerID, mid, id, justMedia} = e.detail;
const {peerID, mid} = e.detail;
if(peerID != this.peerID) return;
const mounted = this.getMountedBubble(mid);

84
src/lib/appManagers/appMessagesManager.ts

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

17
src/lib/appManagers/appWebPagesManager.ts

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

1
src/scss/partials/_chatBubble.scss

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

Loading…
Cancel
Save