|
@@ -22,17 +22,20 @@ import {AvatarControllerModel} from './avatar';
|
|
|
import ControllerModelMode = threema.ControllerModelMode;
|
|
|
|
|
|
export class GroupControllerModel implements threema.ControllerModel<threema.GroupReceiver> {
|
|
|
+ private logTag = '[GroupControllerModel]';
|
|
|
|
|
|
private $log: ng.ILogService;
|
|
|
private $translate: ng.translate.ITranslateService;
|
|
|
private $mdDialog: ng.material.IDialogService;
|
|
|
public members: string[];
|
|
|
public name: string;
|
|
|
+ public access: threema.GroupReceiverAccess;
|
|
|
public subject: string;
|
|
|
+
|
|
|
public isLoading = false; // TODO: Show loading indicator
|
|
|
|
|
|
private addContactPlaceholder: string;
|
|
|
- private group: threema.GroupReceiver;
|
|
|
+ private group: threema.GroupReceiver | null;
|
|
|
private webClientService: WebClientService;
|
|
|
private avatarController: AvatarControllerModel;
|
|
|
private mode: ControllerModelMode;
|
|
@@ -46,7 +49,13 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
this.$translate = $translate;
|
|
|
this.$mdDialog = $mdDialog;
|
|
|
|
|
|
- this.group = group;
|
|
|
+ if (group === undefined) {
|
|
|
+ if (mode !== ControllerModelMode.NEW) {
|
|
|
+ throw new Error('GroupControllerModel: Group may not be undefined for mode ' + mode);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.group = group;
|
|
|
+ }
|
|
|
this.mode = mode;
|
|
|
this.webClientService = webClientService;
|
|
|
this.addContactPlaceholder = $translate.instant('messenger.GROUP_SELECT_CONTACTS');
|
|
@@ -54,17 +63,19 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
switch (this.getMode()) {
|
|
|
case ControllerModelMode.EDIT:
|
|
|
this.subject = $translate.instant('messenger.EDIT_RECEIVER');
|
|
|
- this.name = this.group.displayName;
|
|
|
- this.members = this.group.members;
|
|
|
+ this.name = this.group!.displayName;
|
|
|
+ this.members = this.group!.members;
|
|
|
this.avatarController = new AvatarControllerModel(
|
|
|
- this.$log, this.webClientService, this.group,
|
|
|
+ this.$log, this.webClientService, this.group!,
|
|
|
);
|
|
|
+ this.access = this.group!.access;
|
|
|
break;
|
|
|
|
|
|
case ControllerModelMode.VIEW:
|
|
|
case ControllerModelMode.CHAT:
|
|
|
- this.subject = this.group.displayName;
|
|
|
- this.members = this.group.members;
|
|
|
+ this.subject = this.group!.displayName;
|
|
|
+ this.members = this.group!.members;
|
|
|
+ this.access = this.group!.access;
|
|
|
break;
|
|
|
|
|
|
case ControllerModelMode.NEW:
|
|
@@ -76,7 +87,7 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
- $log.error('Invalid controller model mode: ', this.getMode());
|
|
|
+ $log.error(this.logTag, 'Invalid controller model mode: ', this.getMode());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -103,10 +114,10 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
}
|
|
|
|
|
|
public canEdit(): boolean {
|
|
|
- return this.group.access !== undefined && (
|
|
|
- this.group.access.canChangeAvatar === true
|
|
|
- || this.group.access.canChangeName === true
|
|
|
- || this.group.access.canChangeMembers === true
|
|
|
+ return this.access !== undefined && (
|
|
|
+ this.access.canChangeAvatar === true
|
|
|
+ || this.access.canChangeName === true
|
|
|
+ || this.access.canChangeMembers === true
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -130,8 +141,12 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
}
|
|
|
|
|
|
private reallyClean(): any {
|
|
|
+ if (!this.group) {
|
|
|
+ this.$log.error(this.logTag, 'reallyClean: Group is null');
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!this.canClean()) {
|
|
|
- this.$log.error('not allowed to clean this contact');
|
|
|
+ this.$log.error(this.logTag, 'Not allowed to clean this group');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -142,7 +157,7 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
// TODO: Handle this properly / show an error message
|
|
|
- this.$log.error(`Cleaning receiver conversation failed: ${error}`);
|
|
|
+ this.$log.error(this.logTag, `Cleaning receiver conversation failed: ${error}`);
|
|
|
this.isLoading = false;
|
|
|
});
|
|
|
}
|
|
@@ -152,6 +167,10 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
}
|
|
|
|
|
|
public leave(ev): void {
|
|
|
+ if (!this.group) {
|
|
|
+ this.$log.error(this.logTag, 'leave: Group is null');
|
|
|
+ return;
|
|
|
+ }
|
|
|
const confirm = this.$mdDialog.confirm()
|
|
|
.title(this.$translate.instant('messenger.GROUP_LEAVE'))
|
|
|
.textContent(this.$translate.instant(
|
|
@@ -163,20 +182,20 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
.cancel(this.$translate.instant('common.CANCEL'));
|
|
|
|
|
|
this.$mdDialog.show(confirm).then(() => {
|
|
|
- this.reallyLeave();
|
|
|
+ this.reallyLeave(this.group!);
|
|
|
}, () => {
|
|
|
- this.$log.debug('leave canceled');
|
|
|
+ this.$log.debug(this.logTag, 'Leave canceled');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private reallyLeave(): void {
|
|
|
- if (!this.group.access.canLeave) {
|
|
|
- this.$log.error('cannot leave group');
|
|
|
+ private reallyLeave(group: threema.GroupReceiver): void {
|
|
|
+ if (!group.access.canLeave) {
|
|
|
+ this.$log.error(this.logTag, 'Cannot leave group');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.isLoading = true;
|
|
|
- this.webClientService.leaveGroup(this.group)
|
|
|
+ this.webClientService.leaveGroup(group)
|
|
|
.then(() => {
|
|
|
this.isLoading = false;
|
|
|
})
|
|
@@ -188,6 +207,11 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
}
|
|
|
|
|
|
public delete(ev): void {
|
|
|
+ if (!this.group) {
|
|
|
+ this.$log.error(this.logTag, 'delete: Group is null');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const confirm = this.$mdDialog.confirm()
|
|
|
.title(this.$translate.instant('messenger.GROUP_DELETE'))
|
|
|
.textContent(this.$translate.instant('messenger.GROUP_DELETE_REALLY'))
|
|
@@ -196,24 +220,24 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
.cancel(this.$translate.instant('common.CANCEL'));
|
|
|
|
|
|
this.$mdDialog.show(confirm).then(() => {
|
|
|
- this.reallyDelete();
|
|
|
+ this.reallyDelete(this.group!);
|
|
|
}, () => {
|
|
|
this.$log.debug('delete canceled');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private reallyDelete(): void {
|
|
|
- if (!this.group.access.canDelete) {
|
|
|
+ private reallyDelete(group: threema.GroupReceiver): void {
|
|
|
+ if (!this.access.canDelete) {
|
|
|
this.$log.error('can not delete group');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.isLoading = true;
|
|
|
- this.webClientService.deleteGroup(this.group)
|
|
|
+ this.webClientService.deleteGroup(group)
|
|
|
.then(() => {
|
|
|
this.isLoading = false;
|
|
|
if (this.onRemovedCallback) {
|
|
|
- this.onRemovedCallback(this.group.id);
|
|
|
+ this.onRemovedCallback(group.id);
|
|
|
}
|
|
|
})
|
|
|
.catch((error) => {
|
|
@@ -224,8 +248,12 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
}
|
|
|
|
|
|
public sync(ev): void {
|
|
|
- if (!this.group.access.canSync) {
|
|
|
- this.$log.error('cannot sync group');
|
|
|
+ if (!this.group) {
|
|
|
+ this.$log.error(this.logTag, 'sync: Group is null');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.access.canSync) {
|
|
|
+ this.$log.error(this.logTag, 'Cannot sync group');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -244,7 +272,7 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
switch (this.getMode()) {
|
|
|
case ControllerModelMode.EDIT:
|
|
|
return this.webClientService.modifyGroup(
|
|
|
- this.group.id,
|
|
|
+ this.group!.id,
|
|
|
this.members,
|
|
|
this.name,
|
|
|
this.avatarController.avatarChanged ? this.avatarController.getAvatar() : undefined,
|
|
@@ -256,8 +284,8 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
this.avatarController.avatarChanged ? this.avatarController.getAvatar() : undefined,
|
|
|
);
|
|
|
default:
|
|
|
- this.$log.error('not allowed to save group');
|
|
|
-
|
|
|
+ this.$log.error(this.logTag, 'Cannot save group, invalid mode');
|
|
|
+ return Promise.reject('Cannot save group, invalid mode');
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -279,7 +307,7 @@ export class GroupControllerModel implements threema.ControllerModel<threema.Gro
|
|
|
this.$mdDialog.show(
|
|
|
this.$mdDialog.alert()
|
|
|
.clickOutsideToClose(true)
|
|
|
- .title(this.group.displayName)
|
|
|
+ .title(this.group ? this.group.displayName : 'Error')
|
|
|
.textContent(this.$translate.instant('validationError.modifyReceiver.' + errorCode))
|
|
|
.ok(this.$translate.instant('common.OK')),
|
|
|
);
|