Browse Source

Show previews for documents after uploading

master
Eduard Kuzmenko 4 years ago
parent
commit
9628db6a2b
  1. 4
      src/components/appMediaViewer.ts
  2. 11
      src/components/chat/bubbles.ts
  3. 2
      src/components/chat/chat.ts
  4. 20
      src/components/chat/input.ts
  5. 4
      src/components/sidebarLeft/tabs/addMembers.ts
  6. 4
      src/components/sidebarLeft/tabs/editFolder.ts
  7. 2
      src/components/sidebarLeft/tabs/includedChats.ts
  8. 2
      src/components/sidebarRight/tabs/gifs.ts
  9. 2
      src/components/sidebarRight/tabs/pollResults.ts
  10. 8
      src/components/slider.ts
  11. 2
      src/lib/appManagers/appImManager.ts
  12. 4
      src/scss/partials/pages/_pages.scss

4
src/components/appMediaViewer.ts

@ -23,7 +23,7 @@ import { renderImageFromUrl } from "./misc";
import PopupForward from "./popups/forward"; import PopupForward from "./popups/forward";
import ProgressivePreloader from "./preloader"; import ProgressivePreloader from "./preloader";
import Scrollable from "./scrollable"; import Scrollable from "./scrollable";
import appSidebarRight from "./sidebarRight"; import appSidebarRight, { AppSidebarRight } from "./sidebarRight";
import SwipeHandler from "./swipeHandler"; import SwipeHandler from "./swipeHandler";
import { months, ONE_DAY } from "../helpers/date"; import { months, ONE_DAY } from "../helpers/date";
@ -1190,7 +1190,7 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
//.then(() => mediaSizes.isMobile ? appSidebarRight.sharedMediaTab.closeBtn.click() : Promise.resolve()) //.then(() => mediaSizes.isMobile ? appSidebarRight.sharedMediaTab.closeBtn.click() : Promise.resolve())
.then(() => { .then(() => {
if(mediaSizes.isMobile) { if(mediaSizes.isMobile) {
appSidebarRight.sharedMediaTab.closeBtn.click(); appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.sharedMedia);
} }
const message = appMessagesManager.getMessageByPeer(this.peerId, mid); const message = appMessagesManager.getMessageByPeer(this.peerId, mid);

11
src/components/chat/bubbles.ts

@ -176,6 +176,13 @@ export default class ChatBubbles {
/////this.log('message_sent', bubble); /////this.log('message_sent', bubble);
if(message.media?.document && !message.media.document.type) {
const div = bubble.querySelector(`.document-container[data-mid="${tempId}"] .document`) as AudioElement;
if(div) {
div.replaceWith(wrapDocument({message}));
}
}
// set new mids to album items for mediaViewer // set new mids to album items for mediaViewer
if(message.grouped_id) { if(message.grouped_id) {
const item = (bubble.querySelector(`.grouped-item[data-mid="${tempId}"]`) as HTMLElement) || bubble; // * it can be .document-container const item = (bubble.querySelector(`.grouped-item[data-mid="${tempId}"]`) as HTMLElement) || bubble; // * it can be .document-container
@ -192,12 +199,14 @@ export default class ChatBubbles {
} }
} }
if(['audio', 'voice'].includes(message.media?.document?.type)) { if(message.media?.document) {
if(['audio', 'voice'].includes(message.media.document.type)) {
const audio = bubble.querySelector(`audio-element[message-id="${tempId}"]`) as AudioElement; const audio = bubble.querySelector(`audio-element[message-id="${tempId}"]`) as AudioElement;
audio.setAttribute('doc-id', message.media.document.id); audio.setAttribute('doc-id', message.media.document.id);
audio.setAttribute('message-id', '' + mid); audio.setAttribute('message-id', '' + mid);
audio.message = message; audio.message = message;
} }
}
/* bubble.classList.remove('is-sending'); /* bubble.classList.remove('is-sending');
bubble.classList.add('is-sent'); bubble.classList.add('is-sent');

2
src/components/chat/chat.ts

@ -160,7 +160,7 @@ export default class Chat extends EventListenerBase<{
// set new // set new
if(!samePeer) { if(!samePeer) {
if(appSidebarRight.historyTabIds[appSidebarRight.historyTabIds.length - 1] == AppSidebarRight.SLIDERITEMSIDS.search) { if(appSidebarRight.historyTabIds[appSidebarRight.historyTabIds.length - 1] == AppSidebarRight.SLIDERITEMSIDS.search) {
appSidebarRight.searchTab.closeBtn?.click(); appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.search);
} }
this.peerId = peerId; this.peerId = peerId;

20
src/components/chat/input.ts

@ -345,13 +345,7 @@ export default class ChatInput {
attachClickEvent(this.btnSend, this.onBtnSendClick, {listenerSetter: this.listenerSetter, touchMouseDown: true}); attachClickEvent(this.btnSend, this.onBtnSendClick, {listenerSetter: this.listenerSetter, touchMouseDown: true});
if(this.recorder) { if(this.recorder) {
const onCancelRecordClick = (e: Event) => { attachClickEvent(this.btnCancelRecord, this.onCancelRecordClick, {listenerSetter: this.listenerSetter});
cancelEvent(e);
this.recordCanceled = true;
this.recorder.stop();
opusDecodeController.setKeepAlive(false);
};
attachClickEvent(this.btnCancelRecord, onCancelRecordClick, {listenerSetter: this.listenerSetter});
this.recorder.onstop = () => { this.recorder.onstop = () => {
this.recording = false; this.recording = false;
@ -422,6 +416,16 @@ export default class ChatInput {
this.rowsWrapper.classList.add('is-centered'); this.rowsWrapper.classList.add('is-centered');
} }
private onCancelRecordClick = (e?: Event) => {
if(e) {
cancelEvent(e);
}
this.recordCanceled = true;
this.recorder.stop();
opusDecodeController.setKeepAlive(false);
};
private onEmoticonsOpen = () => { private onEmoticonsOpen = () => {
const toggleClass = isTouchSupported ? 'flip-icon' : 'active'; const toggleClass = isTouchSupported ? 'flip-icon' : 'active';
this.btnToggleEmoticons.classList.toggle(toggleClass, true); this.btnToggleEmoticons.classList.toggle(toggleClass, true);
@ -900,7 +904,7 @@ export default class ChatInput {
if(!this.recorder || this.recording || !this.isInputEmpty() || this.forwardingMids.length || this.editMsgId) { if(!this.recorder || this.recording || !this.isInputEmpty() || this.forwardingMids.length || this.editMsgId) {
if(this.recording) { if(this.recording) {
if((Date.now() - this.recordStartTime) < RECORD_MIN_TIME) { if((Date.now() - this.recordStartTime) < RECORD_MIN_TIME) {
this.btnCancelRecord.click(); this.onCancelRecordClick();
} else { } else {
this.recorder.stop(); this.recorder.stop();
} }

4
src/components/sidebarLeft/tabs/addMembers.ts

@ -18,7 +18,7 @@ export default class AppAddMembersTab implements SliderTab {
constructor() { constructor() {
this.nextBtn.addEventListener('click', () => { this.nextBtn.addEventListener('click', () => {
if(this.skippable) { if(this.skippable) {
this.backBtn.click(); appSidebarLeft.closeTab(AppSidebarLeft.SLIDERITEMSIDS.addMembers);
return; return;
} }
@ -35,7 +35,7 @@ export default class AppAddMembersTab implements SliderTab {
this.selector.freezed = true; this.selector.freezed = true;
appChatsManager.inviteToChannel(this.peerId, peerIds).then(() => { appChatsManager.inviteToChannel(this.peerId, peerIds).then(() => {
this.backBtn.click(); appSidebarLeft.closeTab(AppSidebarLeft.SLIDERITEMSIDS.addMembers);
}); });
} }
}); });

4
src/components/sidebarLeft/tabs/editFolder.ts

@ -91,7 +91,7 @@ export default class AppEditFolderTab implements SliderTab {
this.deleteFolderBtn.setAttribute('disabled', 'true'); this.deleteFolderBtn.setAttribute('disabled', 'true');
appMessagesManager.filtersStorage.updateDialogFilter(this.filter, true).then(bool => { appMessagesManager.filtersStorage.updateDialogFilter(this.filter, true).then(bool => {
if(bool) { if(bool) {
this.closeBtn.click(); appSidebarLeft.closeTab(AppSidebarLeft.SLIDERITEMSIDS.editFolder);
} }
}).finally(() => { }).finally(() => {
this.deleteFolderBtn.removeAttribute('disabled'); this.deleteFolderBtn.removeAttribute('disabled');
@ -127,7 +127,7 @@ export default class AppEditFolderTab implements SliderTab {
promise.then(bool => { promise.then(bool => {
if(bool) { if(bool) {
this.closeBtn.click(); appSidebarLeft.closeTab(AppSidebarLeft.SLIDERITEMSIDS.editFolder);
} }
}).catch(err => { }).catch(err => {
if(err.type == 'DIALOG_FILTERS_TOO_MUCH') { if(err.type == 'DIALOG_FILTERS_TOO_MUCH') {

2
src/components/sidebarLeft/tabs/includedChats.ts

@ -86,7 +86,7 @@ export default class AppIncludedChatsTab implements SliderTab {
//this.filter.pinned_peers = this.filter.pinned_peers.filter(peerId => this.filter.include_peers.includes(peerId)); //this.filter.pinned_peers = this.filter.pinned_peers.filter(peerId => this.filter.include_peers.includes(peerId));
appSidebarLeft.editFolderTab.setFilter(this.filter, false); appSidebarLeft.editFolderTab.setFilter(this.filter, false);
this.closeBtn.click(); appSidebarLeft.closeTab(AppSidebarLeft.SLIDERITEMSIDS.includedChats);
}); });
} }

2
src/components/sidebarRight/tabs/gifs.ts

@ -52,7 +52,7 @@ export default class AppGifsTab implements SliderTab {
const fileId = target.dataset.docId; const fileId = target.dataset.docId;
if(appImManager.chat.input.sendMessageWithDocument(fileId)) { if(appImManager.chat.input.sendMessageWithDocument(fileId)) {
if(mediaSizes.isMobile) { if(mediaSizes.isMobile) {
this.backBtn.click(); appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.gifs);
} }
} else { } else {
console.warn('got no doc by id:', fileId); console.warn('got no doc by id:', fileId);

2
src/components/sidebarRight/tabs/pollResults.ts

@ -71,7 +71,7 @@ export default class AppPollResultsTab implements SliderTab {
list.classList.add('poll-results-voters'); list.classList.add('poll-results-voters');
appDialogsManager.setListClickListener(list, () => { appDialogsManager.setListClickListener(list, () => {
this.closeBtn.click(); appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.pollResults);
}, undefined, true); }, undefined, true);
list.style.minHeight = Math.min(result.voters, 4) * 50 + 'px'; list.style.minHeight = Math.min(result.voters, 4) * 50 + 'px';

8
src/components/slider.ts

@ -47,7 +47,7 @@ export default class SidebarSlider {
} }
public closeTab = (tabId?: number) => { public closeTab = (tabId?: number) => {
if(tabId !== undefined && this.historyTabIds[this.historyTabIds.length - 1] != tabId) { if(tabId !== undefined && this.historyTabIds[this.historyTabIds.length - 1] !== tabId) {
return false; return false;
} }
@ -63,7 +63,7 @@ export default class SidebarSlider {
id = id.id; id = id.id;
} }
if(this.historyTabIds[this.historyTabIds.length - 1] == id) { if(this.historyTabIds[this.historyTabIds.length - 1] === id) {
return false; return false;
} }
@ -86,7 +86,7 @@ export default class SidebarSlider {
} }
public removeTabFromHistory(id: number) { public removeTabFromHistory(id: number) {
this.historyTabIds.findAndSplice(i => i == id); this.historyTabIds.findAndSplice(i => i === id);
this.onCloseTab(id); this.onCloseTab(id);
} }
@ -108,7 +108,7 @@ export default class SidebarSlider {
public addTab(tab: SuperSliderTab) { public addTab(tab: SuperSliderTab) {
let id: number; let id: number;
if(tab.container.parentElement) { if(tab.container.parentElement) {
id = Array.from(this.sidebarEl.children).findIndex(el => el == tab.container); id = Array.from(this.sidebarEl.children).findIndex(el => el === tab.container);
} else { } else {
id = this.sidebarEl.childElementCount; id = this.sidebarEl.childElementCount;
this.sidebarEl.append(tab.container); this.sidebarEl.append(tab.container);

2
src/lib/appManagers/appImManager.ts

@ -449,7 +449,7 @@ export class AppImManager {
rootScope.broadcast('peer_changed', this.chat.peerId); rootScope.broadcast('peer_changed', this.chat.peerId);
if(appSidebarRight.historyTabIds[appSidebarRight.historyTabIds.length - 1] === AppSidebarRight.SLIDERITEMSIDS.search) { if(appSidebarRight.historyTabIds[appSidebarRight.historyTabIds.length - 1] === AppSidebarRight.SLIDERITEMSIDS.search) {
appSidebarRight.searchTab.closeBtn?.click(); appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.search);
} }
appSidebarRight.sharedMediaTab.setPeer(this.chat.peerId, this.chat.threadId); appSidebarRight.sharedMediaTab.setPeer(this.chat.peerId, this.chat.threadId);

4
src/scss/partials/pages/_pages.scss

@ -40,6 +40,10 @@
min-height: 3rem; min-height: 3rem;
/* height: 105px; */ /* height: 105px; */
width: 100%; width: 100%;
/* @media screen and (min-height: 810px) {
height: 22vh;
} */
} }
} }

Loading…
Cancel
Save