Fix shared media new & deleted messages
This commit is contained in:
parent
c1a419909b
commit
1796dff9ce
@ -201,15 +201,20 @@ export default class AppSharedMediaTab implements SliderTab {
|
|||||||
}); */
|
}); */
|
||||||
}
|
}
|
||||||
|
|
||||||
public renderNewMessages(mids: number[]) {
|
public renderNewMessages(peerID: number, mids: number[]) {
|
||||||
if(this.init) return; // * not inited yet
|
if(this.init) return; // * not inited yet
|
||||||
|
|
||||||
|
if(!this.historiesStorage[peerID]) return;
|
||||||
|
|
||||||
mids = mids.slice().reverse(); // ! because it will be ascend sorted array
|
mids = mids.slice().reverse(); // ! because it will be ascend sorted array
|
||||||
for(const sharedMediaType of this.sharedMediaTypes) {
|
for(const sharedMediaType of this.sharedMediaTypes) {
|
||||||
const filtered = this.filterMessagesByType(mids, sharedMediaType);
|
const filtered = this.filterMessagesByType(mids, sharedMediaType);
|
||||||
if(filtered.length) {
|
if(filtered.length) {
|
||||||
if(this.usedFromHistory[sharedMediaType] !== -1) {
|
if(this.historiesStorage[peerID][sharedMediaType]) {
|
||||||
this.historiesStorage[this.peerID][sharedMediaType].unshift(...mids);
|
this.historiesStorage[peerID][sharedMediaType].unshift(...mids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.peerID == peerID && this.usedFromHistory[sharedMediaType] !== -1) {
|
||||||
this.usedFromHistory[sharedMediaType] += filtered.length;
|
this.usedFromHistory[sharedMediaType] += filtered.length;
|
||||||
this.performSearchResult(filtered, sharedMediaType, false);
|
this.performSearchResult(filtered, sharedMediaType, false);
|
||||||
}
|
}
|
||||||
@ -219,30 +224,34 @@ export default class AppSharedMediaTab implements SliderTab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public deleteDeletedMessages(mids: number[]) {
|
public deleteDeletedMessages(peerID: number, mids: number[]) {
|
||||||
if(this.init) return; // * not inited yet
|
if(this.init) return; // * not inited yet
|
||||||
|
|
||||||
|
if(!this.historiesStorage[peerID]) return;
|
||||||
|
|
||||||
for(const mid of mids) {
|
for(const mid of mids) {
|
||||||
for(const sharedMediaType of this.sharedMediaTypes) {
|
for(const sharedMediaType of this.sharedMediaTypes) {
|
||||||
if(!this.historiesStorage[this.peerID] || !this.historiesStorage[this.peerID][sharedMediaType]) continue;
|
if(!this.historiesStorage[peerID][sharedMediaType]) continue;
|
||||||
|
|
||||||
const history = this.historiesStorage[this.peerID][sharedMediaType];
|
const history = this.historiesStorage[peerID][sharedMediaType];
|
||||||
const idx = history.findIndex(m => m == mid);
|
const idx = history.findIndex(m => m == mid);
|
||||||
if(idx !== -1) {
|
if(idx !== -1) {
|
||||||
history.splice(idx, 1);
|
history.splice(idx, 1);
|
||||||
|
|
||||||
const container = this.sharedMedia[sharedMediaType];
|
if(this.peerID == peerID) {
|
||||||
const div = container.querySelector(`div[data-mid="${mid}"]`);
|
const container = this.sharedMedia[sharedMediaType];
|
||||||
if(div) {
|
const div = container.querySelector(`div[data-mid="${mid}"]`);
|
||||||
if(sharedMediaType == 'inputMessagesFilterPhotoVideo') {
|
if(div) {
|
||||||
delete this.mediaDivsByIDs[mid];
|
if(sharedMediaType == 'inputMessagesFilterPhotoVideo') {
|
||||||
|
delete this.mediaDivsByIDs[mid];
|
||||||
|
}
|
||||||
|
|
||||||
|
div.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.usedFromHistory[sharedMediaType] >= (idx + 1)) {
|
||||||
|
this.usedFromHistory[sharedMediaType]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.usedFromHistory[sharedMediaType] >= (idx + 1)) {
|
|
||||||
this.usedFromHistory[sharedMediaType]--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -222,20 +222,25 @@ export class AppImManager {
|
|||||||
|
|
||||||
$rootScope.$on('history_multiappend', (e) => {
|
$rootScope.$on('history_multiappend', (e) => {
|
||||||
const msgIDsByPeer = e.detail;
|
const msgIDsByPeer = e.detail;
|
||||||
|
|
||||||
|
for(const peerID in msgIDsByPeer) {
|
||||||
|
appSidebarRight.sharedMediaTab.renderNewMessages(+peerID, msgIDsByPeer[peerID]);
|
||||||
|
}
|
||||||
|
|
||||||
if(!(this.peerID in msgIDsByPeer)) return;
|
if(!(this.peerID in msgIDsByPeer)) return;
|
||||||
|
|
||||||
const msgIDs = msgIDsByPeer[this.peerID];
|
const msgIDs = msgIDsByPeer[this.peerID];
|
||||||
|
|
||||||
this.renderNewMessagesByIDs(msgIDs);
|
this.renderNewMessagesByIDs(msgIDs);
|
||||||
appSidebarRight.sharedMediaTab.renderNewMessages(msgIDs);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('history_delete', (e) => {
|
$rootScope.$on('history_delete', (e) => {
|
||||||
const detail = e.detail;
|
const {peerID, msgs} = e.detail;
|
||||||
|
|
||||||
const mids = Object.keys(detail.msgs).map(s => +s);
|
const mids = Object.keys(msgs).map(s => +s);
|
||||||
this.deleteMessagesByIDs(mids);
|
appSidebarRight.sharedMediaTab.deleteDeletedMessages(peerID, mids);
|
||||||
appSidebarRight.sharedMediaTab.deleteDeletedMessages(mids);
|
|
||||||
|
if(peerID == this.peerID) {
|
||||||
|
this.deleteMessagesByIDs(mids);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('dialog_flush', (e) => {
|
$rootScope.$on('dialog_flush', (e) => {
|
||||||
@ -282,7 +287,7 @@ export class AppImManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appSidebarRight.sharedMediaTab.renderNewMessages([mid]);
|
appSidebarRight.sharedMediaTab.renderNewMessages(message.peerID, [mid]);
|
||||||
|
|
||||||
let bubble = this.bubbles[tempID];
|
let bubble = this.bubbles[tempID];
|
||||||
if(bubble) {
|
if(bubble) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user