Skip to content

Commit

Permalink
Merge pull request #942 from AiursoftWeb/dev-refactor
Browse files Browse the repository at this point in the history
Use me as a repo.
  • Loading branch information
Anduin2017 committed Feb 13, 2021
2 parents 87a0b1c + 16a68f6 commit 86ab671
Show file tree
Hide file tree
Showing 33 changed files with 316 additions and 286 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -6,9 +6,9 @@

[![Build status](https://aiursoft.visualstudio.com/Star/_apis/build/status/Kahla%20App%20Build)](https://aiursoft.visualstudio.com/Star/_build/latest?definitionId=4)
[![GitHub Release](https://img.shields.io/github/release/AiursoftWeb/Kahla.App.svg?style=flat)]()
[![Maintainability](https://api.codeclimate.com/v1/badges/b7d4a3f5746bcbbe99c1/maintainability)](https://codeclimate.com/github/AiursoftWeb/Kahla.App/maintainability)
![Website](https://img.shields.io/website?url=https%3A%2F%2Fweb.kahla.app)
[![npm](https://img.shields.io/npm/v/kahla.svg?style=flat)](https://www.npmjs.com/package/kahla)
[![Issues](https://img.shields.io/github/issues/AiursoftWeb/Kahla.App.svg)](https://github.com/AiursoftWeb/Kahla.App/issues)
![GitHub all releases](https://img.shields.io/github/downloads/AiursoftWeb/Kahla.App/total)
[![GitHub contributors](https://img.shields.io/github/contributors/AiursoftWeb/Kahla.App.svg?style=flat)](https://github.com/AiursoftWeb/Kahla.App/graphs/contributors)
[![LICENSE](https://img.shields.io/github/license/AiursoftWeb/Kahla.App)](https://github.com/AiursoftWeb/Kahla.App/blob/dev/LICENSE)

Expand Down
34 changes: 29 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "kahla",
"version": "4.3.3",
"version": "4.3.5",
"description": "Kahla is a cross-platform business messaging app.",
"author": "Aiursoft <service@aiursoft.com> (https://www.aiursoft.com/)",
"build": {
Expand Down
10 changes: 1 addition & 9 deletions src/app/Controllers/add-friend.component.ts
Expand Up @@ -3,7 +3,6 @@ import { FriendsApiService } from '../Services/Api/FriendsApiService';
import { Values } from '../values';
import { SearchResult } from '../Models/SearchResult';
import { FriendshipService } from '../Services/FriendshipService';
import { ProbeService } from '../Services/ProbeService';

@Component({
templateUrl: '../Views/add-friend.html',
Expand All @@ -22,8 +21,7 @@ export class AddFriendComponent implements OnInit {

constructor(
private friendsApiService: FriendsApiService,
public friendshipService: FriendshipService,
private probeService: ProbeService,
public friendshipService: FriendshipService
) {
}

Expand All @@ -48,12 +46,6 @@ export class AddFriendComponent implements OnInit {
private callSearchApi(term: string): void {
this.friendsApiService.SearchEverything(term.trim(), this.searchNumbers).subscribe(result => {
if (result.code === 0) {
result.users.forEach(user => {
user.avatarURL = this.probeService.encodeProbeFileUrl(user.iconFilePath);
});
result.groups.forEach(group => {
group.avatarURL = this.probeService.encodeProbeFileUrl(group.imagePath);
});
this.results = result;
if (this.showUsers && result.usersCount === 0 && result.groupsCount !== 0) {
this.showUsers = false;
Expand Down
28 changes: 13 additions & 15 deletions src/app/Controllers/advanced-setting.component.ts
Expand Up @@ -2,8 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { AuthApiService } from '../Services/Api/AuthApiService';
import { KahlaUser } from '../Models/KahlaUser';
import Swal from 'sweetalert2';
import { CacheService } from '../Services/CacheService';
import { ProbeService } from '../Services/ProbeService';
import { MeRepo } from '../Repos/MeRepo';


@Component({
Expand All @@ -19,34 +18,33 @@ export class AdvancedSettingComponent implements OnInit {

constructor(
private authApiService: AuthApiService,
private cacheService: CacheService,
private probeService: ProbeService,
private meRepo: MeRepo
) {
}

public async ngOnInit(): Promise<void> {
if (this.cacheService.cachedData.me) {
this.me = Object.assign({}, this.cacheService.cachedData.me);
} else {
const me = await this.authApiService.Me();
this.me = me.value;
this.me.avatarURL = this.probeService.encodeProbeFileUrl(this.me.iconFilePath);
// Fast render
const cachedResponse = await this.meRepo.getMe();
this.me = cachedResponse.response;

// Full load
if (!cachedResponse.isLatest) {
this.me = (await this.meRepo.getMe(false)).response;
}
}

public async updateSettings(): Promise<void> {
this.updatingSetting = true;
const res = await this.authApiService.UpdateClientSetting(null,
const response = await this.authApiService.UpdateClientSetting(null,
this.me.enableEmailNotification,
this.me.enableEnterToSendMessage,
this.me.enableInvisiable,
this.me.markEmailPublic,
this.me.listInSearchResult);
if (res.code === 0) {
this.cacheService.cachedData.me = Object.assign({}, this.me);
this.cacheService.saveCache();
if (response.code === 0) {
this.meRepo.overrideCache(this.me);
} else {
Swal.fire('Error', res.message, 'error');
Swal.fire('Error', response.message, 'error');
}
this.updatingSetting = false;
}
Expand Down
16 changes: 14 additions & 2 deletions src/app/Controllers/app.component.ts
Expand Up @@ -6,23 +6,26 @@ import { Router } from '@angular/router';
import { HomeService } from '../Services/HomeService';
import { CacheService } from '../Services/CacheService';
import { BrowserContextService } from '../Services/BrowserContextService';
import { MeRepo } from '../Repos/MeRepo';
import { KahlaUser } from '../Models/KahlaUser';

@Component({
selector: 'app-kahla',
templateUrl: '../Views/app.html',
styleUrls: ['../Styles/app.scss']
})


export class AppComponent implements OnInit {
public me: KahlaUser;

constructor(
private initService: InitService,
private themeService: ThemeService,
public cacheService: CacheService,
public route: Router,
public homeService: HomeService,
private browserContext: BrowserContextService) {
private browserContext: BrowserContextService,
private meRepo: MeRepo) {
}

@HostListener('window:popstate', [])
Expand Down Expand Up @@ -65,5 +68,14 @@ export class AppComponent implements OnInit {
// Temporary apply the local theme setting
this.themeService.ApplyThemeFromLocal();
await this.initService.init();

// Fast render
const cachedResponse = await this.meRepo.getMe();
this.me = cachedResponse.response;

// Full load
if (!cachedResponse.isLatest) {
this.me = (await this.meRepo.getMe(false)).response;
}
}
}
4 changes: 1 addition & 3 deletions src/app/Controllers/conversations.component.ts
Expand Up @@ -24,9 +24,7 @@ export class ConversationsComponent implements OnInit {
}

public ngOnInit(): void {
if (this.cacheService.cachedData.me) {
this.cacheService.updateConversation();
}
this.cacheService.updateConversation();
setTimeout(() => {
if (this.homeService.floatingHomeWrapper === null) {
document.body.scroll(0, 0);
Expand Down
7 changes: 1 addition & 6 deletions src/app/Controllers/discover.component.ts
Expand Up @@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
import { FriendsApiService } from '../Services/Api/FriendsApiService';
import { DiscoverUser } from '../Models/DiscoverUser';
import { Values } from '../values';
import { ProbeService } from '../Services/ProbeService';
import { SwalToast } from '../Helpers/Toast';
import Swal from 'sweetalert2';

Expand All @@ -19,8 +18,7 @@ export class DiscoverComponent implements OnInit {
public loadingImgURL = Values.loadingImgURL;

constructor(
private friendsApiService: FriendsApiService,
private probeService: ProbeService,
private friendsApiService: FriendsApiService
) {
}

Expand All @@ -31,9 +29,6 @@ export class DiscoverComponent implements OnInit {
public loadMore(): void {
this.loading = true;
this.friendsApiService.Discover(this.amount).subscribe(users => {
users.items.forEach(item => {
item.targetUser.avatarURL = this.probeService.encodeProbeFileUrl(item.targetUser.iconFilePath);
});
const top = window.scrollY;
this.users = users.items;
if (this.users.length < this.amount) {
Expand Down
15 changes: 8 additions & 7 deletions src/app/Controllers/friends.component.ts
Expand Up @@ -9,6 +9,7 @@ import { SearchResult } from '../Models/SearchResult';
import { KahlaUser } from '../Models/KahlaUser';
import { FriendsApiService } from '../Services/Api/FriendsApiService';
import { GroupsResult } from '../Models/GroupsResults';
import { MeRepo } from '../Repos/MeRepo';

@Component({
selector: 'app-friends',
Expand All @@ -34,14 +35,13 @@ export class FriendsComponent implements OnInit, DoCheck, AfterViewInit {
private friendsApiService: FriendsApiService,
private router: Router,
private messageService: MessageService,
public cacheService: CacheService) {
public cacheService: CacheService,
private meRepo: MeRepo) {
}

public ngOnInit(): void {
if (this.cacheService.cachedData.me && !this.cacheService.cachedData.friends) {
this.cacheService.updateFriends();
this.cacheService.updateRequests();
}
this.cacheService.updateFriends();
this.cacheService.updateRequests();
}

ngAfterViewInit(): void {
Expand All @@ -51,8 +51,9 @@ export class FriendsComponent implements OnInit, DoCheck, AfterViewInit {
}
}

public createGroup(): void {
if (!this.cacheService.cachedData.me.emailConfirmed) {
public async createGroup(): Promise<void> {
const me = await this.meRepo.getMe();
if (!me.response.emailConfirmed) {
Swal.fire('Your email is not verified!', 'You can\'t create group until your email is verified.', 'error');
return;
}
Expand Down
30 changes: 9 additions & 21 deletions src/app/Controllers/group.component.ts
Expand Up @@ -8,8 +8,8 @@ import { Values } from '../values';
import { GroupConversation } from '../Models/GroupConversation';
import { ConversationApiService } from '../Services/Api/ConversationApiService';
import { MessageService } from '../Services/MessageService';
import { ProbeService } from '../Services/ProbeService';
import { SwalToast } from '../Helpers/Toast';
import { MeRepo } from '../Repos/MeRepo';

@Component({
templateUrl: '../Views/group.html',
Expand All @@ -34,41 +34,29 @@ export class GroupComponent implements OnInit {
private router: Router,
private cacheService: CacheService,
public messageService: MessageService,
private probeService: ProbeService,
private meRepo: MeRepo
) {
}

public ngOnInit(): void {
public async ngOnInit(): Promise<void> {
this.route.params
.pipe(
switchMap((params: Params) => this.conversationApiService.ConversationDetail(+params['id'])),
filter(t => t.code === 0),
map(t => t.value)
)
.subscribe(conversation => {
.subscribe(async conversation => {
const me = await this.meRepo.getMe();
this.messageService.conversation = conversation;
this.conversation = <GroupConversation>conversation;
this.groupMembers = conversation.users.length;
this.conversation.avatarURL = this.probeService.encodeProbeFileUrl((<GroupConversation>this.conversation).groupImagePath);
this.conversation.users.forEach(user => {
user.user.avatarURL = this.probeService.encodeProbeFileUrl(user.user.iconFilePath);
try {
if (user.userId === this.cacheService.cachedData.me.id) {
this.muted = user.muted;
}
} catch (error) {
setTimeout(() => {
if (user.userId === this.cacheService.cachedData.me.id) {
this.muted = user.muted;
}
}, 1000);
}
});
this.muted = this.conversation.users.find(t => t.userId === me.response.id).muted;
});
}

public leaveGroup(groupName: string): void {
if (this.conversation.ownerId === this.cacheService.cachedData.me.id) {
public async leaveGroup(groupName: string): Promise<void> {
const me = await this.meRepo.getMe();
if (this.conversation.ownerId === me.response.id) {
Swal.fire('Error', 'You can\'t leave the group without transferring the ownership ' +
'or dissolving the entire group.', 'error');
return;
Expand Down

0 comments on commit 86ab671

Please sign in to comment.