Skip to content

Commit

Permalink
Merge pull request #905 from AiursoftWeb/dev
Browse files Browse the repository at this point in the history
Release 4.2.1
  • Loading branch information
Anduin2017 authored Jul 5, 2020
2 parents 9109d90 + a4577f0 commit 586d34c
Show file tree
Hide file tree
Showing 20 changed files with 374 additions and 287 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kahla",
"version": "4.2.0",
"version": "4.2.1",
"description": "Kahla is a cross-platform business messaging app.",
"author": "Aiursoft <service@aiursoft.com> (https://www.aiursoft.com/)",
"build": {
Expand Down
2 changes: 0 additions & 2 deletions src/app/Controllers/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ElectronService } from 'ngx-electron';
import { ThemeService } from '../Services/ThemeService';
import { Router } from '@angular/router';
import { HomeService } from '../Services/HomeService';
import { MessageService } from '../Services/MessageService';
import { CacheService } from '../Services/CacheService';

@Component({
Expand All @@ -20,7 +19,6 @@ export class AppComponent implements OnInit {
constructor(
private initService: InitService,
private themeService: ThemeService,
public messageService: MessageService,
public cacheService: CacheService,
private _electronService: ElectronService,
public route: Router,
Expand Down
10 changes: 2 additions & 8 deletions src/app/Controllers/conversations.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ContactInfo } from '../Models/ContactInfo';
import { Router } from '@angular/router';
import { CacheService } from '../Services/CacheService';
import { Values } from '../values';
import { MessageService } from '../Services/MessageService';
import { HomeService } from '../Services/HomeService';

@Component({
Expand All @@ -14,13 +13,12 @@ import { HomeService } from '../Services/HomeService';
'../Styles/button.scss',
'../Styles/badge.scss']
})
export class ConversationsComponent implements OnInit, OnDestroy {
export class ConversationsComponent implements OnInit {
public loadingImgURL = Values.loadingImgURL;

constructor(
private router: Router,
public cacheService: CacheService,
public messageService: MessageService,
private homeService: HomeService,
) {
}
Expand Down Expand Up @@ -64,8 +62,4 @@ export class ConversationsComponent implements OnInit, OnDestroy {
this.router.navigate(['/talking', id]);
}
}

public ngOnDestroy(): void {
this.loadingImgURL = null;
}
}
2 changes: 1 addition & 1 deletion src/app/Controllers/file-history.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FileHistoryComponent implements OnInit {
// get access token first
this.loading = true;
this.filesApiService.InitFileAccess(this.conversationId, false).subscribe(t => {
this.accessToken = encodeURIComponent(t.value);
this.accessToken = t.value;
this.loadFiles();
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/app/Controllers/friends.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class FriendsComponent implements OnInit, DoCheck, AfterViewInit {

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

Expand Down
4 changes: 2 additions & 2 deletions src/app/Controllers/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MessageService } from '../Services/MessageService';
import { TimerService } from '../Services/TimerService';
import { HomeService } from '../Services/HomeService';
import { ElectronService } from 'ngx-electron';
import { InitService } from '../Services/InitService';
import { EventService } from '../Services/EventService';

@Component({
selector: 'app-header',
Expand All @@ -30,7 +30,7 @@ export class HeaderComponent {
public messageService: MessageService,
public homeService: HomeService,
public _electronService: ElectronService,
public initService: InitService
public eventService: EventService,
) {}

public goBack(): void {
Expand Down
2 changes: 0 additions & 2 deletions src/app/Controllers/manageGroup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ConversationApiService } from '../Services/Api/ConversationApiService';
import Swal from 'sweetalert2';
import { TimerService } from '../Services/TimerService';
import { UploadService } from '../Services/UploadService';
import { ElectronService } from 'ngx-electron';
import { AiurCollection } from '../Models/AiurCollection';
import { CacheService } from '../Services/CacheService';
import { ProbeService } from '../Services/ProbeService';
Expand All @@ -35,7 +34,6 @@ export class ManageGroupComponent implements OnInit {
private router: Router,
public timerService: TimerService,
public uploadService: UploadService,
public _electronService: ElectronService,
private probeService: ProbeService,
) {

Expand Down
2 changes: 0 additions & 2 deletions src/app/Controllers/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AuthApiService } from '../Services/Api/AuthApiService';
import { Router } from '@angular/router';
import { Values } from '../values';
import { InitService } from '../Services/InitService';
import { MessageService } from '../Services/MessageService';
import Swal from 'sweetalert2';
import { ElectronService } from 'ngx-electron';
import { CacheService } from '../Services/CacheService';
Expand All @@ -24,7 +23,6 @@ export class SettingsComponent implements OnInit {
private authApiService: AuthApiService,
private router: Router,
private initSerivce: InitService,
public messageService: MessageService,
public cacheService: CacheService,
private _electronService: ElectronService,
public homeService: HomeService,
Expand Down
62 changes: 38 additions & 24 deletions src/app/Controllers/talking.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { UploadService } from '../Services/UploadService';
import { MessageService } from '../Services/MessageService';
import { TimerService } from '../Services/TimerService';
import { KahlaUser } from '../Models/KahlaUser';
import { ElectronService } from 'ngx-electron';
import { HeaderComponent } from './header.component';
import { GroupsResult } from '../Models/GroupsResults';
import { FriendshipService } from '../Services/FriendshipService';
Expand Down Expand Up @@ -54,11 +53,12 @@ export class TalkingComponent implements OnInit, OnDestroy {
public lastAutoLoadMoreTimestamp = 0;
public matchedUsers: Array<KahlaUser> = [];
public loadingMore: boolean;
public showMessagesCount = 15;

@ViewChild('imageInput') public imageInput;
@ViewChild('videoInput') public videoInput;
@ViewChild('fileInput') public fileInput;
@ViewChild('header', { static: true }) public header: HeaderComponent;
@ViewChild('header', {static: true}) public header: HeaderComponent;


constructor(
Expand All @@ -71,7 +71,6 @@ export class TalkingComponent implements OnInit, OnDestroy {
public timerService: TimerService,
private friendshipService: FriendshipService,
private themeService: ThemeService,
public _electronService: ElectronService,
public probeService: ProbeService,
) {
}
Expand Down Expand Up @@ -99,11 +98,12 @@ export class TalkingComponent implements OnInit, OnDestroy {
if (window.scrollY <= 0 && document.documentElement.scrollHeight > document.documentElement.clientHeight + 100
&& this.messageService.conversation && !this.messageService.messageLoading && !this.messageService.noMoreMessages) {
const now = Date.now();
if (this.lastAutoLoadMoreTimestamp + 2000 < now) {
const interval = this.showMessagesCount < this.messageService.localMessages.length ? 10 : 2000;
if (this.lastAutoLoadMoreTimestamp + interval < now) {
this.loadMore();
this.lastAutoLoadMoreTimestamp = now;
} else {
setTimeout(() => this.onScroll(), this.lastAutoLoadMoreTimestamp + 2010 - now);
setTimeout(() => this.onScroll(), this.lastAutoLoadMoreTimestamp + interval + 10 - now);
}
}
}
Expand Down Expand Up @@ -164,10 +164,10 @@ export class TalkingComponent implements OnInit, OnDestroy {
this.route.params
.pipe(
switchMap((params: Params) => {
if (!this.uploadService.talkingDestroyed) {
if (!this.messageService.talkingDestroyed) {
this.destroyCurrent();
}
this.uploadService.talkingDestroyed = false;
this.messageService.talkingDestroyed = false;
this.messageService.updateMaxImageWidth();
this.conversationID = Number(params.id);
this.unread = (params.unread && params.unread <= 50) ? Number(params.unread) : 0;
Expand Down Expand Up @@ -203,7 +203,7 @@ export class TalkingComponent implements OnInit, OnDestroy {
map(t => t.value)
)
.subscribe(conversation => {
if (this.conversationID !== conversation.id || this.uploadService.talkingDestroyed) {
if (this.conversationID !== conversation.id || this.messageService.talkingDestroyed) {
return;
}
this.updateConversation(conversation);
Expand Down Expand Up @@ -266,7 +266,7 @@ export class TalkingComponent implements OnInit, OnDestroy {
this.messageService.modifyMessage(tempMessage, false);
this.messageService.localMessages.push(tempMessage);
setTimeout(() => {
this.uploadService.scrollBottom(true);
this.messageService.scrollBottom(true);
}, 0);
const encryptedMessage = AES.encrypt(this.content, this.messageService.conversation.aesKey).toString();
this.conversationApiService.SendMessage(this.messageService.conversation.id, encryptedMessage, tempMessage.id,
Expand All @@ -286,12 +286,15 @@ export class TalkingComponent implements OnInit, OnDestroy {
this.messageService.localMessages.splice(this.messageService.localMessages.indexOf(tempMessage), 1);
this.messageService.showFailedMessages();
this.messageService.reorderLocalMessages();
this.uploadService.scrollBottom(false);
this.messageService.scrollBottom(false);
}
},
next: p => {
this.messageService.localMessages.splice(this.messageService.localMessages.indexOf(tempMessage), 1);
this.messageService.insertMessage(p.value);
const index = this.messageService.localMessages.indexOf(tempMessage);
if (index !== -1) {
this.messageService.localMessages.splice(index, 1);
this.messageService.insertMessage(p.value);
}
}
});
this.content = '';
Expand Down Expand Up @@ -337,7 +340,7 @@ export class TalkingComponent implements OnInit, OnDestroy {
window.scroll(0, window.scrollY + 105);
} else {
if (this.messageService.belowWindowPercent <= 0.2) {
this.uploadService.scrollBottom(false);
this.messageService.scrollBottom(false);
} else {
window.scroll(0, window.scrollY - 105);
}
Expand All @@ -364,7 +367,7 @@ export class TalkingComponent implements OnInit, OnDestroy {
this.uploadService.upload(files, this.messageService.conversation.id, this.messageService.conversation.aesKey, fileType)
?.then(t => {
this.messageService.insertMessage(t.value);
setTimeout(() => this.uploadService.scrollBottom(true), 0);
setTimeout(() => this.messageService.scrollBottom(true), 0);
});
}
}
Expand All @@ -387,7 +390,7 @@ export class TalkingComponent implements OnInit, OnDestroy {
this.uploadService.upload(blob, this.messageService.conversation.id,
this.messageService.conversation.aesKey, FileType.Image)?.then(t => {
this.messageService.insertMessage(t.value);
setTimeout(() => this.uploadService.scrollBottom(true), 0);
setTimeout(() => this.messageService.scrollBottom(true), 0);
});
}
URL.revokeObjectURL(urlString);
Expand Down Expand Up @@ -435,7 +438,7 @@ export class TalkingComponent implements OnInit, OnDestroy {
this.uploadService.upload(t, this.messageService.conversation.id, this.messageService.conversation.aesKey, fileType)
?.then(msg => {
this.messageService.insertMessage(msg.value);
setTimeout(() => this.uploadService.scrollBottom(true), 0);
setTimeout(() => this.messageService.scrollBottom(true), 0);
});
});
this.removeDragData(event);
Expand All @@ -458,7 +461,7 @@ export class TalkingComponent implements OnInit, OnDestroy {
if (this.recording) {
this.mediaRecorder.stop();
} else {
navigator.mediaDevices.getUserMedia({ audio: true })
navigator.mediaDevices.getUserMedia({audio: true})
.then(stream => {
this.recording = true;
this.mediaRecorder = new MediaRecorder(stream);
Expand All @@ -470,7 +473,8 @@ export class TalkingComponent implements OnInit, OnDestroy {
this.mediaRecorder.addEventListener('stop', () => {
this.recording = false;
const audioBlob = new File(audioChunks, `voiceMsg_${new Date().getTime()}.opus`);
this.uploadService.upload(audioBlob, this.conversationID, this.messageService.conversation.aesKey, FileType.Audio);
this.uploadService.upload(audioBlob, this.conversationID, this.messageService.conversation.aesKey, FileType.Audio)
.then(() => this.messageService.scrollBottom(true));
clearTimeout(this.forceStopTimeout);
stream.getTracks().forEach(track => track.stop());
});
Expand Down Expand Up @@ -524,7 +528,7 @@ export class TalkingComponent implements OnInit, OnDestroy {
}

public destroyCurrent() {
this.uploadService.talkingDestroyed = true;
this.messageService.talkingDestroyed = true;
this.content = null;
this.showPanel = null;
this.messageService.resetVariables();
Expand Down Expand Up @@ -572,15 +576,25 @@ export class TalkingComponent implements OnInit, OnDestroy {
}

public async loadMore() {
if (!this.messageService.noMoreMessages) {
const oldScrollHeight = document.documentElement.scrollHeight;
if (this.showMessagesCount < this.messageService.localMessages.length) {
this.showMessagesCount += 15;
} else if (!this.messageService.noMoreMessages) {
this.loadingMore = true;
const oldScrollHeight = document.documentElement.scrollHeight;
await this.messageService.getMessages(-1,
this.messageService.conversation.id, this.messageService.localMessages[0].id, 15);
this.loadingMore = false;
setTimeout(() => {
window.scroll(0, document.documentElement.scrollHeight - oldScrollHeight);
}, 0);
this.showMessagesCount = this.messageService.localMessages.length;
} else {
return;
}
setTimeout(() => {
window.scroll(0, document.documentElement.scrollHeight - oldScrollHeight);
}, 0);
}

public takeMessages(): Message[] {
return this.messageService.localMessages.slice(Math.max(this.messageService.localMessages.length - this.showMessagesCount, 0));
}

}
23 changes: 19 additions & 4 deletions src/app/Controllers/user.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FriendsApiService } from '../Services/Api/FriendsApiService';
import { KahlaUser } from '../Models/KahlaUser';
import { CacheService } from '../Services/CacheService';
import Swal from 'sweetalert2';
import { Values } from '../values';
import { MessageService } from '../Services/MessageService';
import { TimerService } from '../Services/TimerService';
import { Request } from '../Models/Request';
import { ProbeService } from '../Services/ProbeService';
import { Subscription } from 'rxjs';
import { EventService } from '../Services/EventService';
import { filter } from 'rxjs/operators';
import { EventType } from '../Models/Events/EventType';
import { FriendsChangedEvent } from '../Models/Events/FriendsChangedEvent';
import { FriendDeletedEvent } from '../Models/Events/FriendDeletedEvent';

@Component({
templateUrl: '../Views/user.html',
Expand All @@ -18,29 +23,35 @@ import { ProbeService } from '../Services/ProbeService';
'../Styles/badge.scss']
})

export class UserComponent implements OnInit {
export class UserComponent implements OnInit, OnDestroy {
public info: KahlaUser;
public conversationId: number;
public areFriends: boolean;
public loadingImgURL = Values.loadingImgURL;
public sentRequest: boolean;
public pendingRequest: Request;
public updateSubscription: Subscription;

constructor(
private route: ActivatedRoute,
private friendsApiService: FriendsApiService,
private router: Router,
public cacheService: CacheService,
public messageService: MessageService,
public timerService: TimerService,
private probeService: ProbeService,
private eventService: EventService
) {
}

public ngOnInit(): void {
this.route.params.subscribe(t => {
this.updateFriendInfo(t.id);
});
this.updateSubscription = this.eventService.onMessage
.pipe(filter(t => this.info &&
((t.type === EventType.FriendsChangedEvent && (<FriendsChangedEvent>t).request.targetId === this.info.id) ||
(t.type === EventType.FriendDeletedEvent && (<FriendDeletedEvent>t).trigger.id === this.info.id))))
.subscribe(() => this.updateFriendInfo(this.info.id));
}

public updateFriendInfo(userId: string) {
Expand Down Expand Up @@ -141,4 +152,8 @@ export class UserComponent implements OnInit {
public shareUser() {
this.router.navigate(['/share-target', {message: `[user]${this.info.id}`}]);
}

ngOnDestroy(): void {
this.updateSubscription?.unsubscribe();
}
}
Loading

0 comments on commit 586d34c

Please sign in to comment.