diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts
index 7756d8409..17c9799fa 100644
--- a/src/app/pages/chat/chat.page.ts
+++ b/src/app/pages/chat/chat.page.ts
@@ -12,7 +12,7 @@ import {
import { ModalController, Platform } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service';
-import { wsChatMethodsService as wsChatMethodsService} from 'src/app/services/chat/chat.service'
+import { WsChatMethodsService} from 'src/app/services/chat/ws-chat-methods.service'
import { GroupMessagesPage } from './group-messages/group-messages.page';
import { ContactsPage } from './messages/contacts/contacts.page';
import { MessagesPage } from './messages/messages.page';
@@ -127,7 +127,7 @@ export class ChatPage implements OnInit {
private sqlservice: SqliteService,
private platform: Platform,
private storageservice: StorageService,
- public wsChatMethodsService: wsChatMethodsService
+ public wsChatMethodsService: WsChatMethodsService,
) {
this.loggedUserChat = authService.ValidatedUserChat['data'];
diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts
index 34bf21e39..aff6d21fa 100644
--- a/src/app/pages/chat/messages/messages.page.ts
+++ b/src/app/pages/chat/messages/messages.page.ts
@@ -28,7 +28,7 @@ import { SqliteService } from 'src/app/services/sqlite.service';
import { elementAt } from 'rxjs-compat/operator/elementAt';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
-import { wsChatMethodsService } from 'src/app/services/chat/chat.service'
+import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'
const IMAGE_DIR = 'stored-images';
@@ -96,7 +96,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
private changeDetectorRef: ChangeDetectorRef,
private platform: Platform,
private sqlservice: SqliteService,
- public wsChatMethodsService: wsChatMethodsService
+ public wsChatMethodsService: WsChatMethodsService
) {
this.loggedUser = authService.ValidatedUserChat['data'];
this.roomId = this.navParams.get('roomId');
diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts
index 4385a72a5..b5c8616b7 100644
--- a/src/app/services/chat.service.ts
+++ b/src/app/services/chat.service.ts
@@ -42,7 +42,7 @@ export class ChatService {
headers: this.headers,
};
- console.log("CHAT SERVICE");
+ /* console.log("CHAT SERVICE");
wsService.messages = >this.wsService
.connect(environment.apiWsChatUrl)
@@ -79,7 +79,7 @@ export class ChatService {
return (JSON.stringify(data));
});
- console.log(wsService.messages);
+ console.log(wsService.messages) */;
}
diff --git a/src/app/services/chat/chat.service.spec.ts b/src/app/services/chat/chat.service.spec.ts
deleted file mode 100644
index 760f446a5..000000000
--- a/src/app/services/chat/chat.service.spec.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { TestBed } from '@angular/core/testing';
-
-import { wsChatMethodsService } from './chat.service';
-
-describe('ChatService', () => {
- let service: wsChatMethodsService;
-
- beforeEach(() => {
- TestBed.configureTestingModule({});
- service = TestBed.inject(wsChatMethodsService);
- });
-
- it('should be created', () => {
- expect(service).toBeTruthy();
- });
-});
diff --git a/src/app/services/chat/chat.service.ts b/src/app/services/chat/chat.service.ts
deleted file mode 100644
index 521906bda..000000000
--- a/src/app/services/chat/chat.service.ts
+++ /dev/null
@@ -1,114 +0,0 @@
-import { Injectable } from '@angular/core';
-import { RoomService } from './room.service';
-import { WsChatService } from 'src/app/services/chat/ws-chat.service';
-import { MessageService } from 'src/app/services/chat/message.service'
-import { SessionStore } from 'src/app/store/session.service';
-
-@Injectable({
- providedIn: 'root'
-})
-export class wsChatMethodsService {
-
-
- dm: {[key: string]: RoomService} = {}
- group: {[key: string]: RoomService} = {}
-
- loadingWholeList = false
-
- dmCount = 0;
- groupCount = 0;
-
- constructor(
- private WsChatService: WsChatService
- ) {
-
- (async()=>{
- await this.getAllRooms();
- this.subscribeToRoom()
- })()
-
- }
-
- async getAllRooms () {
- this.loadingWholeList = true
-
- const rooms: any = await this.WsChatService.getRooms();
-
- console.log(rooms)
-
- rooms.result.update.forEach((roomData:any) => {
- let room:RoomService;
-
- room = new RoomService(this.WsChatService, new MessageService())
- room.setData({
- id: this.getRoomId(roomData),
- name: this.getRoomName(roomData),
- lastMessage: this.getRoomLastMessage(roomData),
- _updatedAt: roomData._updatedAt['$date']
- })
-
- room.receiveMessage()
-
- let roomId = roomData.lastMessage.rid
-
- if(this.isIndividual(roomData)) {
- this.dm[roomId] = room
- this.dmCount++
- } else {
- this.group[roomId] = room
- this.groupCount++
- }
-
- });
-
- this.loadingWholeList = false
- }
-
- subscribeToRoom() {
- for (const id in this.dm) {
- this.WsChatService.subscribeNotifyRoom(id).then((subscription)=>{
- console.log('subscription', subscription)
- })
- }
-
- for (const id in this.group) {
- this.WsChatService.subscribeNotifyRoom(id).then((subscription)=>{
- console.log('subscription', subscription)
- })
- }
- }
-
- getRoom(id): RoomService {
- try {
- return this.dm[id]
- } catch(e) {
- return this.group[id]
- }
- }
-
- getRoomName(roomData) {
- if(this.isIndividual(roomData)) {
- const names: String[] = roomData.usernames
- const roomName = names.filter((name)=>{
- return name != SessionStore.user.RochetChatUser
- })[0]
-
- return roomName
- } else {
- return roomData.fName
- }
- }
-
- getRoomId(roomData) {
- return roomData.lastMessage.rid
- }
-
- getRoomLastMessage(roomData) {
- return roomData.lastMessage
- }
-
- private isIndividual(roomData) {
- return !roomData.fname
- }
-
-}
diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts
index 670e78983..7b8ab1509 100644
--- a/src/app/services/chat/ws-chat-methods.service.ts
+++ b/src/app/services/chat/ws-chat-methods.service.ts
@@ -19,7 +19,7 @@ export class WsChatMethodsService {
dmCount = 0;
groupCount = 0;
-
+
constructor(
private WsChatService: WsChatService
) {
@@ -28,7 +28,7 @@ export class WsChatMethodsService {
await this.getAllRooms();
this.subscribeToRoom()
})()
-
+
}
async getAllRooms () {
@@ -36,11 +36,14 @@ export class WsChatMethodsService {
const rooms: any = await this.WsChatService.getRooms();
- console.log(rooms)
+ console.log("ROOMS" + rooms)
rooms.result.update.forEach((roomData:any) => {
let room:RoomService;
-
+
+ console.log(roomData);
+
+
room = new RoomService(this.WsChatService, new MessageService())
room.setData({
id: this.getRoomId(roomData),
@@ -60,7 +63,7 @@ export class WsChatMethodsService {
this.group[roomId] = room
this.groupCount++
}
-
+
});
this.loadingWholeList = false
@@ -97,7 +100,7 @@ export class WsChatMethodsService {
return roomName
} else {
- return roomData.fName
+ return roomData.fname
}
}
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts
index cc9bcc4e9..218e648ec 100644
--- a/src/app/shared/chat/messages/messages.page.ts
+++ b/src/app/shared/chat/messages/messages.page.ts
@@ -19,7 +19,7 @@ import { ThemeService } from 'src/app/services/theme.service'
import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
-import { wsChatMethodsService as wsChatMethodsService} from 'src/app/services/chat/chat.service'
+import { WsChatMethodsService} from 'src/app/services/chat/ws-chat-methods.service'
@Component({
selector: 'app-messages',
@@ -78,9 +78,9 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
public ThemeService: ThemeService,
private changeDetectorRef: ChangeDetectorRef,
private router: Router,
- public wsChatMethodsService: wsChatMethodsService
+ public wsChatMethodsService: WsChatMethodsService
) {
-
+
this.loggedUser = authService.ValidatedUserChat['data'];
}
ngOnChanges(changes: SimpleChanges): void {