Browse Source

Fix handling profile update

master
Eduard Kuzmenko 3 years ago
parent
commit
529f8b5d93
  1. 92
      src/components/peerProfile.ts
  2. 12
      src/lib/appManagers/appProfileManager.ts
  3. 5
      src/lib/appManagers/appUsersManager.ts

92
src/components/peerProfile.ts

@ -33,8 +33,8 @@ import { toast } from "./toast"; @@ -33,8 +33,8 @@ import { toast } from "./toast";
let setText = (text: string, row: Row) => {
//fastRaf(() => {
row.title.innerHTML = text;
row.container.style.display = '';
row.title.innerHTML = text || '';
row.container.style.display = text ? '' : 'none';
//});
};
@ -207,6 +207,12 @@ export default class PeerProfile { @@ -207,6 +207,12 @@ export default class PeerProfile {
}
});
listenerSetter.add(rootScope)('peer_title_edit', (peerId) => {
if(peerId === this.peerId) {
this.fillUsername();
}
});
listenerSetter.add(rootScope)('user_update', (userId) => {
if(this.peerId === userId.toPeerId()) {
this.setPeerStatus();
@ -216,12 +222,8 @@ export default class PeerProfile { @@ -216,12 +222,8 @@ export default class PeerProfile {
listenerSetter.add(rootScope)('contacts_update', (userId) => {
if(this.peerId === userId.toPeerId()) {
const user = appUsersManager.getUser(userId);
if(!user.pFlags.self) {
if(user.phone) {
setText(appUsersManager.formatUserPhone(user.phone), this.phone);
} else {
this.phone.container.style.display = 'none';
}
if(!user.pFlags.self || !this.isDialog) {
this.fillUserPhone();
}
}
});
@ -299,47 +301,44 @@ export default class PeerProfile { @@ -299,47 +301,44 @@ export default class PeerProfile {
this.section.content.prepend(this.avatar, this.name, this.subtitle);
}
public fillProfileElements() {
if(!this.cleaned) return;
this.cleaned = false;
const peerId = this.peerId;
this.cleanupHTML();
this.setAvatar();
// username
if(this.canBeDetailed()) {
if(peerId.isUser()) {
private fillUsername() {
const {peerId} = this;
if(peerId.isUser() && this.canBeDetailed()) {
const username = appPeersManager.getPeerUsername(peerId);
if(username) {
setText(appPeersManager.getPeerUsername(peerId), this.username);
setText(username, this.username);
}
}
if(this.notifications) {
const muted = appNotificationsManager.isPeerLocalMuted(peerId, false);
this.notifications.checkboxField.checked = !muted;
private fillUserPhone() {
const {peerId} = this;
if(peerId.isUser() && this.canBeDetailed()) {
const user = appUsersManager.getUser(peerId);
setText(user.phone ? appUsersManager.formatUserPhone(user.phone) : undefined, this.phone);
}
} else if(this.notifications) {
fastRaf(() => {
this.notifications.container.style.display = 'none';
});
}
//let membersLi = this.profileTabs.firstElementChild.children[0] as HTMLLIElement;
if(peerId.isUser()) {
//membersLi.style.display = 'none';
private fillNotifications() {
const notificationsRow = this.notifications;
if(!notificationsRow) {
return;
}
let user = appUsersManager.getUser(peerId);
if(user.phone && this.canBeDetailed()) {
setText(appUsersManager.formatUserPhone(user.phone), this.phone);
if(this.canBeDetailed()) {
const muted = appNotificationsManager.isPeerLocalMuted(this.peerId, false);
notificationsRow.checkboxField.checked = !muted;
} else {
fastRaf(() => {
notificationsRow.container.style.display = 'none';
});
}
}/* else {
//membersLi.style.display = appPeersManager.isBroadcast(peerId) ? 'none' : '';
} */
}
private fillRows() {
const peerId = this.peerId;
this.fillUsername();
this.fillUserPhone();
this.fillNotifications();
this.setMoreDetails();
replaceContent(this.name, new PeerTitle({
@ -355,6 +354,15 @@ export default class PeerProfile { @@ -355,6 +354,15 @@ export default class PeerProfile {
this.setPeerStatus(true);
}
public fillProfileElements() {
if(!this.cleaned) return;
this.cleaned = false;
this.cleanupHTML();
this.setAvatar();
this.fillRows();
}
public setMoreDetails(override?: true) {
if(this.setMoreDetailsTimeout) {
window.clearTimeout(this.setMoreDetailsTimeout);
@ -376,9 +384,9 @@ export default class PeerProfile { @@ -376,9 +384,9 @@ export default class PeerProfile {
//this.log('chatInfo res 2:', chatFull);
if(peerFull.about) {
setText(RichTextProcessor.wrapRichText(peerFull.about), this.bio);
}
// if(peerFull.about) {
setText(peerFull.about ? RichTextProcessor.wrapRichText(peerFull.about) : undefined, this.bio);
// }
if(!peerId.isUser()) {
const chat: Chat.channel = appChatsManager.getChat(peerId.toChatId());

12
src/lib/appManagers/appProfileManager.ts

@ -496,7 +496,7 @@ export class AppProfileManager { @@ -496,7 +496,7 @@ export class AppProfileManager {
// this.getProfileByPeerId(peerId, true);
}
public updateProfile(first_name: string, last_name: string, about: string) {
public updateProfile(first_name?: string, last_name?: string, about?: string) {
return apiManager.invokeApi('account.updateProfile', {
first_name,
last_name,
@ -504,6 +504,16 @@ export class AppProfileManager { @@ -504,6 +504,16 @@ export class AppProfileManager {
}).then(user => {
appUsersManager.saveApiUser(user);
if(about !== undefined) {
const peerId = user.id.toPeerId();
const userFull = this.usersFull[user.id];
if(userFull) {
userFull.about = about;
}
rootScope.dispatchEvent('peer_bio_edit', peerId);
}
return this.getProfile(rootScope.myId, true);
});
}

5
src/lib/appManagers/appUsersManager.ts

@ -106,11 +106,12 @@ export class AppUsersManager { @@ -106,11 +106,12 @@ export class AppUsersManager {
if(user) {
this.forceUserOnline(userId);
this.saveApiUser(Object.assign({}, user, {
this.saveApiUser({
...user,
first_name: update.first_name,
last_name: update.last_name,
username: update.username
}), true);
}, true);
}
}
});

Loading…
Cancel
Save