Edit contact done

This commit is contained in:
Eduard Kuzmenko 2021-03-13 07:53:19 +04:00
parent cf9834aa67
commit 4b9d571f8c
5 changed files with 93 additions and 40 deletions

View File

@ -24,4 +24,4 @@ export default class PopupPeer extends PopupElement {
this.container.insertBefore(p, this.header.nextElementSibling);
}
}
}

View File

@ -5,11 +5,15 @@ import { SettingSection } from "../../sidebarLeft";
import Row from "../../row";
import CheckboxField from "../../checkboxField";
import Button from "../../button";
import appChatsManager from "../../../lib/appManagers/appChatsManager";
import { attachClickEvent } from "../../../helpers/dom";
import { attachClickEvent, toggleDisability } from "../../../helpers/dom";
import appUsersManager from "../../../lib/appManagers/appUsersManager";
import appNotificationsManager from "../../../lib/appManagers/appNotificationsManager";
import PeerTitle from "../../peerTitle";
import appMessagesManager from "../../../lib/appManagers/appMessagesManager";
import rootScope from "../../../lib/rootScope";
import appPeersManager from "../../../lib/appManagers/appPeersManager";
import PopupPeer from "../../popups/peer";
import { addCancelButton } from "../../popups";
export default class AppEditContactTab extends SliderSuperTab {
private nameInputField: InputField;
@ -64,11 +68,31 @@ export default class AppEditContactTab extends SliderSuperTab {
text: 'Notifications'
});
notificationsCheckboxField.input.addEventListener('change', (e) => {
if(!e.isTrusted) {
return;
}
appMessagesManager.mutePeer(this.peerId);
});
this.listenerSetter.add(rootScope, 'notify_settings', (update) => {
if(update.peer._ !== 'notifyPeer') return;
const peerId = appPeersManager.getPeerId(update.peer.peer);
if(this.peerId === peerId) {
const enabled = !appNotificationsManager.isMuted(update.notify_settings);
if(enabled !== notificationsCheckboxField.value) {
notificationsCheckboxField.value = enabled;
}
}
});
const notificationsRow = new Row({
checkboxField: notificationsCheckboxField
});
notificationsCheckboxField.value = !appNotificationsManager.isPeerLocalMuted(this.peerId, false);
const enabled = !appNotificationsManager.isPeerLocalMuted(this.peerId, false);
notificationsCheckboxField.value = enabled;
const profileNameDiv = document.createElement('div');
profileNameDiv.classList.add('profile-name');
@ -87,25 +111,9 @@ export default class AppEditContactTab extends SliderSuperTab {
attachClickEvent(this.editPeer.nextBtn, () => {
this.editPeer.nextBtn.disabled = true;
let promises: Promise<any>[] = [];
const id = -this.peerId;
if(this.nameInputField.isValid()) {
promises.push(appChatsManager.editTitle(id, this.nameInputField.value));
}
if(this.lastNameInputField.isValid()) {
promises.push(appChatsManager.editAbout(id, this.lastNameInputField.value));
}
if(this.editPeer.uploadAvatar) {
promises.push(this.editPeer.uploadAvatar().then(inputFile => {
return appChatsManager.editPhoto(id, inputFile);
}));
}
Promise.race(promises).finally(() => {
appUsersManager.addContact(this.peerId, this.nameInputField.value, this.lastNameInputField.value, appUsersManager.getUser(this.peerId).phone)
.finally(() => {
this.editPeer.nextBtn.removeAttribute('disabled');
this.close();
});
@ -119,6 +127,27 @@ export default class AppEditContactTab extends SliderSuperTab {
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'Delete Contact'});
attachClickEvent(btnDelete, () => {
new PopupPeer('popup-delete-contact', {
peerId: this.peerId,
title: 'Delete Contact?',
description: `Are you sure you want to delete <b>${appPeersManager.getPeerTitle(this.peerId)}</b> from your contact list?`,
buttons: addCancelButton([{
text: 'DELETE',
callback: () => {
toggleDisability([btnDelete], true);
appUsersManager.deleteContacts([this.peerId]).then(() => {
this.close();
}, () => {
toggleDisability([btnDelete], false);
});
},
isDanger: true
}])
}).show();
}, {listenerSetter: this.listenerSetter});
section.content.append(btnDelete);
this.scrollable.append(section.container);

View File

@ -723,25 +723,19 @@ export class AppUsersManager {
});
}
/* public onContactUpdated(userId: number, isContact: boolean) {
userId = parseInt('' + userId);
if(Array.isArray(this.contactsList)) {
var curPos = this.contactsList.indexOf(userId);
var curIsContact = curPos !== -1;
if(isContact !== curIsContact) {
if(isContact) {
this.contactsList.push(userId)
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
} else {
this.contactsList.splice(curPos, 1);
}
rootScope.$broadcast('contacts_update', userId);
public onContactUpdated(userId: number, isContact: boolean) {
const curIsContact = this.contactsList.has(userId);
if(isContact !== curIsContact) {
if(isContact) {
this.contactsList.add(userId)
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
} else {
this.contactsList.delete(userId);
}
rootScope.broadcast('contacts_update', userId);
}
} */
}
public setUserStatus(userId: number, offline: boolean) {
if(this.isBot(userId)) {
@ -763,6 +757,32 @@ export class AppUsersManager {
rootScope.broadcast('user_update', userId);
}
}
public addContact(userId: number, first_name: string, last_name: string, phone: string, showPhone?: true) {
return apiManager.invokeApi('contacts.addContact', {
id: this.getUserInput(userId),
first_name,
last_name,
phone,
add_phone_privacy_exception: showPhone
}).then((updates) => {
apiUpdatesManager.processUpdateMessage(updates);
this.onContactUpdated(userId, true);
});
}
public deleteContacts(userIds: number[]) {
return apiManager.invokeApi('contacts.deleteContacts', {
id: userIds.map(userId => this.getUserInput(userId))
}).then((updates) => {
apiUpdatesManager.processUpdateMessage(updates);
userIds.forEach(userId => {
this.onContactUpdated(userId, false);
});
});
}
}
const appUsersManager = new AppUsersManager();

View File

@ -72,7 +72,7 @@ export type BroadcastEvents = {
'state_synchronized': number,
'state_synchronizing': number,
//'contacts_update': any,
'contacts_update': number,
'avatar_update': number,
'chat_full_update': number,
'poll_update': {poll: Poll, results: PollResults},

View File

@ -347,6 +347,10 @@
/* > div:not(:empty) + .content-empty {
display: none;
} */
> div:first-child {
transform: translateY(0);
}
}
/* .scrollable-y {