Browse Source

Added 'Send as...' menu

master
Eduard Kuzmenko 3 years ago
parent
commit
a29a42cd44
  1. 8
      src/components/chat/bubbles.ts
  2. 54
      src/components/chat/input.ts
  3. 4
      src/components/peerProfile.ts
  4. 4
      src/components/sidebarLeft/tabs/settings.ts
  5. 2
      src/config/app.ts
  6. 2
      src/lang.ts

8
src/components/chat/bubbles.ts

@ -3069,6 +3069,8 @@ export default class ChatBubbles { @@ -3069,6 +3069,8 @@ export default class ChatBubbles {
const isOut = our && (!fwdFrom || this.peerId !== rootScope.myId);
let nameContainer: HTMLElement = bubbleContainer;
const canHideNameIfMedia = !message.viaBotId && message.fromId === rootScope.myId;
// media
if(messageMedia/* && messageMedia._ === 'messageMediaPhoto' */) {
let attachmentDiv = document.createElement('div');
@ -3089,7 +3091,7 @@ export default class ChatBubbles { @@ -3089,7 +3091,7 @@ export default class ChatBubbles {
canHaveTail = false;
}
if(!message.viaBotId) {
if(canHideNameIfMedia) {
bubble.classList.add('hide-name');
}
@ -3333,7 +3335,7 @@ export default class ChatBubbles { @@ -3333,7 +3335,7 @@ export default class ChatBubbles {
canHaveTail = false;
}
if(!message.viaBotId) {
if(canHideNameIfMedia) {
bubble.classList.add('hide-name');
}
@ -3540,7 +3542,7 @@ export default class ChatBubbles { @@ -3540,7 +3542,7 @@ export default class ChatBubbles {
let savedFrom = '';
// const needName = ((peerId.isAnyChat() && (peerId !== message.fromId || our)) && message.fromId !== rootScope.myId) || message.viaBotId;
const needName = (message.fromId !== rootScope.myId && this.appPeersManager.isAnyChat(peerId) && !this.appPeersManager.isBroadcast(peerId)) || message.viaBotId || (message as Message.message).pFlags.sponsored;
const needName = (message.fromId !== rootScope.myId && this.appPeersManager.isAnyGroup(peerId)) || message.viaBotId || (message as Message.message).pFlags.sponsored;
if(needName || fwdFrom || message.reply_to_mid) { // chat
let title: HTMLElement | DocumentFragment;
let titleVia: typeof title;

54
src/components/chat/input.ts

@ -220,6 +220,7 @@ export default class ChatInput { @@ -220,6 +220,7 @@ export default class ChatInput {
private sendAsBtnMenu: HTMLElement;
private sendAsPeerIds: PeerId[];
public sendAsPeerId: PeerId;
private updatingSendAsPromise: Promise<void>;
// private activeContainer: HTMLElement;
@ -1232,6 +1233,7 @@ export default class ChatInput { @@ -1232,6 +1233,7 @@ export default class ChatInput {
sendAsContainer.remove();
SetTransition(this.newMessageWrapper, 'has-send-as', false, 0);
this.sendAsPeerId = undefined;
this.updatingSendAsPromise = undefined;
this.updateSendAs(true);
}
@ -1266,6 +1268,8 @@ export default class ChatInput { @@ -1266,6 +1268,8 @@ export default class ChatInput {
subtitle.classList.add('btn-menu-item-subtitle');
if(sendAsPeerId.isUser()) {
subtitle.append(i18n('Chat.SendAs.PersonalAccount'));
} else if(sendAsPeerId === this.chat.peerId) {
subtitle.append(i18n('VoiceChat.DiscussionGroup'));
} else {
subtitle.append(this.appProfileManager.getChatMembersString(sendAsPeerId.toChatId()));
}
@ -1284,6 +1288,7 @@ export default class ChatInput { @@ -1284,6 +1288,7 @@ export default class ChatInput {
channelFull.default_send_as = this.appPeersManager.getOutputPeer(sendAsPeerId);
this.sendAsPeerId = sendAsPeerId;
this.updateSendAsAvatar(sendAsPeerId);
this.updateMessageInputPlaceholder();
const middleware = this.chat.bubbles.getMiddleware();
const executeButtonsUpdate = () => {
@ -1368,11 +1373,14 @@ export default class ChatInput { @@ -1368,11 +1373,14 @@ export default class ChatInput {
private updateSendAs(skipAnimation?: boolean) {
const peerId = this.chat.peerId;
if(!peerId.isChannel()) {
if(!peerId.isChannel() || this.updatingSendAsPromise) {
return;
}
const middleware = this.chat.bubbles.getMiddleware();
const middleware = this.chat.bubbles.getMiddleware(() => {
return !this.updatingSendAsPromise || this.updatingSendAsPromise === updatingSendAsPromise;
});
const {sendAsContainer} = this;
const chatId = peerId.toChatId();
const result = this.getDefaultSendAs();
@ -1382,11 +1390,12 @@ export default class ChatInput { @@ -1382,11 +1390,12 @@ export default class ChatInput {
skipAnimation = undefined;
}
callbackify(result, (sendAsPeerId) => {
const updateSendAsResult = callbackify(result, (sendAsPeerId) => {
if(!middleware() || sendAsPeerId === undefined) return;
this.sendAsPeerId = sendAsPeerId;
this.updateSendAsAvatar(sendAsPeerId, skipAnimation);
this.updateMessageInputPlaceholder();
this.appChatsManager.getSendAs(chatId).then(peers => {
if(!middleware()) return;
@ -1406,30 +1415,25 @@ export default class ChatInput { @@ -1406,30 +1415,25 @@ export default class ChatInput {
}
SetTransition(this.newMessageWrapper, 'has-send-as', true, skipAnimation ? 0 : SEND_AS_ANIMATION_DURATION, undefined, useRafs);
this.updatingSendAsPromise = undefined;
});
}
public updateMessageInput() {
const {chatInput, attachMenu, messageInput} = this;
const {peerId, threadId} = this.chat;
const canWrite = this.chat.canSend();
const isHidden = chatInput.classList.contains('is-hidden');
const willBeHidden = !canWrite;
if(isHidden !== willBeHidden) {
chatInput.classList.add('no-transition');
chatInput.classList.toggle('is-hidden', !canWrite);
void chatInput.offsetLeft; // reflow
chatInput.classList.remove('no-transition');
const updatingSendAsPromise = this.updatingSendAsPromise = Promise.resolve(updateSendAsResult);
return updatingSendAsPromise;
}
const i = I18n.weakMap.get(messageInput) as I18n.IntlElement;
private updateMessageInputPlaceholder() {
const i = I18n.weakMap.get(this.messageInput) as I18n.IntlElement;
if(i) {
const {peerId, threadId} = this.chat;
let key: LangPackKey;
if(threadId) {
key = 'Comment';
} else if(this.appPeersManager.isBroadcast(peerId)) {
key = 'ChannelBroadcast';
} else if(this.appMessagesManager.isAnonymousSending(peerId)) {
} else if((this.sendAsPeerId !== undefined && this.sendAsPeerId !== rootScope.myId) ||
this.appMessagesManager.isAnonymousSending(peerId)) {
key = 'SendAnonymously';
} else {
key = 'Message';
@ -1437,6 +1441,22 @@ export default class ChatInput { @@ -1437,6 +1441,22 @@ export default class ChatInput {
i.compareAndUpdate({key});
}
}
public updateMessageInput() {
const {chatInput, attachMenu, messageInput} = this;
const {peerId, threadId} = this.chat;
const canWrite = this.chat.canSend();
const isHidden = chatInput.classList.contains('is-hidden');
const willBeHidden = !canWrite;
if(isHidden !== willBeHidden) {
chatInput.classList.add('no-transition');
chatInput.classList.toggle('is-hidden', !canWrite);
void chatInput.offsetLeft; // reflow
chatInput.classList.remove('no-transition');
}
this.updateMessageInputPlaceholder();
const visible = this.attachMenuButtons.filter(button => {
const good = button.verify(peerId, threadId);

4
src/components/peerProfile.ts

@ -232,9 +232,9 @@ export default class PeerProfile { @@ -232,9 +232,9 @@ export default class PeerProfile {
}
public setPeerStatus = (needClear = false) => {
if(!this.peerId) return;
const peerId = this.peerId;
if(!peerId || rootScope.myId === peerId) return;
appImManager.setPeerStatus(this.peerId, this.subtitle, needClear, true, () => peerId === this.peerId, !this.isDialog);
};

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

@ -28,6 +28,7 @@ import { AccountAuthorizations, Authorization } from "/Users/kuzmenko/Documents/ @@ -28,6 +28,7 @@ import { AccountAuthorizations, Authorization } from "/Users/kuzmenko/Documents/
import { SliderSuperTabConstructable } from "../../sliderTab";
import PopupAvatar from "../../popups/avatar";
import appProfileManager from "../../../lib/appManagers/appProfileManager";
import appUsersManager from "../../../lib/appManagers/appUsersManager";
//import AppMediaViewer from "../../appMediaViewerNew";
export default class AppSettingsTab extends SliderSuperTab {
@ -78,6 +79,8 @@ export default class AppSettingsTab extends SliderSuperTab { @@ -78,6 +79,8 @@ export default class AppSettingsTab extends SliderSuperTab {
this.profile.setPeer(rootScope.myId);
this.profile.fillProfileElements();
const user = appUsersManager.getSelf();
if(user.photo?._ === 'userProfilePhoto') {
const changeAvatarBtn = Button('btn-circle btn-corner z-depth-1 profile-change-avatar', {icon: 'cameraadd'});
changeAvatarBtn.addEventListener('click', () => {
const canvas = document.createElement('canvas');
@ -88,6 +91,7 @@ export default class AppSettingsTab extends SliderSuperTab { @@ -88,6 +91,7 @@ export default class AppSettingsTab extends SliderSuperTab {
});
});
this.profile.element.lastElementChild.firstElementChild.append(changeAvatarBtn);
}
/* const div = document.createElement('div');
//div.style.cssText = 'border-radius: 8px; overflow: hidden; width: 396px; height: 264px; flex: 0 0 auto; position: relative; margin: 10rem 0 10rem auto;';

2
src/config/app.ts

@ -19,7 +19,7 @@ const App = { @@ -19,7 +19,7 @@ const App = {
version: process.env.VERSION,
versionFull: process.env.VERSION_FULL,
build: +process.env.BUILD,
langPackVersion: '0.3.9',
langPackVersion: '0.4.0',
langPack: 'macos',
langPackCode: 'en',
domains: [MAIN_DOMAIN] as string[],

2
src/lang.ts

@ -133,6 +133,8 @@ const lang = { @@ -133,6 +133,8 @@ const lang = {
"PushNotification.Message.NoPreview": "You have a new message",
"LogOut.Description": "Are you sure you want to log out?\n\nNote that you can seamlessly use Telegram on all your devices at once.",
//"PushNotification.Action.Mute1d.Success": "Notification settings were successfully saved.",
//it is from iOS
"VoiceChat.DiscussionGroup": "discussion group",
// * android
"AccDescrEditing": "Editing",

Loading…
Cancel
Save