mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
merge
This commit is contained in:
@@ -167,3 +167,209 @@ export interface chatHistory {
|
||||
unreadNotLoaded: number;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
interface Ts {
|
||||
$date: any;
|
||||
}
|
||||
|
||||
interface U {
|
||||
_id: string;
|
||||
username: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface UpdatedAt {
|
||||
$date: any;
|
||||
}
|
||||
|
||||
interface Attachment {
|
||||
ts: Date;
|
||||
title_link_download: boolean;
|
||||
}
|
||||
|
||||
export interface File {
|
||||
type: string;
|
||||
guid: string;
|
||||
image_url: string;
|
||||
subject: string;
|
||||
start_date?: Date;
|
||||
end_date?: Date;
|
||||
venue: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface EditedAt {
|
||||
$date: number;
|
||||
}
|
||||
|
||||
interface EditedBy {
|
||||
_id: string;
|
||||
username: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
interface Ts2 {
|
||||
$date: number;
|
||||
}
|
||||
|
||||
interface U2 {
|
||||
_id: string;
|
||||
username: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface UpdatedAt2 {
|
||||
$date: number;
|
||||
}
|
||||
|
||||
interface FirstUnread {
|
||||
_id: string;
|
||||
rid: string;
|
||||
msg: string;
|
||||
ts: Ts2;
|
||||
u: U2;
|
||||
_updatedAt: UpdatedAt2;
|
||||
mentions: any[];
|
||||
channels: any[];
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
customFields:any;
|
||||
_id: string;
|
||||
rid: string;
|
||||
msg: string;
|
||||
ts: Ts;
|
||||
u: U;
|
||||
t: string;
|
||||
_updatedAt: UpdatedAt;
|
||||
mentions: any[];
|
||||
channels: any[];
|
||||
attachments: Attachment[];
|
||||
file: File;
|
||||
editedAt: EditedAt;
|
||||
editedBy: EditedBy;
|
||||
urls: any[];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export interface Lm {
|
||||
$date: any;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export interface LastMessage {
|
||||
_id: string;
|
||||
rid: string;
|
||||
msg: string;
|
||||
ts: Ts;
|
||||
u: U;
|
||||
_updatedAt: UpdatedAt2;
|
||||
mentions: any[];
|
||||
channels: any[];
|
||||
file: File;
|
||||
attachments: Attachment[];
|
||||
}
|
||||
|
||||
export interface CustomFields {
|
||||
}
|
||||
|
||||
export interface Update {
|
||||
_id: string;
|
||||
t: string;
|
||||
usernames: string[];
|
||||
usersCount: number;
|
||||
uids: string[];
|
||||
default: boolean;
|
||||
ro: boolean;
|
||||
sysMes: boolean;
|
||||
_updatedAt: UpdatedAt;
|
||||
lm: Lm;
|
||||
lastMessage: LastMessage;
|
||||
name: string;
|
||||
fname: string;
|
||||
u: U2;
|
||||
customFields: CustomFields;
|
||||
}
|
||||
|
||||
export interface DeletedAt {
|
||||
$date: any;
|
||||
}
|
||||
|
||||
export interface Remove {
|
||||
_id: string;
|
||||
_deletedAt: DeletedAt;
|
||||
}
|
||||
|
||||
export interface Result {
|
||||
update: Update[];
|
||||
remove: Remove[];
|
||||
}
|
||||
|
||||
export interface Rooms {
|
||||
msg: string;
|
||||
id: string;
|
||||
result: Result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface ChatMessage {
|
||||
msg: string;
|
||||
id: string;
|
||||
result: Message
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export interface chatHistory {
|
||||
msg: string;
|
||||
id: string;
|
||||
result: {
|
||||
messages: Message[];
|
||||
firstUnread: FirstUnread;
|
||||
unreadNotLoaded: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface chatUser {
|
||||
_id: string;
|
||||
createdAt: Date;
|
||||
emails: {
|
||||
address: string;
|
||||
verified: boolean;
|
||||
}
|
||||
type: string;
|
||||
status: string;
|
||||
active: boolean;
|
||||
_updatedAt: Date;
|
||||
roles: string[];
|
||||
name: string;
|
||||
lastLogin: Date;
|
||||
statusConnection: string;
|
||||
utcOffset: number;
|
||||
username: string;
|
||||
__rooms: string[];
|
||||
requirePasswordChange?: boolean;
|
||||
settings: {
|
||||
preferences: {
|
||||
language: string;
|
||||
};
|
||||
};
|
||||
nickname: string;
|
||||
statusText: string;
|
||||
banners: any;
|
||||
statusDefault: string;
|
||||
language: string;
|
||||
avatarOrigin: string;
|
||||
avatarETag?: any;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ export interface wsCallbacksParams {
|
||||
runOnces?: boolean
|
||||
requestId?: string
|
||||
key?: string
|
||||
order?: number
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +101,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
|
||||
this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked;
|
||||
|
||||
this.wsChatMethodsService.openRoom(this.roomId)
|
||||
|
||||
setTimeout(()=>{
|
||||
this.scrollToBottomClicked()
|
||||
}, 50)
|
||||
|
||||
@@ -114,7 +114,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory()
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
|
||||
|
||||
this.wsChatMethodsService.openRoom(this.roomId)
|
||||
|
||||
setTimeout(()=>{
|
||||
this.scrollToBottomClicked()
|
||||
}, 150)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AppProcessStatusService } from './app-process-status.service';
|
||||
|
||||
describe('AppProcessStatusService', () => {
|
||||
let service: AppProcessStatusService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(AppProcessStatusService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AppProcessStatusService {
|
||||
|
||||
status: 'resume' | 'pause' = 'resume'
|
||||
|
||||
constructor() {
|
||||
this.events()
|
||||
}
|
||||
|
||||
private events() {
|
||||
document.addEventListener('pause', () => {
|
||||
// console.log('App going to background');
|
||||
this.status = 'pause'
|
||||
});
|
||||
|
||||
document.addEventListener('resume', () => {
|
||||
// console.log('App going to background');
|
||||
this.status = 'resume'
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ export class MessageService {
|
||||
if (this.file) {
|
||||
if (this.file.guid) {
|
||||
this.storage.get(this.file.guid).then((image) => {
|
||||
console.log('IMAGE FROM STORAGE', image)
|
||||
// console.log('IMAGE FROM STORAGE', image)
|
||||
this.file.image_url = image
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import { NativeNotificationService } from 'src/app/services/native-notification.
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { capitalizeTxt } from 'src/plugin/text'
|
||||
import { SortService } from '../functions/sort.service';
|
||||
import { chatUser } from 'src/app/models/chatMethod';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -40,6 +42,9 @@ export class RoomService {
|
||||
mgsArray = [];
|
||||
|
||||
scrollDown = () => { }
|
||||
getAllUsers = (): chatUser[] => {
|
||||
return []
|
||||
}
|
||||
|
||||
constructor(
|
||||
public WsChatService: WsChatService,
|
||||
@@ -198,6 +203,19 @@ export class RoomService {
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
private setTypingOff() {
|
||||
this.typing('')
|
||||
}
|
||||
|
||||
roomLeave() {
|
||||
this.setTypingOff()
|
||||
}
|
||||
|
||||
open() {
|
||||
// this.typing(this.message)
|
||||
}
|
||||
|
||||
|
||||
leave(rid?) {
|
||||
this.WsChatService.leaveRoom(this.id)
|
||||
}
|
||||
@@ -437,7 +455,7 @@ export class RoomService {
|
||||
console.log('FIX UPDATE ', message.result)
|
||||
message.result._updatedAt = message.result._updatedAt['$date']
|
||||
} else {
|
||||
console.log('FIX UPDATE 11', message)
|
||||
// console.log('FIX UPDATE 11', message)
|
||||
message._updatedAt = message._updatedAt['$date']
|
||||
}
|
||||
return message
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Platform } from '@ionic/angular';
|
||||
import { SqliteService } from 'src/app/services/sqlite.service';
|
||||
import { NativeNotificationService } from 'src/app/services/native-notification.service';
|
||||
import { SortService } from '../functions/sort.service';
|
||||
import { chatUser } from 'src/app/models/chatMethod';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -28,6 +29,10 @@ export class WsChatMethodsService {
|
||||
dmCount = 0;
|
||||
groupCount = 0;
|
||||
|
||||
|
||||
currentRoom = null
|
||||
users: chatUser[] = []
|
||||
|
||||
constructor(
|
||||
private WsChatService: WsChatService,
|
||||
private storage: Storage,
|
||||
@@ -40,10 +45,37 @@ export class WsChatMethodsService {
|
||||
await this.getAllRooms();
|
||||
this.subscribeToRoom()
|
||||
|
||||
|
||||
//
|
||||
await this.getUser()
|
||||
this.getUserStatus()
|
||||
|
||||
})()
|
||||
|
||||
}
|
||||
|
||||
openRoom(roomId) {
|
||||
|
||||
if(this.currentRoom) {
|
||||
if(this.getDmRoom(this.currentRoom)) {
|
||||
this.getDmRoom(this.currentRoom).roomLeave()
|
||||
} else if(this.getGroupRoom(this.currentRoom)) {
|
||||
this.getGroupRoom(this.currentRoom).roomLeave()
|
||||
}
|
||||
}
|
||||
|
||||
this.currentRoom = roomId
|
||||
|
||||
if(this.currentRoom) {
|
||||
if(this.getDmRoom(this.currentRoom)) {
|
||||
this.getDmRoom(this.currentRoom).open()
|
||||
} else if(this.getGroupRoom(this.currentRoom)) {
|
||||
this.getGroupRoom(this.currentRoom).open()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async getAllRooms () {
|
||||
this.loadingWholeList = true
|
||||
|
||||
@@ -140,6 +172,7 @@ export class WsChatMethodsService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
prepareRoom(roomData) {
|
||||
let room:RoomService;
|
||||
|
||||
@@ -155,6 +188,7 @@ export class WsChatMethodsService {
|
||||
})
|
||||
|
||||
room.receiveMessage()
|
||||
room.getAllUsers = this.getUsers
|
||||
room.receiveMessageDelete();
|
||||
|
||||
let roomId = this.getRoomId(roomData)
|
||||
@@ -170,6 +204,51 @@ export class WsChatMethodsService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
getReceptorName(roomData) {
|
||||
try {
|
||||
return roomData.usernames.find((e)=> e != SessionStore.user.RochetChatUser)
|
||||
} catch(e) {
|
||||
return '*'
|
||||
}
|
||||
}
|
||||
|
||||
getUserStatus(id?:string) {
|
||||
|
||||
this.WsChatService.getUserStatus((d) => {
|
||||
|
||||
const username = d.fields.args[0][1]
|
||||
const statusNum = d.fields.args[0][2]
|
||||
|
||||
console.log('d', d)
|
||||
|
||||
const statusText = this.statusNumberToText(statusNum)
|
||||
this.getUserByName(username).status = statusText
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
getUserByName(username) {
|
||||
return this.users.find((user)=> user.username == username)
|
||||
}
|
||||
|
||||
statusNumberToText(text) {
|
||||
if(text == '0') {
|
||||
return "offline"
|
||||
}
|
||||
else if(text == '1') {
|
||||
return "online"
|
||||
}
|
||||
else if(text == '2') {
|
||||
return "away"
|
||||
}
|
||||
else if(text == '3') {
|
||||
return "busy"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
deleteMessage(id?) {
|
||||
return this.WsChatService.deleteMessage(id);
|
||||
}
|
||||
@@ -229,4 +308,28 @@ export class WsChatMethodsService {
|
||||
return !roomData.fname
|
||||
}
|
||||
|
||||
getUsers = () =>{
|
||||
return this.users
|
||||
}
|
||||
|
||||
async getUser() {
|
||||
|
||||
// let _res = await this.chatService.getAllUsers().toPromise()
|
||||
|
||||
// let user = _res['users'].filter(data => data.username != SessionStore.user.RochetChatUser);
|
||||
|
||||
// user = user.sort((a,b) => {
|
||||
// if(a.name < b.name) {
|
||||
// return -1;
|
||||
// }
|
||||
// if(a.name > b.name) {
|
||||
// return 1;
|
||||
// }
|
||||
// return 0;
|
||||
// });
|
||||
|
||||
// this.users = user
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ export class WsChatService {
|
||||
});
|
||||
}
|
||||
|
||||
hidingRoom(roomId){
|
||||
hidingRoom(roomId) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
@@ -350,6 +350,19 @@ export class WsChatService {
|
||||
}})
|
||||
}
|
||||
|
||||
|
||||
getUserStatus(funx:Function){
|
||||
this.ws.registerCallback({
|
||||
type:'Onmessage',
|
||||
funx:(message)=>{
|
||||
if(message.msg == 'changed' && message.collection == "stream-notify-logged") {
|
||||
funx(message)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
loadHistory(roomId, limit: number = 50) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
@@ -18,9 +18,9 @@ export class NativeNotificationService {
|
||||
LocalNotifications.requestPermissions()
|
||||
|
||||
LocalNotifications.checkPermissions().then((data)=>{
|
||||
console.log('success', data)
|
||||
// console.log('success', data)
|
||||
}).catch((data)=>{
|
||||
console.log('error', data)
|
||||
// console.log('error', data)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
//this.scrollToBottom();
|
||||
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
|
||||
this.wsChatMethodsService.getGroupRoom(this.roomId).getMsgFromDB();
|
||||
console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).messages);
|
||||
// console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).messages);
|
||||
this.wsChatMethodsService.openRoom(this.roomId)
|
||||
this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked
|
||||
|
||||
setTimeout(()=>{
|
||||
|
||||
@@ -100,21 +100,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory()
|
||||
//this.wsChatMethodsService.getDmRoom(this.roomId).getMsgFromDB()
|
||||
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
|
||||
/* console.log('DATATATA', this.wsChatMethodsService.getDmRoom(this.roomId).massages)
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).massages.forEach((element) => {
|
||||
console.log('DATATATA 11', element)
|
||||
}) */
|
||||
|
||||
|
||||
//this.transformData(this.wsChatMethodsService.getDmRoom(this.roomId).massages)
|
||||
//this.getMessageDB()
|
||||
|
||||
|
||||
this.wsChatMethodsService.openRoom(this.roomId)
|
||||
setTimeout(() => {
|
||||
this.scrollToBottomClicked()
|
||||
}, 50)
|
||||
}, 150)
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// https://stackoverflow.com/a/68628927/14115342
|
||||
|
||||
const ArrayToObject = (array = [], getKey) => array.reduce((obj, cur) => {
|
||||
const key = getKey(cur);
|
||||
return (Object.assign(Object.assign({}, obj), { [key]: cur }));
|
||||
}, {});
|
||||
Reference in New Issue
Block a user