Browse Source

Edit contact done

master
Eduard Kuzmenko 4 years ago
parent
commit
9d5dcc0e4a
  1. 71
      src/components/sidebarRight/tabs/editContact.ts
  2. 54
      src/lib/appManagers/appUsersManager.ts
  3. 2
      src/lib/rootScope.ts
  4. 4
      src/scss/partials/_rightSidebar.scss

71
src/components/sidebarRight/tabs/editContact.ts

@ -5,11 +5,15 @@ import { SettingSection } from "../../sidebarLeft";
import Row from "../../row"; import Row from "../../row";
import CheckboxField from "../../checkboxField"; import CheckboxField from "../../checkboxField";
import Button from "../../button"; import Button from "../../button";
import appChatsManager from "../../../lib/appManagers/appChatsManager"; import { attachClickEvent, toggleDisability } from "../../../helpers/dom";
import { attachClickEvent } from "../../../helpers/dom";
import appUsersManager from "../../../lib/appManagers/appUsersManager"; import appUsersManager from "../../../lib/appManagers/appUsersManager";
import appNotificationsManager from "../../../lib/appManagers/appNotificationsManager"; import appNotificationsManager from "../../../lib/appManagers/appNotificationsManager";
import PeerTitle from "../../peerTitle"; 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 { export default class AppEditContactTab extends SliderSuperTab {
private nameInputField: InputField; private nameInputField: InputField;
@ -64,11 +68,31 @@ export default class AppEditContactTab extends SliderSuperTab {
text: 'Notifications' 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({ const notificationsRow = new Row({
checkboxField: notificationsCheckboxField checkboxField: notificationsCheckboxField
}); });
notificationsCheckboxField.value = !appNotificationsManager.isPeerLocalMuted(this.peerId, false); const enabled = !appNotificationsManager.isPeerLocalMuted(this.peerId, false);
notificationsCheckboxField.value = enabled;
const profileNameDiv = document.createElement('div'); const profileNameDiv = document.createElement('div');
profileNameDiv.classList.add('profile-name'); profileNameDiv.classList.add('profile-name');
@ -88,24 +112,8 @@ export default class AppEditContactTab extends SliderSuperTab {
attachClickEvent(this.editPeer.nextBtn, () => { attachClickEvent(this.editPeer.nextBtn, () => {
this.editPeer.nextBtn.disabled = true; this.editPeer.nextBtn.disabled = true;
let promises: Promise<any>[] = []; appUsersManager.addContact(this.peerId, this.nameInputField.value, this.lastNameInputField.value, appUsersManager.getUser(this.peerId).phone)
.finally(() => {
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(() => {
this.editPeer.nextBtn.removeAttribute('disabled'); this.editPeer.nextBtn.removeAttribute('disabled');
this.close(); 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'}); 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); section.content.append(btnDelete);
this.scrollable.append(section.container); this.scrollable.append(section.container);

54
src/lib/appManagers/appUsersManager.ts

@ -723,25 +723,19 @@ export class AppUsersManager {
}); });
} }
/* public onContactUpdated(userId: number, isContact: boolean) { public onContactUpdated(userId: number, isContact: boolean) {
userId = parseInt('' + userId); const curIsContact = this.contactsList.has(userId);
if(isContact !== curIsContact) {
if(Array.isArray(this.contactsList)) { if(isContact) {
var curPos = this.contactsList.indexOf(userId); this.contactsList.add(userId)
var curIsContact = curPos !== -1; searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex);
} else {
if(isContact !== curIsContact) { this.contactsList.delete(userId);
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);
} }
rootScope.broadcast('contacts_update', userId);
} }
} */ }
public setUserStatus(userId: number, offline: boolean) { public setUserStatus(userId: number, offline: boolean) {
if(this.isBot(userId)) { if(this.isBot(userId)) {
@ -763,6 +757,32 @@ export class AppUsersManager {
rootScope.broadcast('user_update', userId); 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(); const appUsersManager = new AppUsersManager();

2
src/lib/rootScope.ts

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

4
src/scss/partials/_rightSidebar.scss

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

Loading…
Cancel
Save