Browse Source

Supported sending messages with signature

Toggle chat pre history hidden
Toggle broadcast signatures
master
morethanwords 3 years ago
parent
commit
bd3eed26fb
  1. 69
      src/components/sidebarRight/tabs/editChat.ts
  2. 1
      src/lang.ts
  3. 20
      src/lib/appManagers/appChatsManager.ts
  4. 14
      src/lib/appManagers/appMessagesManager.ts
  5. 2
      src/lib/appManagers/appUsersManager.ts

69
src/components/sidebarRight/tabs/editChat.ts

@ -12,7 +12,7 @@ import Row from "../../row";
import Button from "../../button"; import Button from "../../button";
import appChatsManager, { ChatRights } from "../../../lib/appManagers/appChatsManager"; import appChatsManager, { ChatRights } from "../../../lib/appManagers/appChatsManager";
import appProfileManager from "../../../lib/appManagers/appProfileManager"; import appProfileManager from "../../../lib/appManagers/appProfileManager";
import { Chat } from "../../../layer"; import { Chat, ChatFull } from "../../../layer";
import AppChatTypeTab from "./chatType"; import AppChatTypeTab from "./chatType";
import rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import AppGroupPermissionsTab from "./groupPermissions"; import AppGroupPermissionsTab from "./groupPermissions";
@ -22,6 +22,7 @@ import { addCancelButton } from "../../popups";
import PopupPeer from "../../popups/peer"; import PopupPeer from "../../popups/peer";
import { attachClickEvent } from "../../../helpers/dom/clickEvent"; import { attachClickEvent } from "../../../helpers/dom/clickEvent";
import toggleDisability from "../../../helpers/dom/toggleDisability"; import toggleDisability from "../../../helpers/dom/toggleDisability";
import CheckboxField from "../../checkboxField";
export default class AppEditChatTab extends SliderSuperTab { export default class AppEditChatTab extends SliderSuperTab {
private chatNameInputField: InputField; private chatNameInputField: InputField;
@ -43,6 +44,17 @@ export default class AppEditChatTab extends SliderSuperTab {
const isBroadcast = appChatsManager.isBroadcast(this.chatId); const isBroadcast = appChatsManager.isBroadcast(this.chatId);
const isChannel = appChatsManager.isChannel(this.chatId); const isChannel = appChatsManager.isChannel(this.chatId);
const chatUpdateListeners: (() => void)[] = [];
const addChatUpdateListener = (callback: () => void) => {
chatUpdateListeners.push(callback);
};
this.listenerSetter.add(rootScope)('chat_update', (chatId) => {
if(this.chatId === chatId) {
chatUpdateListeners.forEach(callback => callback());
}
});
{ {
const section = new SettingSection({noDelimiter: true}); const section = new SettingSection({noDelimiter: true});
const inputFields: InputField[] = []; const inputFields: InputField[] = [];
@ -53,7 +65,8 @@ export default class AppEditChatTab extends SliderSuperTab {
this.chatNameInputField = new InputField({ this.chatNameInputField = new InputField({
label: isBroadcast ? 'Channel.ChannelNameHolder' : 'CreateGroup.NameHolder', label: isBroadcast ? 'Channel.ChannelNameHolder' : 'CreateGroup.NameHolder',
name: 'chat-name', name: 'chat-name',
maxLength: 255 maxLength: 255,
required: true
}); });
this.descriptionInputField = new InputField({ this.descriptionInputField = new InputField({
label: 'DescriptionPlaceholder', label: 'DescriptionPlaceholder',
@ -181,8 +194,8 @@ export default class AppEditChatTab extends SliderSuperTab {
}); });
}, {listenerSetter: this.listenerSetter}); }, {listenerSetter: this.listenerSetter});
/*
if(appChatsManager.hasRights(-this.peerId, 'change_info')) { /* if(appChatsManager.hasRights(-this.peerId, 'change_info')) {
const discussionRow = new Row({ const discussionRow = new Row({
titleLangKey: 'PeerInfo.Discussion', titleLangKey: 'PeerInfo.Discussion',
subtitleLangKey: 'PeerInfo.Discussion.Add', subtitleLangKey: 'PeerInfo.Discussion.Add',
@ -200,24 +213,36 @@ export default class AppEditChatTab extends SliderSuperTab {
clickable: true clickable: true
}); });
section.content.append(administratorsRow.container); section.content.append(administratorsRow.container); */
if(appChatsManager.hasRights(-this.peerId, 'change_info')) { if(isBroadcast && appChatsManager.hasRights(this.chatId, 'change_info')) {
const signMessagesCheckboxField = new CheckboxField({ const signMessagesCheckboxField = new CheckboxField({
text: 'PeerInfo.SignMessages', text: 'PeerInfo.SignMessages',
checked: false checked: !!(chat as Chat.channel).pFlags.signatures,
withRipple: true
});
this.listenerSetter.add(signMessagesCheckboxField.input)('change', () => {
const toggle = signMessagesCheckboxField.toggleDisability(true);
appChatsManager.toggleSignatures(this.chatId, signMessagesCheckboxField.checked).then(() => {
toggle();
});
});
addChatUpdateListener(() => {
signMessagesCheckboxField.setValueSilently(!!(chat as Chat.channel).pFlags.signatures);
}); });
section.content.append(signMessagesCheckboxField.label); section.content.append(signMessagesCheckboxField.label);
} */ }
} }
/* { if(!isBroadcast) {
const section = new SettingSection({ const section = new SettingSection({
}); });
const membersRow = new Row({ /* const membersRow = new Row({
titleLangKey: isBroadcast ? 'PeerInfo.Subscribers' : 'GroupMembers', titleLangKey: isBroadcast ? 'PeerInfo.Subscribers' : 'GroupMembers',
icon: 'newgroup', icon: 'newgroup',
clickable: true clickable: true
@ -225,23 +250,31 @@ export default class AppEditChatTab extends SliderSuperTab {
membersRow.subtitle.append(i18n('Subscribers', [numberThousandSplitter(335356)])); membersRow.subtitle.append(i18n('Subscribers', [numberThousandSplitter(335356)]));
section.content.append(membersRow.container); section.content.append(membersRow.container); */
if(appChatsManager.hasRights(this.chatId, 'change_permissions')) { if(!isBroadcast && appChatsManager.hasRights(this.chatId, 'change_permissions')) {
const showChatHistoryCheckboxField = new CheckboxField({ const showChatHistoryCheckboxField = new CheckboxField({
text: 'Show chat history for new members', text: 'ChatHistory',
withRipple: true withRipple: true,
checked: !(chatFull as ChatFull.channelFull).pFlags.hidden_prehistory
}); });
if(appChatsManager.isChannel(this.chatId) && !(chatFull as ChatFull.channelFull).pFlags.hidden_prehistory) { this.listenerSetter.add(showChatHistoryCheckboxField.input)('change', () => {
showChatHistoryCheckboxField.checked = true; const toggle = showChatHistoryCheckboxField.toggleDisability(true);
} appChatsManager.togglePreHistoryHidden(this.chatId, !showChatHistoryCheckboxField.checked).then(() => {
toggle();
});
});
addChatUpdateListener(() => {
showChatHistoryCheckboxField.setValueSilently(!(chatFull as ChatFull.channelFull).pFlags.hidden_prehistory);
});
section.content.append(showChatHistoryCheckboxField.label); section.content.append(showChatHistoryCheckboxField.label);
} }
this.scrollable.append(section.container); this.scrollable.append(section.container);
} */ }
if(appChatsManager.hasRights(this.chatId, 'delete_chat')) { if(appChatsManager.hasRights(this.chatId, 'delete_chat')) {
const section = new SettingSection({}); const section = new SettingSection({});

1
src/lang.ts

@ -561,6 +561,7 @@ const lang = {
"ReportInfo": "Please enter any additional details relevant to your report.", "ReportInfo": "Please enter any additional details relevant to your report.",
"ReportSentInfo": "Telegram moderators will review your report.\nThank you for your cooperation!", "ReportSentInfo": "Telegram moderators will review your report.\nThank you for your cooperation!",
"ReportHint": "Additional details...", "ReportHint": "Additional details...",
"ChatHistory": "Chat history for new members",
// * macos // * macos
"AccountSettings.Filters": "Chat Folders", "AccountSettings.Filters": "Chat Folders",

20
src/lib/appManagers/appChatsManager.ts

@ -707,6 +707,26 @@ export class AppChatsManager {
this.saveApiChats(messagesChats.chats); this.saveApiChats(messagesChats.chats);
}); });
} }
public togglePreHistoryHidden(id: number, enabled: boolean) {
return this.migrateChat(id).then(channelId => {
return apiManager.invokeApi('channels.togglePreHistoryHidden', {
channel: this.getChannelInput(channelId),
enabled
});
}).then(updates => {
apiUpdatesManager.processUpdateMessage(updates);
});
}
public toggleSignatures(id: number, enabled: boolean) {
return apiManager.invokeApi('channels.toggleSignatures', {
channel: this.getChannelInput(id),
enabled
}).then(updates => {
apiUpdatesManager.processUpdateMessage(updates);
});
}
} }
const appChatsManager = new AppChatsManager(); const appChatsManager = new AppChatsManager();

