Skip to content

Commit

Permalink
Merge pull request #520 from AiursoftWeb/timer
Browse files Browse the repository at this point in the history
only let owner set timer
  • Loading branch information
Anduin2017 committed Jun 6, 2019
2 parents 8e3bdaf + 5717c95 commit 2d19cfc
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 34 deletions.
56 changes: 27 additions & 29 deletions src/app/Controllers/group.component.ts
Expand Up @@ -45,39 +45,35 @@ export class GroupComponent implements OnInit {
}

public ngOnInit(): void {
if (!this.messageService.conversation) {
this.route.params
.pipe(
switchMap((params: Params) => this.conversationApiService.ConversationDetail(+params['id'])),
filter(t => t.code === 0),
map(t => t.value)
)
.subscribe(conversation => {
this.messageService.conversation = conversation;
this.conversation = <GroupConversation>conversation;
this.groupMembers = conversation.users.length;
this.conversation.avatarURL = Values.fileAddress + (<GroupConversation>this.conversation).groupImageKey;
this.conversation.users.forEach(user => {
user.user.avatarURL = Values.fileAddress + user.user.headImgFileKey;
try {
this.route.params
.pipe(
switchMap((params: Params) => this.conversationApiService.ConversationDetail(+params['id'])),
filter(t => t.code === 0),
map(t => t.value)
)
.subscribe(conversation => {
this.messageService.conversation = conversation;
this.conversation = <GroupConversation>conversation;
this.groupMembers = conversation.users.length;
this.conversation.avatarURL = Values.fileAddress + (<GroupConversation>this.conversation).groupImageKey;
this.conversation.users.forEach(user => {
user.user.avatarURL = Values.fileAddress + user.user.headImgFileKey;
try {
if (user.userId === this.messageService.me.id) {
this.muted = user.muted;
}
} catch (error) {
setTimeout(() => {
if (user.userId === this.messageService.me.id) {
this.muted = user.muted;
}
} catch (error) {
setTimeout(() => {
if (user.userId === this.messageService.me.id) {
this.muted = user.muted;
}
}, 1000);
}
});
this.messageService.searchUser('', false).forEach(user => {
this.inputOptions[user.id] = user.nickName;
});
}, 1000);
}
});
} else {
this.conversation = <GroupConversation>this.messageService.conversation;
}
this.messageService.searchUser('', false).forEach(user => {
this.inputOptions[user.id] = user.nickName;
});
});
}

public leaveGroup(groupName: string): void {
Expand All @@ -98,6 +94,7 @@ export class GroupComponent implements OnInit {
if (response.code === 0) {
Swal.fire('Success', response.message, 'success');
this.cache.updateConversation();
this.cache.updateFriends();
this.router.navigate(['/friends']);
} else {
Swal.fire('Error', response.message, 'error');
Expand Down Expand Up @@ -134,6 +131,7 @@ export class GroupComponent implements OnInit {
this.groupsApiService.TransferOwner(this.conversation.groupName, willTransfer.value)
.subscribe(response => {
if (response.code === 0) {
(<GroupConversation>this.messageService.conversation).ownerId = willTransfer.value;
Swal.fire('Success', response.message, 'success');
} else {
Swal.fire('Error', response.message, 'error');
Expand Down
12 changes: 12 additions & 0 deletions src/app/Services/MessageService.ts
Expand Up @@ -24,6 +24,7 @@ import { Router } from '@angular/router';
import { UserGroupRelation } from '../Models/KahlaUsers';
import { SomeoneLeftEvent } from '../Models/SomeoneLeftEvent';
import { NewMemberEvent } from '../Models/NewMemberEvent';
import { GroupConversation } from '../Models/GroupConversation';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -338,4 +339,15 @@ export class MessageService {
const regex = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
return regex.test(text);
}

public checkOwner(id?: string): boolean {
if (this.conversation && this.me) {
if (this.conversation.discriminator === 'GroupConversation') {
return (<GroupConversation>this.conversation).ownerId === (id ? id : this.me.id);
} else {
return true;
}
}
return false;
}
}
1 change: 1 addition & 0 deletions src/app/Services/TimerService.ts
Expand Up @@ -31,6 +31,7 @@ export class TimerService {
if (selected.value) {
this.conversationApiService.UpdateMessageLifeTime(conversationId, selected.value)
.subscribe(result => {
this.updateDestructTime(selected.value);
if (result.code !== 0) {
Swal.fire({
title: 'Error!',
Expand Down
6 changes: 3 additions & 3 deletions src/app/Views/group.html
Expand Up @@ -12,7 +12,7 @@
</div>

<div class="menu-holder"></div>
<div class="menu-button" *ngIf="conversation" (click)="timerService.setTimer(conversation.id)">
<div class="menu-button" *ngIf="messageService.checkOwner()" (click)="timerService.setTimer(conversation.id)">
<div class="img">
<i class="fa fa-clock-o"></i>
</div>
Expand All @@ -33,7 +33,7 @@
<input id="toggleMute" class="tgl" type="checkbox" [checked]="!muted" (click)="mute()"/>
<label for="toggleMute" class="tgl-btn"></label>
</div>
<div class="menu-button" *ngIf="messageService.me && conversation && conversation.ownerId == messageService.me.id" (click)="transferOwner()">
<div class="menu-button" *ngIf="messageService.checkOwner()" (click)="transferOwner()">
<div class="img">
<i class="fa fa-exchange"></i>
</div>
Expand All @@ -52,7 +52,7 @@
<div class="text">
{{e.user.nickName}}
</div>
<label class="badge badge-primary" *ngIf="conversation.ownerId == e.userId">Owner</label>
<label class="badge badge-primary" *ngIf="messageService.checkOwner(e.userId)">Owner</label>
</div>
</div>
<div class="menu-holder"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/Views/header.html
Expand Up @@ -5,7 +5,7 @@
<div *ngIf="headerService.timer"></div>
<div *ngIf="!headerService.returnButton"></div>
<div class="text">{{headerService.title}}</div>
<div *ngIf="headerService.timer && messageService.conversation" class="user-button headerButton" (click)="timerService.setTimer(messageService.conversation.id)">
<div *ngIf="headerService.timer && messageService.conversation" class="user-button headerButton" (click)="(messageService.checkOwner()) && timerService.setTimer(messageService.conversation.id)">
<i class="fa fa-clock-o"></i>
<div class="dot reddot">
{{timerService.destructTime}}
Expand Down
2 changes: 1 addition & 1 deletion src/app/Views/talking.html
Expand Up @@ -12,7 +12,7 @@
<span
*ngIf="messageService.groupConversation && messageService.me && message.senderId != messageService.me.id"
[ngStyle]="{'color': messageService.getGroupColor(message)}">{{ message.sender.nickName }}
<label class="badge badge-primary" *ngIf="messageService.conversation.ownerId == message.senderId">Owner</label>
<label class="badge badge-primary" *ngIf="messageService.checkOwner(message.senderId)">Owner</label>
<label class="badge badge-secondary"
*ngIf="message.sender.emailConfirmed && message.sender.email && message.sender.email.endsWith('@aiursoft.com')">Staff</label>
</span>
Expand Down

0 comments on commit 2d19cfc

Please sign in to comment.