Browse Source

Added translation of saved

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

4
src/components/peerTitle.ts

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

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

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

6
src/helpers/object.ts

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

1
src/lang.ts

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

12
src/lib/appManagers/appChatsManager.ts

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

14
src/lib/appManagers/appMessagesManager.ts

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

44
src/lib/appManagers/appUsersManager.ts

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

3
src/lib/langPack.ts

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

2
src/lib/rootScope.ts

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

10
src/lib/searchIndexManager.ts

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

4
src/lib/storages/dialogs.ts

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

Loading…
Cancel
Save