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

7
src/components/chat/pinnedMessage.ts

@ -244,13 +244,14 @@ export default class ChatPinnedMessage {
constructor(private topbar: ChatTopbar, private chat: Chat, private appMessagesManager: AppMessagesManager, private appPeersManager: AppPeersManager) { constructor(private topbar: ChatTopbar, private chat: Chat, private appMessagesManager: AppMessagesManager, private appPeersManager: AppPeersManager) {
this.listenerSetter = new ListenerSetter(); 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)) { if(appPeersManager.canPinMessage(this.topbar.peerId)) {
new PopupPinMessage(this.topbar.peerId, this.pinnedMid, true); new PopupPinMessage(this.topbar.peerId, this.pinnedMid, true);
return Promise.resolve(false);
} else { } else {
return this.appMessagesManager.hidePinnedMessages(this.topbar.peerId).then(() => true); new PopupPinMessage(this.topbar.peerId, 0, true);
} }
return false;
}); });
this.pinnedMessageBorder = new PinnedMessageBorder(); this.pinnedMessageBorder = new PinnedMessageBorder();

21
src/components/chat/topbar.ts

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

76
src/components/popups/unpinMessage.ts

@ -1,31 +1,83 @@
import appMessagesManager from "../../lib/appManagers/appMessagesManager"; import appMessagesManager from "../../lib/appManagers/appMessagesManager";
import { PopupButton } from "."; import { PopupButton } from ".";
import PopupPeer from "./peer"; import PopupPeer from "./peer";
import appPeersManager from "../../lib/appManagers/appPeersManager";
export default class PopupPinMessage { 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[] = []; 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 пока он будет закрываться 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); }, 300);
}; };
const firstName = appPeersManager.getPeerTitle(peerId, false, true);
if(unpin) { if(unpin) {
title = `Unpin Message?`; let buttonText = 'UNPIN';
description = 'Would you like to unpin this message?'; 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({ buttons.push({
text: 'UNPIN', text: buttonText,
isDanger: true, isDanger: true,
callback callback: () => callback()
}); });
} else { } else {
title = 'Pin Message?'; title = 'Pin Message?';
description = 'Would you like to pin this message?';
buttons.push({ if(peerId < 0) {
text: 'PIN', description = 'Do you want to pin this message for all members in the group?';
callback 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({ buttons.push({

Loading…
Cancel
Save