Browse Source

Fix handling profile update

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

94
src/components/peerProfile.ts

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

12
src/lib/appManagers/appProfileManager.ts

@ -496,7 +496,7 @@ export class AppProfileManager {
// this.getProfileByPeerId(peerId, true); // 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', { return apiManager.invokeApi('account.updateProfile', {
first_name, first_name,
last_name, last_name,
@ -504,6 +504,16 @@ export class AppProfileManager {
}).then(user => { }).then(user => {
appUsersManager.saveApiUser(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); return this.getProfile(rootScope.myId, true);
}); });
} }

5
src/lib/appManagers/appUsersManager.ts

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

Loading…
Cancel
Save