Browse Source

Pinned message setting confirmations

Fix hiding hidden pinned messages
master
Eduard Kuzmenko 4 years ago
parent
commit
223fe64ac1
  1. 10
      src/components/chat/input.ts
  2. 7
      src/components/chat/pinnedMessage.ts
  3. 21
      src/components/chat/topbar.ts
  4. 76
      src/components/popups/unpinMessage.ts

10
src/components/chat/input.ts

@ -31,6 +31,7 @@ import Button from '../button'; @@ -31,6 +31,7 @@ import Button from '../button';
import PopupSchedule from '../popups/schedule';
import SendMenu from './sendContextMenu';
import rootScope from '../../lib/rootScope';
import PopupPinMessage from '../popups/unpinMessage';
const RECORD_MIN_TIME = 500;
const POSTING_MEDIA_NOT_ALLOWED = 'Posting media content isn\'t allowed in this group.';
@ -403,14 +404,7 @@ export default class ChatInput { @@ -403,14 +404,7 @@ export default class ChatInput {
this.listenerSetter.add(this.pinnedControlBtn, 'click', () => {
const peerId = this.chat.peerId;
let promise: Promise<any>;
if(this.appPeersManager.canPinMessage(peerId)) {
promise = this.appMessagesManager.unpinAllMessages(peerId);
} else {
promise = this.appMessagesManager.hidePinnedMessages(peerId);
}
promise.then(() => {
new PopupPinMessage(peerId, 0, true, () => {
this.chat.appImManager.setPeer(0); // * close tab
// ! костыль, это скроет закреплённые сообщения сразу, вместо того, чтобы ждать пока анимация перехода закончится

7
src/components/chat/pinnedMessage.ts

@ -244,13 +244,14 @@ export default class ChatPinnedMessage { @@ -244,13 +244,14 @@ export default class ChatPinnedMessage {
constructor(private topbar: ChatTopbar, private chat: Chat, private appMessagesManager: AppMessagesManager, private appPeersManager: AppPeersManager) {
this.listenerSetter = new ListenerSetter();
this.pinnedMessageContainer = new PinnedContainer(topbar, chat, this.listenerSetter, 'message', new ReplyContainer('pinned-message'), () => {
this.pinnedMessageContainer = new PinnedContainer(topbar, chat, this.listenerSetter, 'message', new ReplyContainer('pinned-message'), async() => {
if(appPeersManager.canPinMessage(this.topbar.peerId)) {
new PopupPinMessage(this.topbar.peerId, this.pinnedMid, true);
return Promise.resolve(false);
} else {
return this.appMessagesManager.hidePinnedMessages(this.topbar.peerId).then(() => true);
new PopupPinMessage(this.topbar.peerId, 0, true);
}
return false;
});
this.pinnedMessageBorder = new PinnedMessageBorder();

21
src/components/chat/topbar.ts

@ -266,13 +266,20 @@ export default class ChatTopbar { @@ -266,13 +266,20 @@ export default class ChatTopbar {
});
this.chat.addListener('setPeer', (mid, isTopMessage) => {
if(isTopMessage) {
this.pinnedMessage.unsetScrollDownListener();
this.pinnedMessage.testMid(mid, 0); // * because slider will not let get bubble by document.elementFromPoint
} else if(!this.pinnedMessage.locked) {
this.pinnedMessage.handleFollowingPinnedMessage();
this.pinnedMessage.testMid(mid);
}
const middleware = this.chat.bubbles.getMiddleware();
appStateManager.getState().then((state) => {
if(!middleware()) return;
this.pinnedMessage.hidden = !!state.hiddenPinnedMessages[this.chat.peerId];
if(isTopMessage) {
this.pinnedMessage.unsetScrollDownListener();
this.pinnedMessage.testMid(mid, 0); // * because slider will not let get bubble by document.elementFromPoint
} else if(!this.pinnedMessage.locked) {
this.pinnedMessage.handleFollowingPinnedMessage();
this.pinnedMessage.testMid(mid);
}
});
});
this.setPeerStatusInterval = window.setInterval(this.setPeerStatus, 60e3);

76
src/components/popups/unpinMessage.ts

@ -1,31 +1,83 @@ @@ -1,31 +1,83 @@
import appMessagesManager from "../../lib/appManagers/appMessagesManager";
import { PopupButton } from ".";
import PopupPeer from "./peer";
import appPeersManager from "../../lib/appManagers/appPeersManager";
export default class PopupPinMessage {
constructor(peerId: number, mid: number, unpin?: true) {
constructor(peerId: number, mid: number, unpin?: true, onConfirm?: () => void) {
let title: string, description: string, buttons: PopupButton[] = [];
const callback = () => {
const canUnpin = appPeersManager.canPinMessage(peerId);
const callback = (oneSide?: true, silent?: true) => {
setTimeout(() => { // * костыль, потому что document.elementFromPoint вернёт popup-peer пока он будет закрываться
appMessagesManager.updatePinnedMessage(peerId, mid, unpin);
let promise: Promise<any>;
if(unpin && !mid) {
if(canUnpin) {
promise = appMessagesManager.unpinAllMessages(peerId);
} else {
promise = appMessagesManager.hidePinnedMessages(peerId);
}
} else {
promise = appMessagesManager.updatePinnedMessage(peerId, mid, unpin, silent, oneSide);
}
if(onConfirm) {
promise.then(onConfirm);
}
}, 300);
};
const firstName = appPeersManager.getPeerTitle(peerId, false, true);
if(unpin) {
title = `Unpin Message?`;
description = 'Would you like to unpin this message?';
let buttonText = 'UNPIN';
if(!mid) {
if(canUnpin) {
title = 'Unpin All Messages?';
description = 'Would you like to unpin all messages?';
} else {
title = 'Hide Pinned Messages?';
description = 'Do you want to hide the pinned message bar? It wil stay hidden until a new message is pinned.';
buttonText = 'HIDE';
}
} else {
title = `Unpin Message?`;
description = 'Would you like to unpin this message?';
}
buttons.push({
text: 'UNPIN',
text: buttonText,
isDanger: true,
callback
callback: () => callback()
});
} else {
title = 'Pin Message?';
description = 'Would you like to pin this message?';
buttons.push({
text: 'PIN',
callback
});
if(peerId < 0) {
description = 'Do you want to pin this message for all members in the group?';
buttons.push({
text: 'PIN AND NOTIFY',
callback: () => callback()
});
buttons.push({
text: 'PIN WITHOUT NOTIFYING',
callback: () => callback(undefined, true)
});
} else {
description = 'Would you like to pin this message?';
buttons.push({
text: 'PIN JUST FOR ME',
callback: () => callback(true)
});
buttons.push({
text: 'PIN FOR ME AND ' + firstName,
callback: () => callback()
});
}
}
buttons.push({

Loading…
Cancel
Save