Fix chat leave
Close deleted chat & channel
This commit is contained in:
parent
e183dda671
commit
7f746738f5
@ -56,12 +56,12 @@ export default class DialogsContextMenu {
|
|||||||
this.buttons.delete.addEventListener('click', () => {
|
this.buttons.delete.addEventListener('click', () => {
|
||||||
let firstName = appPeersManager.getPeerTitle(this.selectedID, false, true);
|
let firstName = appPeersManager.getPeerTitle(this.selectedID, false, true);
|
||||||
|
|
||||||
let callbackFlush = (justClear: boolean) => {
|
let callbackFlush = (justClear?: true) => {
|
||||||
appMessagesManager.flushHistory(this.selectedID, justClear);
|
appMessagesManager.flushHistory(this.selectedID, justClear);
|
||||||
};
|
};
|
||||||
|
|
||||||
let callbackLeave = () => {
|
let callbackLeave = () => {
|
||||||
appChatsManager.leaveChannel(-this.selectedID);
|
appChatsManager.leave(-this.selectedID);
|
||||||
};
|
};
|
||||||
|
|
||||||
let title: string, description: string, buttons: PopupButton[];
|
let title: string, description: string, buttons: PopupButton[];
|
||||||
@ -96,7 +96,7 @@ export default class DialogsContextMenu {
|
|||||||
buttons = [{
|
buttons = [{
|
||||||
text: 'DELETE FOR ME AND ' + firstName,
|
text: 'DELETE FOR ME AND ' + firstName,
|
||||||
isDanger: true,
|
isDanger: true,
|
||||||
callback: () => callbackFlush(false)
|
callback: () => callbackFlush()
|
||||||
}, {
|
}, {
|
||||||
text: 'DELETE JUST FOR ME',
|
text: 'DELETE JUST FOR ME',
|
||||||
isDanger: true,
|
isDanger: true,
|
||||||
@ -112,7 +112,7 @@ export default class DialogsContextMenu {
|
|||||||
buttons = [{
|
buttons = [{
|
||||||
text: 'DELETE SAVED MESSAGES',
|
text: 'DELETE SAVED MESSAGES',
|
||||||
isDanger: true,
|
isDanger: true,
|
||||||
callback: () => callbackFlush(false)
|
callback: () => callbackFlush()
|
||||||
}];
|
}];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -124,7 +124,7 @@ export default class DialogsContextMenu {
|
|||||||
buttons = [{
|
buttons = [{
|
||||||
text: 'DELETE AND LEAVE ' + firstName,
|
text: 'DELETE AND LEAVE ' + firstName,
|
||||||
isDanger: true,
|
isDanger: true,
|
||||||
callback: () => callbackFlush(true)
|
callback: () => callbackLeave()
|
||||||
}];
|
}];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import appSidebarLeft, { AppSidebarLeft } from "..";
|
import appSidebarLeft, { AppSidebarLeft } from "..";
|
||||||
|
import { InputFile } from "../../../layer";
|
||||||
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
||||||
import PopupAvatar from "../../popupAvatar";
|
import PopupAvatar from "../../popupAvatar";
|
||||||
import { SliderTab } from "../../slider";
|
import { SliderTab } from "../../slider";
|
||||||
@ -10,7 +11,7 @@ export default class AppNewChannelTab implements SliderTab {
|
|||||||
private channelDescriptionInput = this.container.querySelector('.new-channel-description') as HTMLInputElement;
|
private channelDescriptionInput = this.container.querySelector('.new-channel-description') as HTMLInputElement;
|
||||||
private nextBtn = this.container.querySelector('.btn-corner') as HTMLButtonElement;
|
private nextBtn = this.container.querySelector('.btn-corner') as HTMLButtonElement;
|
||||||
private backBtn = this.container.querySelector('.sidebar-close-button') as HTMLButtonElement;
|
private backBtn = this.container.querySelector('.sidebar-close-button') as HTMLButtonElement;
|
||||||
private uploadAvatar: () => Promise<any> = null;
|
private uploadAvatar: () => Promise<InputFile> = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.container.querySelector('.avatar-edit').addEventListener('click', () => {
|
this.container.querySelector('.avatar-edit').addEventListener('click', () => {
|
||||||
@ -35,7 +36,7 @@ export default class AppNewChannelTab implements SliderTab {
|
|||||||
this.nextBtn.disabled = true;
|
this.nextBtn.disabled = true;
|
||||||
appChatsManager.createChannel(title, about).then((channelID) => {
|
appChatsManager.createChannel(title, about).then((channelID) => {
|
||||||
if(this.uploadAvatar) {
|
if(this.uploadAvatar) {
|
||||||
this.uploadAvatar().then((inputFile: any) => {
|
this.uploadAvatar().then((inputFile) => {
|
||||||
appChatsManager.editPhoto(channelID, inputFile);
|
appChatsManager.editPhoto(channelID, inputFile);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import appSidebarLeft, { AppSidebarLeft } from "..";
|
import appSidebarLeft, { AppSidebarLeft } from "..";
|
||||||
|
import { InputFile } from "../../../layer";
|
||||||
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
||||||
import appDialogsManager from "../../../lib/appManagers/appDialogsManager";
|
import appDialogsManager from "../../../lib/appManagers/appDialogsManager";
|
||||||
import appUsersManager from "../../../lib/appManagers/appUsersManager";
|
import appUsersManager from "../../../lib/appManagers/appUsersManager";
|
||||||
@ -14,7 +15,7 @@ export default class AppNewGroupTab implements SliderTab {
|
|||||||
private groupNameInput = this.container.querySelector('.new-group-name') as HTMLInputElement;
|
private groupNameInput = this.container.querySelector('.new-group-name') as HTMLInputElement;
|
||||||
private nextBtn = this.container.querySelector('.btn-corner') as HTMLButtonElement;
|
private nextBtn = this.container.querySelector('.btn-corner') as HTMLButtonElement;
|
||||||
private searchGroup = new SearchGroup(' ', 'contacts', true, 'new-group-members disable-hover', false);
|
private searchGroup = new SearchGroup(' ', 'contacts', true, 'new-group-members disable-hover', false);
|
||||||
private uploadAvatar: () => Promise<any> = null;
|
private uploadAvatar: () => Promise<InputFile> = null;
|
||||||
private userIDs: number[];
|
private userIDs: number[];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -35,7 +36,7 @@ export default class AppNewGroupTab implements SliderTab {
|
|||||||
this.nextBtn.disabled = true;
|
this.nextBtn.disabled = true;
|
||||||
appChatsManager.createChat(title, this.userIDs).then((chatID) => {
|
appChatsManager.createChat(title, this.userIDs).then((chatID) => {
|
||||||
if(this.uploadAvatar) {
|
if(this.uploadAvatar) {
|
||||||
this.uploadAvatar().then((inputFile: any) => {
|
this.uploadAvatar().then((inputFile) => {
|
||||||
appChatsManager.editPhoto(chatID, inputFile);
|
appChatsManager.editPhoto(chatID, inputFile);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipants, InputChannel, InputChatPhoto, InputPeer, Updates } from "../../layer";
|
import { ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipants, InputChannel, InputChatPhoto, InputFile, InputPeer, Updates } from "../../layer";
|
||||||
import apiManager from '../mtproto/mtprotoworker';
|
import apiManager from '../mtproto/mtprotoworker';
|
||||||
import { RichTextProcessor } from "../richtextprocessor";
|
import { RichTextProcessor } from "../richtextprocessor";
|
||||||
import $rootScope from "../rootScope";
|
import $rootScope from "../rootScope";
|
||||||
import searchIndexManager from "../searchIndexManager";
|
import searchIndexManager from "../searchIndexManager";
|
||||||
import { copy, getAbbreviation, isObject, numberWithCommas, safeReplaceObject } from "../utils";
|
import { copy, getAbbreviation, isObject, numberWithCommas, safeReplaceObject } from "../utils";
|
||||||
import apiUpdatesManager from "./apiUpdatesManager";
|
import apiUpdatesManager from "./apiUpdatesManager";
|
||||||
|
import appMessagesManager from "./appMessagesManager";
|
||||||
import appProfileManager from "./appProfileManager";
|
import appProfileManager from "./appProfileManager";
|
||||||
import appUsersManager from "./appUsersManager";
|
import appUsersManager from "./appUsersManager";
|
||||||
|
|
||||||
@ -296,13 +297,13 @@ export class AppChatsManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasChat(id: number, allowMin?: any) {
|
public hasChat(id: number, allowMin?: true) {
|
||||||
let chat = this.chats[id]
|
const chat = this.chats[id]
|
||||||
return isObject(chat) && (allowMin || !chat.pFlags.min);
|
return isObject(chat) && (allowMin || !chat.pFlags.min);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getChatPhoto(id: number) {
|
public getChatPhoto(id: number) {
|
||||||
let chat = this.getChat(id);
|
const chat = this.getChat(id);
|
||||||
|
|
||||||
if(this.cachedPhotoLocations[id] === undefined) {
|
if(this.cachedPhotoLocations[id] === undefined) {
|
||||||
this.cachedPhotoLocations[id] = chat && chat.photo ? chat.photo : {empty: true};
|
this.cachedPhotoLocations[id] = chat && chat.photo ? chat.photo : {empty: true};
|
||||||
@ -312,7 +313,7 @@ export class AppChatsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getChatString(id: number) {
|
public getChatString(id: number) {
|
||||||
let chat = this.getChat(id);
|
const chat = this.getChat(id);
|
||||||
if(this.isChannel(id)) {
|
if(this.isChannel(id)) {
|
||||||
return (this.isMegagroup(id) ? 's' : 'c') + id + '_' + chat.access_hash;
|
return (this.isMegagroup(id) ? 's' : 'c') + id + '_' + chat.access_hash;
|
||||||
}
|
}
|
||||||
@ -328,8 +329,8 @@ export class AppChatsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public wrapForFull(id: number, fullChat: any) {
|
public wrapForFull(id: number, fullChat: any) {
|
||||||
let chatFull = copy(fullChat);
|
const chatFull = copy(fullChat);
|
||||||
let chat = this.getChat(id);
|
const chat = this.getChat(id);
|
||||||
|
|
||||||
if(!chatFull.participants_count) {
|
if(!chatFull.participants_count) {
|
||||||
chatFull.participants_count = chat.participants_count;
|
chatFull.participants_count = chat.participants_count;
|
||||||
@ -351,10 +352,10 @@ export class AppChatsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public wrapParticipants(id: number, participants: any[]) {
|
public wrapParticipants(id: number, participants: any[]) {
|
||||||
let chat = this.getChat(id);
|
const chat = this.getChat(id);
|
||||||
let myID = appUsersManager.getSelf().id;
|
const myID = appUsersManager.getSelf().id;
|
||||||
if(this.isChannel(id)) {
|
if(this.isChannel(id)) {
|
||||||
let isAdmin = chat.pFlags.creator;
|
const isAdmin = chat.pFlags.creator;
|
||||||
participants.forEach((participant) => {
|
participants.forEach((participant) => {
|
||||||
participant.canLeave = myID == participant.user_id;
|
participant.canLeave = myID == participant.user_id;
|
||||||
participant.canKick = isAdmin && participant._ == 'channelParticipant';
|
participant.canKick = isAdmin && participant._ == 'channelParticipant';
|
||||||
@ -363,7 +364,7 @@ export class AppChatsManager {
|
|||||||
participant.user = appUsersManager.getUser(participant.user_id);
|
participant.user = appUsersManager.getUser(participant.user_id);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let isAdmin = chat.pFlags.creator || chat.pFlags.admins_enabled && chat.pFlags.admin;
|
const isAdmin = chat.pFlags.creator || chat.pFlags.admins_enabled && chat.pFlags.admin;
|
||||||
participants.forEach((participant) => {
|
participants.forEach((participant) => {
|
||||||
participant.canLeave = myID == participant.user_id;
|
participant.canLeave = myID == participant.user_id;
|
||||||
participant.canKick = !participant.canLeave && (
|
participant.canKick = !participant.canLeave && (
|
||||||
@ -393,8 +394,8 @@ export class AppChatsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public inviteToChannel(id: number, userIDs: number[]) {
|
public inviteToChannel(id: number, userIDs: number[]) {
|
||||||
let input = this.getChannelInput(id);
|
const input = this.getChannelInput(id);
|
||||||
let usersInputs = userIDs.map(u => appUsersManager.getUserInput(u));
|
const usersInputs = userIDs.map(u => appUsersManager.getUserInput(u));
|
||||||
|
|
||||||
return apiManager.invokeApi('channels.inviteToChannel', {
|
return apiManager.invokeApi('channels.inviteToChannel', {
|
||||||
channel: input,
|
channel: input,
|
||||||
@ -415,7 +416,7 @@ export class AppChatsManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public editPhoto(id: number, inputFile: any) {
|
public editPhoto(id: number, inputFile: InputFile) {
|
||||||
const isChannel = this.isChannel(id);
|
const isChannel = this.isChannel(id);
|
||||||
|
|
||||||
const inputChatPhoto: InputChatPhoto.inputChatUploadedPhoto = {
|
const inputChatPhoto: InputChatPhoto.inputChatUploadedPhoto = {
|
||||||
@ -500,6 +501,23 @@ export class AppChatsManager {
|
|||||||
channel: this.getChannelInput(id)
|
channel: this.getChannelInput(id)
|
||||||
}).then(this.onChatUpdated.bind(this, id));
|
}).then(this.onChatUpdated.bind(this, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public deleteChatUser(id: number, userID: number) {
|
||||||
|
return apiManager.invokeApi('messages.deleteChatUser', {
|
||||||
|
chat_id: id,
|
||||||
|
user_id: appUsersManager.getUserInput(userID)
|
||||||
|
}).then(this.onChatUpdated.bind(this, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public leaveChat(id: number) {
|
||||||
|
return this.deleteChatUser(id, appUsersManager.getSelf().id).then(() => {
|
||||||
|
return appMessagesManager.flushHistory(-id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public leave(id: number) {
|
||||||
|
return this.isChannel(id) ? this.leaveChannel(id) : this.leaveChat(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new AppChatsManager();
|
export default new AppChatsManager();
|
||||||
|
@ -362,6 +362,12 @@ export class AppImManager {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$rootScope.$on('dialog_drop', (e) => {
|
||||||
|
if(e.detail.peerID == this.peerID) {
|
||||||
|
this.setPeer(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$rootScope.$on('apiUpdate', (e) => {
|
$rootScope.$on('apiUpdate', (e) => {
|
||||||
let update = e.detail;
|
let update = e.detail;
|
||||||
|
|
||||||
|
@ -2096,14 +2096,9 @@ export class AppMessagesManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private doFlushHistory(inputPeer: any, justClear: boolean): Promise<true> {
|
private doFlushHistory(inputPeer: any, justClear?: true): Promise<true> {
|
||||||
let flags = 0;
|
|
||||||
if(justClear) {
|
|
||||||
flags |= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return apiManager.invokeApi('messages.deleteHistory', {
|
return apiManager.invokeApi('messages.deleteHistory', {
|
||||||
flags: flags,
|
just_clear: justClear,
|
||||||
peer: inputPeer,
|
peer: inputPeer,
|
||||||
max_id: 0
|
max_id: 0
|
||||||
}).then((affectedHistory) => {
|
}).then((affectedHistory) => {
|
||||||
@ -2124,7 +2119,7 @@ export class AppMessagesManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async flushHistory(peerID: number, justClear: boolean) {
|
public async flushHistory(peerID: number, justClear?: true) {
|
||||||
if(appPeersManager.isChannel(peerID)) {
|
if(appPeersManager.isChannel(peerID)) {
|
||||||
let promise = this.getHistory(peerID, 0, 1);
|
let promise = this.getHistory(peerID, 0, 1);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user