14
src/lib/appManagers/appMessagesManager.ts

@ -1415,11 +1415,23 @@ export class AppMessagesManager {
options.replyToMsgId = options.threadId; options.replyToMsgId = options.threadId;
} }
let postAuthor: string;
const isBroadcast = appPeersManager.isBroadcast(peerId);
if(isBroadcast) {
const chat = appPeersManager.getPeer(peerId) as Chat.channel;
if(chat.pFlags.signatures) {
const user = appUsersManager.getSelf();
const fullName = user.first_name + (user.last_name ? ' ' + user.last_name : '');
postAuthor = fullName;
}
}
const message: Message.message = { const message: Message.message = {
_: 'message', _: 'message',
id: this.generateTempMessageId(peerId), id: this.generateTempMessageId(peerId),
from_id: this.generateFromId(peerId), from_id: this.generateFromId(peerId),
peer_id: appPeersManager.getOutputPeer(peerId), peer_id: appPeersManager.getOutputPeer(peerId),
post_author: postAuthor,
pFlags: this.generateFlags(peerId), pFlags: this.generateFlags(peerId),
date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset), date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset),
message: '', message: '',
@ -1429,7 +1441,7 @@ export class AppMessagesManager {
via_bot_id: options.viaBotId, via_bot_id: options.viaBotId,
reply_markup: options.replyMarkup, reply_markup: options.replyMarkup,
replies: this.generateReplies(peerId), replies: this.generateReplies(peerId),
views: appPeersManager.isBroadcast(peerId) && 1, views: isBroadcast && 1,
pending: true, pending: true,
}; };

2
src/lib/appManagers/appUsersManager.ts

@ -388,7 +388,7 @@ export class AppUsersManager {
|| oldUser.sortName === undefined || oldUser.sortName === undefined
|| oldUser.first_name !== user.first_name || oldUser.first_name !== user.first_name
|| oldUser.last_name !== user.last_name) { || oldUser.last_name !== user.last_name) {
const fullName = user.first_name + ' ' + (user.last_name || ''); const fullName = user.first_name + (user.last_name ? ' ' + user.last_name : '');
user.sortName = user.pFlags.deleted ? '' : cleanSearchText(fullName, false); user.sortName = user.pFlags.deleted ? '' : cleanSearchText(fullName, false);
user.initials = RichTextProcessor.getAbbreviation(fullName); user.initials = RichTextProcessor.getAbbreviation(fullName);

Loading…
Cancel
Save