Browse Source

Added translation of saved

Translated saved in search
Update search index on peer's update
master
morethanwords 3 years ago
parent
commit
967e849aae
  1. 7
      src/components/appSelectPeers.ts
  2. 4
      src/components/peerTitle.ts
  3. 13
      src/components/sidebarLeft/index.ts
  4. 8
      src/components/sidebarRight/tabs/sharedMedia.ts
  5. 6
      src/helpers/object.ts
  6. 1
      src/lang.ts
  7. 12
      src/lib/appManagers/appChatsManager.ts
  8. 14
      src/lib/appManagers/appMessagesManager.ts
  9. 44
      src/lib/appManagers/appUsersManager.ts
  10. 3
      src/lib/langPack.ts
  11. 2
      src/lib/rootScope.ts
  12. 10
      src/lib/searchIndexManager.ts
  13. 4
      src/lib/storages/dialogs.ts

7
src/components/appSelectPeers.ts

@ -11,7 +11,7 @@ import appPeersManager from "../lib/appManagers/appPeersManager";
import appPhotosManager from "../lib/appManagers/appPhotosManager"; import appPhotosManager from "../lib/appManagers/appPhotosManager";
import appUsersManager from "../lib/appManagers/appUsersManager"; import appUsersManager from "../lib/appManagers/appUsersManager";
import rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { cancelEvent } from "../helpers/dom"; import { cancelEvent, replaceContent } from "../helpers/dom";
import Scrollable from "./scrollable"; import Scrollable from "./scrollable";
import { FocusDirection } from "../helpers/fastSmoothScroll"; import { FocusDirection } from "../helpers/fastSmoothScroll";
import CheckboxField from "./checkboxField"; import CheckboxField from "./checkboxField";
@ -20,6 +20,7 @@ import { safeAssign } from "../helpers/object";
import { i18n, LangPackKey, _i18n } from "../lib/langPack"; import { i18n, LangPackKey, _i18n } from "../lib/langPack";
import findUpAttribute from "../helpers/dom/findUpAttribute"; import findUpAttribute from "../helpers/dom/findUpAttribute";
import findUpClassName from "../helpers/dom/findUpClassName"; import findUpClassName from "../helpers/dom/findUpClassName";
import PeerTitle from "./peerTitle";
type PeerType = 'contacts' | 'dialogs' | 'channelParticipants'; type PeerType = 'contacts' | 'dialogs' | 'channelParticipants';
@ -475,7 +476,7 @@ export default class AppSelectPeers {
div.dataset.key = '' + peerId; div.dataset.key = '' + peerId;
if(typeof(peerId) === 'number') { if(typeof(peerId) === 'number') {
if(title === undefined) { if(title === undefined) {
title = peerId === rootScope.myId ? 'Saved' : appPeersManager.getPeerTitle(peerId, false, true); title = new PeerTitle({peerId, onlyFirstName: true}).element;
} }
avatarEl.setAttribute('peer', '' + peerId); avatarEl.setAttribute('peer', '' + peerId);
@ -485,7 +486,7 @@ export default class AppSelectPeers {
if(typeof(title) === 'string') { if(typeof(title) === 'string') {
div.innerHTML = title; div.innerHTML = title;
} else { } else {
div.innerHTML = ''; replaceContent(div, title);
div.append(title); div.append(title);
} }
} }

4
src/components/peerTitle.ts

@ -7,6 +7,8 @@
import { MOUNT_CLASS_TO } from "../config/debug"; import { MOUNT_CLASS_TO } from "../config/debug";
import appPeersManager from "../lib/appManagers/appPeersManager"; import appPeersManager from "../lib/appManagers/appPeersManager";
import rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { replaceContent } from "../helpers/dom";
import { i18n } from "../lib/langPack";
export type PeerTitleOptions = { export type PeerTitleOptions = {
peerId: number, peerId: number,
@ -59,7 +61,7 @@ export default class PeerTitle {
if(this.peerId !== rootScope.myId || !this.dialog) { if(this.peerId !== rootScope.myId || !this.dialog) {
this.element.innerHTML = appPeersManager.getPeerTitle(this.peerId, this.plainText, this.onlyFirstName); this.element.innerHTML = appPeersManager.getPeerTitle(this.peerId, this.plainText, this.onlyFirstName);
} else { } else {
this.element.innerHTML = this.onlyFirstName ? 'Saved' : 'Saved Messages'; replaceContent(this.element, i18n(this.onlyFirstName ? 'Saved' : 'SavedMessages'));
} }
} }
} }

13
src/components/sidebarLeft/index.ts

@ -34,6 +34,8 @@ import { isMobileSafari } from "../../helpers/userAgent";
import appNavigationController from "../appNavigationController"; import appNavigationController from "../appNavigationController";
import findUpClassName from "../../helpers/dom/findUpClassName"; import findUpClassName from "../../helpers/dom/findUpClassName";
import findUpTag from "../../helpers/dom/findUpTag"; import findUpTag from "../../helpers/dom/findUpTag";
import PeerTitle from "../peerTitle";
import { replaceContent } from "../../helpers/dom";
export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown'; export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown';
@ -290,7 +292,7 @@ export class AppSidebarLeft extends SidebarSlider {
searchSuper.nav.parentElement.append(helper); searchSuper.nav.parentElement.append(helper);
const renderEntity = (peerId: any, title?: string) => { const renderEntity = (peerId: any, title?: string | HTMLElement) => {
const div = document.createElement('div'); const div = document.createElement('div');
div.classList.add('selector-user'/* , 'scale-in' */); div.classList.add('selector-user'/* , 'scale-in' */);
@ -302,7 +304,7 @@ export class AppSidebarLeft extends SidebarSlider {
div.dataset.key = '' + peerId; div.dataset.key = '' + peerId;
if(typeof(peerId) === 'number') { if(typeof(peerId) === 'number') {
if(title === undefined) { if(title === undefined) {
title = peerId === rootScope.myId ? 'Saved' : appPeersManager.getPeerTitle(peerId, false, true); title = new PeerTitle({peerId, onlyFirstName: true}).element;
} }
avatarEl.setAttribute('peer', '' + peerId); avatarEl.setAttribute('peer', '' + peerId);
@ -311,7 +313,12 @@ export class AppSidebarLeft extends SidebarSlider {
} }
if(title) { if(title) {
if(typeof(title) === 'string') {
div.innerHTML = title; div.innerHTML = title;
} else {
replaceContent(div, title);
div.append(title);
}
} }
div.insertAdjacentElement('afterbegin', avatarEl); div.insertAdjacentElement('afterbegin', avatarEl);
@ -446,7 +453,7 @@ export class AppSidebarLeft extends SidebarSlider {
this.newBtnMenu.classList.add('is-hidden'); this.newBtnMenu.classList.add('is-hidden');
this.toolsBtn.parentElement.firstElementChild.classList.toggle('state-back', true); this.toolsBtn.parentElement.firstElementChild.classList.toggle('state-back', true);
if(!isMobileSafari) { if(!isMobileSafari && !appNavigationController.findItemByType('global-search')) {
appNavigationController.pushItem({ appNavigationController.pushItem({
onPop: () => { onPop: () => {
close(); close();

8
src/components/sidebarRight/tabs/sharedMedia.ts

@ -497,6 +497,7 @@ class PeerProfile {
} }
public setAvatar() { public setAvatar() {
if(this.peerId !== rootScope.myId) {
const photo = appPeersManager.getPeerPhoto(this.peerId); const photo = appPeersManager.getPeerPhoto(this.peerId);
if(photo) { if(photo) {
@ -509,7 +510,11 @@ class PeerProfile {
if(oldAvatars) oldAvatars.container.replaceWith(this.avatars.container); if(oldAvatars) oldAvatars.container.replaceWith(this.avatars.container);
else this.element.prepend(this.avatars.container); else this.element.prepend(this.avatars.container);
} else {
return;
}
}
if(this.avatars) { if(this.avatars) {
this.avatars.container.remove(); this.avatars.container.remove();
this.avatars = undefined; this.avatars = undefined;
@ -519,7 +524,6 @@ class PeerProfile {
this.section.content.prepend(this.avatar, this.name, this.subtitle); this.section.content.prepend(this.avatar, this.name, this.subtitle);
} }
}
public fillProfileElements() { public fillProfileElements() {
if(!this.cleaned) return; if(!this.cleaned) return;

6
src/helpers/object.ts

@ -67,6 +67,10 @@ export function getObjectKeysAndSort(object: any, sort: 'asc' | 'desc' = 'asc')
} }
export function safeReplaceObject(wasObject: any, newObject: any) { export function safeReplaceObject(wasObject: any, newObject: any) {
if(!wasObject) {
return newObject;
}
for(var key in wasObject) { for(var key in wasObject) {
if(!newObject.hasOwnProperty(key) && key.charAt(0) !== '$') { if(!newObject.hasOwnProperty(key) && key.charAt(0) !== '$') {
delete wasObject[key]; delete wasObject[key];
@ -78,6 +82,8 @@ export function safeReplaceObject(wasObject: any, newObject: any) {
wasObject[key] = newObject[key]; wasObject[key] = newObject[key];
//} //}
} }
return wasObject;
} }
/** /**

1
src/lang.ts

@ -90,6 +90,7 @@ const lang = {
"MarkupTooltip.LinkPlaceholder": "Enter URL...", "MarkupTooltip.LinkPlaceholder": "Enter URL...",
"MediaViewer.Context.Download": "Download", "MediaViewer.Context.Download": "Download",
"Profile": "Profile", "Profile": "Profile",
"Saved": "Saved",
// * android // * android
"ActionCreateChannel": "Channel created", "ActionCreateChannel": "Channel created",

12
src/lib/appManagers/appChatsManager.ts

@ -36,7 +36,6 @@ export class AppChatsManager {
//public usernames: any = {}; //public usernames: any = {};
//public channelAccess: any = {}; //public channelAccess: any = {};
//public megagroups: {[id: number]: true} = {}; //public megagroups: {[id: number]: true} = {};
public cachedPhotoLocations: {[id: number]: ChatPhoto} = {};
public megagroupOnlines: {[id: number]: {timestamp: number, onlines: number}} = {}; public megagroupOnlines: {[id: number]: {timestamp: number, onlines: number}} = {};
@ -184,11 +183,6 @@ export class AppChatsManager {
rootScope.broadcast('chat_update', chat.id); rootScope.broadcast('chat_update', chat.id);
} }
if(this.cachedPhotoLocations[chat.id] !== undefined) {
safeReplaceObject(this.cachedPhotoLocations[chat.id], chat &&
chat.photo ? chat.photo : {empty: true});
}
if(changedPhoto) { if(changedPhoto) {
rootScope.broadcast('avatar_update', -chat.id); rootScope.broadcast('avatar_update', -chat.id);
} }
@ -388,15 +382,11 @@ export class AppChatsManager {
public getChatPhoto(id: number) { public getChatPhoto(id: number) {
const chat: Chat.chat = this.getChat(id); const chat: Chat.chat = this.getChat(id);
if(this.cachedPhotoLocations[id] === undefined) { return chat && chat.photo || {
this.cachedPhotoLocations[id] = chat && chat.photo || {
_: 'chatPhotoEmpty' _: 'chatPhotoEmpty'
}; };
} }
return this.cachedPhotoLocations[id];
}
public getChatString(id: number) { public getChatString(id: number) {
const chat = this.getChat(id); const chat = this.getChat(id);
if(this.isChannel(id)) { if(this.isChannel(id)) {

14
src/lib/appManagers/appMessagesManager.ts

@ -184,7 +184,6 @@ export class AppMessagesManager {
private reloadConversationsPromise: Promise<void>; private reloadConversationsPromise: Promise<void>;
private reloadConversationsPeers: number[] = []; private reloadConversationsPeers: number[] = [];
private dialogsIndex = searchIndexManager.createIndex();
private cachedResults: { private cachedResults: {
query: string, query: string,
count: number, count: number,
@ -228,6 +227,15 @@ export class AppMessagesManager {
}); });
}); });
rootScope.on('language_change', (e) => {
const peerId = appUsersManager.getSelf().id;
const dialog = this.getDialogByPeerId(peerId)[0];
if(dialog) {
const peerText = appPeersManager.getPeerSearchText(peerId);
searchIndexManager.indexObject(peerId, peerText, this.dialogsStorage.dialogsIndex);
}
});
rootScope.on('webpage_updated', (e) => { rootScope.on('webpage_updated', (e) => {
const eventData = e; const eventData = e;
eventData.msgs.forEach((mid) => { eventData.msgs.forEach((mid) => {
@ -1650,7 +1658,7 @@ export class AppMessagesManager {
this.cachedResults.query = query; this.cachedResults.query = query;
this.cachedResults.folderId = folderId; this.cachedResults.folderId = folderId;
const results = searchIndexManager.search(query, this.dialogsIndex); const results = searchIndexManager.search(query, this.dialogsStorage.dialogsIndex);
this.cachedResults.dialogs = []; this.cachedResults.dialogs = [];
@ -3070,7 +3078,7 @@ export class AppMessagesManager {
} }
const peerText = appPeersManager.getPeerSearchText(peerId); const peerText = appPeersManager.getPeerSearchText(peerId);
searchIndexManager.indexObject(peerId, peerText, this.dialogsIndex); searchIndexManager.indexObject(peerId, peerText, this.dialogsStorage.dialogsIndex);
let mid: number, message; let mid: number, message;
if(dialog.top_message) { if(dialog.top_message) {

44
src/lib/appManagers/appUsersManager.ts

@ -35,7 +35,6 @@ export class AppUsersManager {
private users: {[userId: number]: User} = {}; private users: {[userId: number]: User} = {};
private usernames: {[username: string]: number} = {}; private usernames: {[username: string]: number} = {};
//public userAccess: {[userId: number]: string} = {}; //public userAccess: {[userId: number]: string} = {};
private cachedPhotoLocations: {[userId: number]: UserProfilePhoto} = {};
private contactsIndex = searchIndexManager.createIndex(); private contactsIndex = searchIndexManager.createIndex();
private contactsFillPromise: Promise<Set<number>>; private contactsFillPromise: Promise<Set<number>>;
public contactsList: Set<number> = new Set(); public contactsList: Set<number> = new Set();
@ -80,15 +79,10 @@ export class AppUsersManager {
if(user) { if(user) {
this.forceUserOnline(userId); this.forceUserOnline(userId);
if(!user.photo) { if(update.photo._ === 'userProfilePhotoEmpty') {
user.photo = update.photo; delete user.photo;
} else { } else {
safeReplaceObject(user.photo, update.photo); user.photo = safeReplaceObject(user.photo, update.photo);
}
if(this.cachedPhotoLocations[userId] !== undefined) {
safeReplaceObject(this.cachedPhotoLocations[userId], update.photo ?
update.photo : {empty: true});
} }
rootScope.broadcast('user_update', userId); rootScope.broadcast('user_update', userId);
@ -120,6 +114,11 @@ export class AppUsersManager {
} }
}); });
rootScope.on('language_change', (e) => {
const userId = this.getSelf().id;
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
});
appStateManager.getState().then((state) => { appStateManager.getState().then((state) => {
this.users = state.users; this.users = state.users;
@ -198,12 +197,16 @@ export class AppUsersManager {
return ''; return '';
} }
const serviceText = user.pFlags.self ? 'Saved Messages' : ''; const arr: string[] = [
return (user.first_name || '') + user.first_name,
' ' + (user.last_name || '') + user.last_name,
' ' + (user.phone || '') + user.phone,
' ' + (user.username || '') + user.username,
' ' + serviceText; user.pFlags.self ? I18n.format('SavedMessages', true) : '',
user.pFlags.self ? 'Saved Messages' : ''
];
return arr.filter(Boolean).join(' ');
} }
public getContacts(query?: string, includeSaved = false) { public getContacts(query?: string, includeSaved = false) {
@ -351,11 +354,6 @@ export class AppUsersManager {
rootScope.broadcast('user_update', userId); rootScope.broadcast('user_update', userId);
if(this.cachedPhotoLocations[userId] !== undefined) {
safeReplaceObject(this.cachedPhotoLocations[userId], user &&
user.photo ? user.photo : {empty: true});
}
if(changedTitle) { if(changedTitle) {
rootScope.broadcast('peer_title_edit', user.id); rootScope.broadcast('peer_title_edit', user.id);
} }
@ -514,15 +512,11 @@ export class AppUsersManager {
public getUserPhoto(id: number) { public getUserPhoto(id: number) {
const user = this.getUser(id); const user = this.getUser(id);
if(this.cachedPhotoLocations[id] === undefined) { return user && user.photo || {
this.cachedPhotoLocations[id] = user && user.photo || {
_: 'userProfilePhotoEmpty' _: 'userProfilePhotoEmpty'
}; };
} }
return this.cachedPhotoLocations[id];
}
public getUserString(id: number) { public getUserString(id: number) {
const user = this.getUser(id); const user = this.getUser(id);
return 'u' + id + (user.access_hash ? '_' + user.access_hash : ''); return 'u' + id + (user.access_hash ? '_' + user.access_hash : '');

3
src/lib/langPack.ts

@ -13,6 +13,7 @@ import { LangPackDifference, LangPackString } from "../layer";
import apiManager from "./mtproto/mtprotoworker"; import apiManager from "./mtproto/mtprotoworker";
import sessionStorage from "./sessionStorage"; import sessionStorage from "./sessionStorage";
import App from "../config/app"; import App from "../config/app";
import rootScope from "./rootScope";
export const langPack: {[actionType: string]: LangPackKey} = { export const langPack: {[actionType: string]: LangPackKey} = {
"messageActionChatCreate": "ActionCreateGroup", "messageActionChatCreate": "ActionCreateGroup",
@ -204,6 +205,8 @@ namespace I18n {
strings.set(string.key as LangPackKey, string); strings.set(string.key as LangPackKey, string);
} }
rootScope.broadcast('language_change');
const elements = Array.from(document.querySelectorAll(`.i18n`)) as HTMLElement[]; const elements = Array.from(document.querySelectorAll(`.i18n`)) as HTMLElement[];
elements.forEach(element => { elements.forEach(element => {
const instance = weakMap.get(element); const instance = weakMap.get(element);

2
src/lib/rootScope.ts

@ -108,6 +108,8 @@ export type BroadcastEvents = {
'notify_settings': Update.updateNotifySettings, 'notify_settings': Update.updateNotifySettings,
'notify_peer_type_settings': {key: Exclude<NotifyPeer['_'], 'notifyPeer'>, settings: PeerNotifySettings}, 'notify_peer_type_settings': {key: Exclude<NotifyPeer['_'], 'notifyPeer'>, settings: PeerNotifySettings},
'language_change': void,
}; };
class RootScope extends EventListenerBase<any> { class RootScope extends EventListenerBase<any> {

10
src/lib/searchIndexManager.ts

@ -54,12 +54,16 @@ class SearchIndexManager {
} }
public indexObject(id: number, searchText: string, searchIndex: SearchIndex) { public indexObject(id: number, searchText: string, searchIndex: SearchIndex) {
if(searchIndex.fullTexts.hasOwnProperty(id)) { /* if(searchIndex.fullTexts.hasOwnProperty(id)) {
return false; return false;
} } */
if(searchText.trim()) {
searchText = this.cleanSearchText(searchText); searchText = this.cleanSearchText(searchText);
if(!searchText.length) { }
if(!searchText) {
delete searchIndex.fullTexts[id];
return false; return false;
} }

4
src/lib/storages/dialogs.ts

@ -15,6 +15,7 @@ import type { AppChatsManager } from "../appManagers/appChatsManager";
import type { AppMessagesManager, Dialog, MyMessage } from "../appManagers/appMessagesManager"; import type { AppMessagesManager, Dialog, MyMessage } from "../appManagers/appMessagesManager";
import type { AppPeersManager } from "../appManagers/appPeersManager"; import type { AppPeersManager } from "../appManagers/appPeersManager";
import type { ServerTimeManager } from "../mtproto/serverTimeManager"; import type { ServerTimeManager } from "../mtproto/serverTimeManager";
import searchIndexManager from "../searchIndexManager";
export default class DialogsStorage { export default class DialogsStorage {
public dialogs: {[peerId: string]: Dialog} = {}; public dialogs: {[peerId: string]: Dialog} = {};
@ -25,6 +26,8 @@ export default class DialogsStorage {
public pinnedOrders: {[folder_id: number]: number[]}; public pinnedOrders: {[folder_id: number]: number[]};
private dialogsNum: number; private dialogsNum: number;
public dialogsIndex = searchIndexManager.createIndex();
constructor(private appMessagesManager: AppMessagesManager, private appChatsManager: AppChatsManager, private appPeersManager: AppPeersManager, private serverTimeManager: ServerTimeManager) { constructor(private appMessagesManager: AppMessagesManager, private appChatsManager: AppChatsManager, private appPeersManager: AppPeersManager, private serverTimeManager: ServerTimeManager) {
this.reset(); this.reset();
} }
@ -199,6 +202,7 @@ export default class DialogsStorage {
if(foundDialog[0]) { if(foundDialog[0]) {
this.byFolders[foundDialog[0].folder_id].splice(foundDialog[1], 1); this.byFolders[foundDialog[0].folder_id].splice(foundDialog[1], 1);
delete this.dialogs[peerId]; delete this.dialogs[peerId];
searchIndexManager.indexObject(peerId, '', this.dialogsIndex);
} }
return foundDialog; return foundDialog;

Loading…
Cancel
Save