rename files

This commit is contained in:
Peter Maquiran
2022-09-30 15:13:36 +01:00
parent 64ad7bbc7f
commit 12cf5831a8
36 changed files with 256 additions and 315 deletions
@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing';
import { WebsocketService } from './websocket.service';
import { ChatSystemService } from './chat-system.service';
describe('WebsocketService', () => {
let service: WebsocketService;
describe('ChatSystemService', () => {
let service: ChatSystemService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(WebsocketService);
service = TestBed.inject(ChatSystemService);
});
it('should be created', () => {
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { RoomService } from './room.service';
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
import { MessageService } from 'src/app/services/chat/message.service';
import { SessionStore } from 'src/app/store/session.service';
import { capitalizeTxt } from 'src/plugin/text';
@@ -23,7 +23,7 @@ import { NetworkServiceService} from 'src/app/services/network-service.service';
@Injectable({
providedIn: 'root'
})
export class WsChatMethodsService {
export class ChatSystemService {
dm: {[key: string]: RoomService} = {}
group: {[key: string]: RoomService} = {}
@@ -45,7 +45,7 @@ export class WsChatMethodsService {
delete = []
constructor(
private WsChatService: WsChatService,
private RochetChatConnectorService: RochetChatConnectorService,
private storage: Storage,
private platform: Platform,
private sqlservice: SqliteService,
@@ -66,7 +66,7 @@ export class WsChatMethodsService {
this.loadChat()
this.WsChatService.registerCallback({
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: () => {
/**
@@ -171,7 +171,7 @@ export class WsChatMethodsService {
async getAllRooms () {
this.loadingWholeList = true
const rooms = await this.WsChatService.getRooms();
const rooms = await this.RochetChatConnectorService.getRooms();
try {
await this.storage.remove('Rooms');
} catch(e) {}
@@ -299,7 +299,7 @@ export class WsChatMethodsService {
this.defaultSubtribe(id)
}
this.WsChatService.streamNotifyLogged().then((subscription=>{
this.RochetChatConnectorService.streamNotifyLogged().then((subscription=>{
}))
}
@@ -326,23 +326,23 @@ export class WsChatMethodsService {
*/
private defaultSubtribe(id: any) {
this.WsChatService.streamRoomMessages(id).then((subscription) => {
this.RochetChatConnectorService.streamRoomMessages(id).then((subscription) => {
const room = this.getRoomById(id);
room.status.receive.message = true;
})
this.WsChatService.subStreamNotifyRoom(id, 'typing', false).then((subscription) => {
this.RochetChatConnectorService.subStreamNotifyRoom(id, 'typing', false).then((subscription) => {
const room = this.getRoomById(id);
room.status.receive.typing = true;
//
})
this.WsChatService.subStreamNotifyRoom(id, 'readMessage', false).then((subscription) => {
this.RochetChatConnectorService.subStreamNotifyRoom(id, 'readMessage', false).then((subscription) => {
const room = this.getRoomById(id);
room.status.receive.readMessage = true;
})
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription) => {
this.RochetChatConnectorService.streamNotifyRoomDeleteMessage(id).then((subscription) => {
const room = this.getRoomById(id);
room.status.receive.deleteMessage = true;
})
@@ -389,7 +389,7 @@ export class WsChatMethodsService {
if (setData.name != 'Rocket Cat') {
// create room
if(!this.roomExist(roomId)) {
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this)
let room:RoomService = new RoomService(this.RochetChatConnectorService, new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this)
room.setData(setData)
room.receiveMessage()
room.getAllUsers = this.getUsers
@@ -458,7 +458,7 @@ export class WsChatMethodsService {
*/
private getUserStatus(id?:string) {
this.WsChatService.getUserStatus((d) => {
this.RochetChatConnectorService.getUserStatus((d) => {
const username = d.fields.args[0][1]
const statusNum = d.fields.args[0][2]
@@ -501,11 +501,11 @@ export class WsChatMethodsService {
deleteMessage(id?) {
return this.WsChatService.deleteMessage(id);
return this.RochetChatConnectorService.deleteMessage(id);
}
leaveRoom(id?) {
return this.WsChatService.leaveRoom(id);
return this.RochetChatConnectorService.leaveRoom(id);
}
async hideRoom(id) {
@@ -526,18 +526,18 @@ export class WsChatMethodsService {
hidingRoom(id?) {
return this.WsChatService.hidingRoom(id).then(()=>{
return this.RochetChatConnectorService.hidingRoom(id).then(()=>{
// this.hideRoom(id)
})
}
addRoomOwner(roomid, userId) {
return this.WsChatService.addRoomOwner(roomid, userId);
return this.RochetChatConnectorService.addRoomOwner(roomid, userId);
}
createPrivateRoom(groupName, username, customFields){
return this.WsChatService.createPrivateRoom(groupName, username, customFields);
return this.RochetChatConnectorService.createPrivateRoom(groupName, username, customFields);
}
getDmRoom(id): RoomService {
@@ -613,8 +613,7 @@ export class WsChatMethodsService {
}
getUserOfRoom(roomId){
return this.WsChatService.getUserOfRoom(roomId);
return this.RochetChatConnectorService.getUserOfRoom(roomId);
}
}
+6 -6
View File
@@ -4,7 +4,7 @@ import { Storage } from '@ionic/storage';
import { SessionStore } from 'src/app/store/session.service';
import { capitalizeTxt } from 'src/plugin/text'
import { NfService } from 'src/app/services/chat/nf.service'
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
import { showDateDuration } from 'src/plugin/showDateDuration';
import { ChatStorageService } from './chat-storage.service'
import { ChatMethodsService } from './chat-methods.service'
@@ -64,7 +64,7 @@ export class MessageService {
constructor(private storage: Storage,
private NfService: NfService,
private WsChatService: WsChatService,
private RochetChatConnectorService: RochetChatConnectorService,
private ChatStorageService: ChatStorageService,
private ChatMethodsService: ChatMethodsService,
private AESEncrypt: AESEncrypt,
@@ -166,9 +166,9 @@ export class MessageService {
const params = {roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file, localReference: this.localReference}
await this.sendRequest(params)
} else if(this.WsChatService.isLogin == false) {
} else if(this.RochetChatConnectorService.isLogin == false) {
this.WsChatService.registerCallback({
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: async ()=> {
this.send()
@@ -203,7 +203,7 @@ export class MessageService {
if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
console.log('online send')
this.WsChatService.send(params).then(
this.RochetChatConnectorService.send(params).then(
(ChatMessage: any) => {
console.log('response')
ChatMessage = ChatMessage.message.result
@@ -215,7 +215,7 @@ export class MessageService {
} else {
console.log("reconnect")
this.WsChatService.registerCallback({
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: async ()=> {
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { RochetChatConnectorService } from './rochet-chat-connector.service';
describe('RochetChatConnectorService', () => {
let service: RochetChatConnectorService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(RochetChatConnectorService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -9,7 +9,7 @@ import { chatHistory, Rooms } from 'src/app/models/chatMethod';
@Injectable({
providedIn: 'root'
})
export class WsChatService {
export class RochetChatConnectorService {
isLogin = false;
loginResponse = {}
@@ -803,4 +803,5 @@ export class WsChatService {
}
}
}}
}
}
+25 -25
View File
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
import { MessageService } from 'src/app/services/chat/message.service';
import { showDateDuration } from 'src/plugin/showDateDuration';
import { chatHistory } from 'src/app/models/chatMethod';
@@ -22,7 +22,7 @@ import { AESEncrypt } from '../aesencrypt.service';
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { ConnectionStatus, NetworkServiceService} from 'src/app/services/network-service.service';
import { WsChatMethodsService } from './ws-chat-methods.service';
import { ChatSystemService } from './chat-system.service';
@Injectable({
providedIn: 'root'
@@ -79,7 +79,7 @@ export class RoomService {
chatServiceDeleteRoom = (roomId) => {}
constructor(
public WsChatService: WsChatService,
public RochetChatConnectorService: RochetChatConnectorService,
private MessageService: MessageService,
private storage: Storage,
private platform: Platform,
@@ -93,11 +93,11 @@ export class RoomService {
private AESEncrypt: AESEncrypt,
private AttachmentsService: AttachmentsService,
private NetworkServiceService: NetworkServiceService,
private wsChatMethodsService: WsChatMethodsService
private ChatSystemService: ChatSystemService
) {
this.NativeNotificationService.askForPermission()
this.WsChatService.getUserStatus((d) => {
this.RochetChatConnectorService.getUserStatus((d) => {
const userId = d.fields.args[0][0]
const statusNum = d.fields.args[0][2]
@@ -136,7 +136,7 @@ export class RoomService {
}
})
this.WsChatService.registerCallback({
this.RochetChatConnectorService.registerCallback({
type: 'Offline',
funx: () => {
/**
@@ -181,7 +181,7 @@ export class RoomService {
}
}
setData({membersExcludeMe, members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), _updatedAt }) {
setData({membersExcludeMe, members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), _updatedAt }) {
this.customFields = customFields
this.id = id
this.name = name
@@ -236,15 +236,15 @@ export class RoomService {
if(this.t === 'p') {
this.chatService.deleteGroup(body).subscribe(res=>{
this.wsChatMethodsService.deleteRoom(this.id);
this.wsChatMethodsService.getAllRooms();
this.ChatSystemService.deleteRoom(this.id);
this.ChatSystemService.getAllRooms();
this.chatServiceDeleteRoom(this.id);
});
}
else {
this.chatService.deleteChannel(body).subscribe(res=>{
this.wsChatMethodsService.deleteRoom(this.id);
this.wsChatMethodsService.getAllRooms();
this.ChatSystemService.deleteRoom(this.id);
this.ChatSystemService.getAllRooms();
this.chatServiceDeleteRoom(this.id);
});
}
@@ -261,7 +261,7 @@ export class RoomService {
receiveMessage() {
this.WsChatService.updateRoomEventss(
this.RochetChatConnectorService.updateRoomEventss(
this.id,
"stream-room-messages",
async (IncomingChatMessage:IncomingChatMessage) => {
@@ -335,7 +335,7 @@ export class RoomService {
}
)
this.WsChatService.receiveStreamNotifyRoom((message) => {
this.RochetChatConnectorService.receiveStreamNotifyRoom((message) => {
if(message.fields.eventName == this.id+'/'+'typing') {
@@ -446,7 +446,7 @@ export class RoomService {
async receiveMessageDelete() {
this.WsChatService.updateRoomEventss(
this.RochetChatConnectorService.updateRoomEventss(
this.id,
"stream-notify-room",
async (ChatMessage) => {
@@ -532,14 +532,14 @@ export class RoomService {
if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
this.WsChatService.deleteMessage(msgId).then(async() => {
this.RochetChatConnectorService.deleteMessage(msgId).then(async() => {
message.delateRequest = true
await message.save();
this.deleteMessage(msgId);
})
} else {
this.WsChatService.registerCallback({
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: async ()=> {
@@ -609,7 +609,7 @@ export class RoomService {
}
if(lastIsTyping != this.isTyping) {
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.UserName, 'typing', this.isTyping)
this.RochetChatConnectorService.sendStreamNotifyRoom(this.id, SessionStore.user.UserName, 'typing', this.isTyping)
}
@@ -618,7 +618,7 @@ export class RoomService {
}
sendFalseTypingReadMessage(method,param: object) {
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.UserName, 'typing', {method:method, params: param} as falseTypingMethod)
this.RochetChatConnectorService.sendStreamNotifyRoom(this.id, SessionStore.user.UserName, 'typing', {method:method, params: param} as falseTypingMethod)
this.setTypingOff()
}
@@ -630,7 +630,7 @@ export class RoomService {
if(this.isTyping == true) {
this.isTyping = false
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.UserName, 'typing', this.isTyping)
this.RochetChatConnectorService.sendStreamNotifyRoom(this.id, SessionStore.user.UserName, 'typing', this.isTyping)
}
}
@@ -654,7 +654,7 @@ export class RoomService {
leave(rid?) {
this.WsChatService.leaveRoom(this.id)
this.RochetChatConnectorService.leaveRoom(this.id)
}
isJson(str) {
@@ -731,7 +731,7 @@ export class RoomService {
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
await this.RochetChatConnectorService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
// console.log('load history', chatHistory)
//
@@ -807,7 +807,7 @@ export class RoomService {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
const wewMessage = new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
wewMessage.setData(message)
wewMessage.loadHistory = this.hasLoadHistory
@@ -864,7 +864,7 @@ export class RoomService {
async prepareCreate({message, save = true}): Promise<MessageService> {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
const wewMessage = new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
wewMessage.setData(message)
wewMessage.loadHistory = this.hasLoadHistory
@@ -902,7 +902,7 @@ export class RoomService {
simplePrepareMessage(message) {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
const wewMessage = new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
wewMessage.setData(message)
wewMessage.loadHistory = this.hasLoadHistory
@@ -977,7 +977,7 @@ export class RoomService {
}
sendReadMessage() {
this.WsChatService.readMessage(this.id)
this.RochetChatConnectorService.readMessage(this.id)
this.sendFalseTypingReadMessage('viewMessage', {})
this.messageUnread = false
}
@@ -1,43 +0,0 @@
import { Injectable } from '@angular/core';
import * as Rx from 'rxjs/Rx';
@Injectable({
providedIn: 'root'
})
export class WebsocketService {
constructor() { }
private subject: Rx.Subject<MessageEvent>;
public connect(url): Rx.Subject<MessageEvent> {
if(!this.subject){
this.subject = this.create(url);
}
return this.subject;
}
private create(url): Rx.Subject<MessageEvent>{
let ws = new WebSocket(url);
let observable = Rx.Observable.create(
(obs: Rx.Observer<MessageEvent>) => {
ws.onmessage = obs.next.bind(obs);
ws.onerror = obs.error.bind(obs);
ws.onclose = obs.complete.bind(obs);
return ws.close.bind(ws)
})
let observer = {
next: (data: Object) => {
if(ws.readyState === WebSocket.OPEN){
ws.send(JSON.stringify(data));
}
}
}
return Rx.Subject.create(observer, observable);
}
}
@@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { WsChatMethodsService } from './ws-chat-methods.service';
describe('WsChatMethodsService', () => {
let service: WsChatMethodsService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(WsChatMethodsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { WsChatService } from './ws-chat.service';
describe('WsChatService', () => {
let service: WsChatService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(WsChatService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});