fix merge

This commit is contained in:
Peter Maquiran
2022-01-28 16:26:21 +01:00
23 changed files with 596 additions and 423 deletions
+9 -5
View File
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { AlertController, AnimationController } from '@ionic/angular';
import { ChatService } from './chat.service';
import { WsChatMethodsService } from './chat/ws-chat-methods.service';
import { ToastService } from './toast.service';
@Injectable({
@@ -13,6 +14,7 @@ export class AlertService {
private animationController: AnimationController,
private chatService: ChatService,
private toastService: ToastService,
public wsChatMethodsService: WsChatMethodsService,
) { }
async presentAlert(message:string) {
@@ -40,7 +42,9 @@ export class AlertService {
}, 2500);
}
async confirmDeleteMessage(body:any) {
async confirmDeleteMessage(msgId:any, room:any) {
console.log(room);
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Apagar a mensagem?',
@@ -55,10 +59,10 @@ export class AlertService {
}, {
text: 'Apagar',
handler: () => {
const loader = this.toastService.loading();
this.chatService.deleteMessage(body).subscribe(res=>{
loader.remove();
});
//const loader = this.toastService.loading();
this.wsChatMethodsService.deleteMessage(msgId);
//this.wsChatMethodsService.subscribeToRoomUpdate(room._id, room);
//loader.remove();
}
}
]
+47 -11
View File
@@ -11,12 +11,13 @@ import { SqliteService } from 'src/app/services/sqlite.service';
import { NativeNotificationService } from 'src/app/services/native-notification.service';
import { SessionStore } from 'src/app/store/session.service';
import { capitalizeTxt } from 'src/plugin/text'
import { SortService } from '../functions/sort.service';
@Injectable({
providedIn: 'root'
})
export class RoomService {
massages: MessageService[] = []
messages: MessageService[] = []
storageMessage: any[] = [];
lastMessage: MessageService;
@@ -46,12 +47,12 @@ export class RoomService {
private storage: Storage,
private platform: Platform,
private sqlservice: SqliteService,
private NativeNotificationService: NativeNotificationService
private NativeNotificationService: NativeNotificationService,
) {
this.NativeNotificationService.askForPermission()
}
setData({ customFields, id, name, t, lastMessage, _updatedAt }) {
setData({ customFields, id, name, t, lastMessage = new MessageService(), _updatedAt }) {
this.customFields = customFields
this.id = id
this.name = name
@@ -64,8 +65,9 @@ export class RoomService {
receiveMessage() {
this.WsChatService.receiveLiveMessageFromRoom(
this.WsChatService.upateRoomEvents(
this.id,
"stream-room-messages",
(ChatMessage) => {
ChatMessage = ChatMessage.fields.args[0]
ChatMessage = this.fix_updatedAt(ChatMessage)
@@ -74,15 +76,17 @@ export class RoomService {
/* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */
const message = new MessageService()
message.setData(ChatMessage)
this.lastMessage.msg = message.msg
this.lastMessage = message
if (message.t == 'r') { this.name = message.msg }
this.calDateDuration(ChatMessage._updatedAt)
this.massages.push(message)
this.messages.push(message)
setTimeout(() => {
this.scrollDown()
}, 100)
//this.sortService.sortDate(this.messages, '')
if(SessionStore.user.RochetChatUser != ChatMessage.u.username) {
this.NativeNotificationService.sendNotificationChat({
@@ -118,6 +122,36 @@ export class RoomService {
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
})
this.WsChatService.registerCallback
}
async receiveMessageDelete() {
this.WsChatService.upateRoomEvents(
this.id,
"stream-notify-room",
async (ChatMessage) => {
console.log(ChatMessage.fields.args[0]._id);
const messageId = ChatMessage.fields.args[0]._id;
this.messages.forEach((message, index)=>{
if(message._id == messageId){
this.messages.splice(index, 1)
this.storage.set('chatmsg' + this.id, this.messages).then((value) => {
//console.log('MSG DELETE ON STORAGE', value)
});
//Get previous last message from room
const previousLastMessage = this.messages.slice(-1)[0];
this.lastMessage = previousLastMessage;
this.calDateDuration(previousLastMessage._updatedAt)
}
})
}
)
this.WsChatService.registerCallback
}
send() {
@@ -199,8 +233,8 @@ export class RoomService {
console.log('FROM DB WEB', mmessage)
const wewMessage = new MessageService()
wewMessage.setData(mmessage)
this.massages.push(wewMessage)
console.log('loadHistory 222', this.massages)
this.messages.push(wewMessage)
console.log('loadHistory 222', this.messages)
});
});
}
@@ -223,7 +257,7 @@ export class RoomService {
if (message.file) {
if (message.file.guid) {
this.storage.get(message.file.guid).then((image) => {
console.log('IMAGE FROM STORAGE', image)
//console.log('IMAGE FROM STORAGE', image)
message.file.image_url = image
});
}
@@ -233,8 +267,8 @@ export class RoomService {
console.log('FROM DB WEB', mmessage)
const wewMessage = new MessageService()
wewMessage.setData(mmessage)
this.massages.push(wewMessage)
console.log('loadHistory 222', this.massages)
this.messages.push(wewMessage)
console.log('loadHistory 222', this.messages)
});
})
}
@@ -263,6 +297,8 @@ export class RoomService {
this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => {
const mgsArray = chatHistory.result.messages.reverse();
console.log(mgsArray);
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
await this.storage.remove('chatmsg' + this.id).then(() => {
console.log('MSG REMOVE ON STORAGE')
@@ -9,6 +9,7 @@ import { Storage } from '@ionic/storage';
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';
@Injectable({
providedIn: 'root'
@@ -28,7 +29,8 @@ export class WsChatMethodsService {
private storage: Storage,
private platform: Platform,
private sqlservice: SqliteService,
private NativeNotificationService: NativeNotificationService
private NativeNotificationService: NativeNotificationService,
private sortService: SortService
) {
(async()=>{
await this.getAllRooms();
@@ -46,30 +48,7 @@ export class WsChatMethodsService {
// console.log("ROOMS" + JSON.stringify(rooms))
rooms.result.update.forEach((roomData: room) => {
let room:RoomService;
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice, this.NativeNotificationService)
room.setData({
customFields: roomData.customFields,
id: this.getRoomId(roomData),
name: this.getRoomName(roomData),
t: roomData.t,
lastMessage: this.getRoomLastMessage(roomData),
_updatedAt: new Date(roomData._updatedAt['$date'])
})
room.receiveMessage()
let roomId = this.getRoomId(roomData)
if(this.isIndividual(roomData)) {
this.dm[roomId] = room
this.dmCount++
} else {
this.group[roomId] = room
this.groupCount++
}
this.prepareRoom(roomData);
});
this.loadingWholeList = false
@@ -83,6 +62,9 @@ export class WsChatMethodsService {
})
this.WsChatService.subStreamNotifyRoom(id, 'typing', false)
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{
console.log('streamNotifyRoomDeleteMessage', subscription);
})
}
for (const id in this.group) {
@@ -91,13 +73,69 @@ export class WsChatMethodsService {
})
this.WsChatService.subStreamNotifyRoom(id, 'typing', false)
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{
console.log('streamNotifyRoomDeleteMessage', subscription);
})
}
this.WsChatService.streamNotifyLogged().then((subscription=>{
console.log('streamRoomMessages', subscription)
}))
}
subscribeToRoomUpdate(id, roomData) {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log('streamRoomMessages', subscription)
})
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log('streamRoomMessages', subscription)
})
this.WsChatService.streamNotifyLogged().then((subscription=>{
console.log('streamRoomMessages', subscription)
}))
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{
console.log('streamNotifyRoomDeleteMessage', subscription);
})
this.prepareRoom(roomData);
this.getGroupRoom(id).loadHistory();
}
prepareRoom(roomData){
let room:RoomService;
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice, this.NativeNotificationService)
room.setData({
customFields: roomData.customFields,
id: this.getRoomId(roomData),
name: this.getRoomName(roomData),
t: roomData.t,
lastMessage: this.getRoomLastMessage(roomData),
_updatedAt: new Date(roomData._updatedAt['$date'])
})
room.receiveMessage()
room.receiveMessageDelete();
let roomId = this.getRoomId(roomData)
if(this.isIndividual(roomData)) {
console.log(room);
this.dm[roomId] = room
this.dmCount++
} else {
this.group[roomId] = room
this.groupCount++
}
}
deleteMessage(id?) {
return this.WsChatService.deleteMessage(id);
}
leaveRoom(id?) {
return this.WsChatService.leaveRoom(id);
}
@@ -110,6 +148,10 @@ export class WsChatMethodsService {
return this.WsChatService.addRoomOwner(roomid, userId);
}
createPrivateRoom(groupName, username, customFields){
return this.WsChatService.createPrivateRoom(groupName, username, customFields);
}
getDmRoom(id): RoomService {
try {
return this.dm[id]
@@ -141,7 +183,7 @@ export class WsChatMethodsService {
return roomData._id
}
getRoomLastMessage(roomData: room) {
getRoomLastMessage(roomData: room):any {
return roomData.lastMessage
}
+87 -4
View File
@@ -228,8 +228,59 @@ export class WsChatService {
}
joinRoom(){}
deleteMessage() {}
createRoom() {}
deleteMessage(msgId) {
const requestId = uuidv4();
var message = {
msg: "method",
method: "deleteMessage",
id: requestId,
params:[{"_id":msgId}]
}
this.ws.send({message, requestId});
return new Promise ((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message) =>{
if(message.id == requestId || deepFind(message, 'result') == requestId){
resolve(message)
return true
}
}})
});
}
createPrivateRoom(groupName, username, customFields) {
const requestId = uuidv4()
var message = {
msg: "method",
method: "createPrivateGroup",
id: requestId,
params: [
groupName,
[username],
false,
customFields,
{
"broadcast":false,
"encrypted":false
}
]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
sendStreamNotifyRoom(roomId : string, username, event: 'typing', param: any) {
@@ -374,15 +425,20 @@ export class WsChatService {
}
receiveLiveMessageFromRoom(roomId, funx: Function) {
upateRoomEvents(roomId, collection:string, funx: Function, ) {
this.ws.registerCallback({
type:'Onmessage',
funx:(message)=>{
if(message.msg =='changed' && message.collection == 'stream-room-messages') {
//console.log(message);
if(message.msg =='changed' && message.collection == collection) {
if(message.fields.args[0].rid == roomId) {
funx(message)
}
else if(message.fields.eventName ==`${roomId}/deleteMessage`){
funx(message)
}
}
}
})
@@ -469,6 +525,33 @@ export class WsChatService {
}
streamNotifyRoomDeleteMessage(roomId:string) {
const requestId = uuidv4()
let message = {
"msg": "sub",
"id": requestId,
"name": "stream-notify-room",
"params": [
`${roomId}/deleteMessage`,
true
]
};
this.ws.send({message, requestId})
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
registerCallback(data:wsCallbacksParams) {
return this.ws.registerCallback(data)
}
+112 -74
View File
@@ -13,7 +13,7 @@ import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera
import { Filesystem, Directory } from '@capacitor/filesystem';
import { environment } from 'src/environments/environment';
import { HttpClient, HttpEventType, HttpHeaders, HttpParams } from '@angular/common/http';
import { Storage } from '@ionic/storage';
const IMAGE_DIR = 'stored-images';
@@ -53,6 +53,7 @@ export class FileService {
private platform: Platform,
private loadingCtrl: LoadingController,
private http: HttpClient,
private storage: Storage
) {
this.headers = new HttpHeaders();
}
@@ -253,43 +254,64 @@ export class FileService {
this.capturedImage = this.images[0].data
this.capturedImageTitle = new Date().getTime() + '.jpeg';
const base64 = await fetch(this.capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", this.capturedImage);
let guid: any = await this.uploadFile(this.capturedImage).toPromise()
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.uploadFile(formData).toPromise()
console.log(guid.path);
let body = {
"message":
{
"rid": roomid,
"msg": "",
"attachments": [{
"title": this.capturedImageTitle,
"title_link_download": false,
"image_url": this.capturedImage,
}],
"file":{
"type": "application/img",
"guid": guid.path,
"image_url": ""
this.downloadFile(guid.path).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
//console.log('FILE TYPE 33', msg.file.type)
} else if (event.type === HttpEventType.Response) {
var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
let body = {
"message":
{
"rid": roomid,
"msg": "",
"attachments": [{
"title": this.capturedImageTitle,
"title_link_download": false,
"image_url": fileImage,
}],
"file":{
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
}
}
}
console.log('BODY TAKE PICTURE CHAT', body)
const loader = this.toastService.loading();
this.chatService.sendMessage(body).subscribe(res=> {
console.log(res);
loader.remove();
},(error) => {
loader.remove();
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
});
});
}
}
}
console.log('BODY TAKE PICTURE CHAT', body)
const loader = this.toastService.loading();
this.chatService.sendMessage(body).subscribe(res=> {
console.log(res);
loader.remove();
},(error) => {
loader.remove();
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
});
});
}
async addCameraPictureToChat(roomId){
console.log('add camera to picture')
const image = await Camera.getPhoto({
quality: 50,
allowEditing: false,
@@ -299,6 +321,8 @@ export class FileService {
if (image) {
await this.saveImage(image,roomId)
} else {
console.log('Error saving image')
}
//this.capturedImage = this.capturedImage;
@@ -354,70 +378,84 @@ export class FileService {
//loader.remove();
});
*/ }
addPictureToChat(roomId) {
addPictureToChat(roomId) {
console.log('add picture to chat')
console.log('add picture to chat')
const input = this.fileLoaderService.createInput({
accept: ['image/apng', 'image/jpeg', 'image/png']
})
const input = this.fileLoaderService.createInput({
accept: ['image/apng', 'image/jpeg', 'image/png']
})
setInterval(()=>{
console.log(input.value)
}, 550)
setInterval(() => {
console.log(input.value)
}, 550)
input.onchange = async () => {
input.onchange = async () => {
//alert('Onchange AQUI')
//alert('Onchange AQUI')
const file = this.fileLoaderService.getFirstFile(input)
const file = this.fileLoaderService.getFirstFile(input)
console.log(file);
console.log('first file',file);
const formData = new FormData();
formData.append("blobFile", file);
let guid: any = await this.uploadFile(formData).toPromise()
console.log('add picture to chat',guid.path);
const formData = new FormData();
formData.append("blobFile", file);
let guid: any = await this.uploadFile(formData).toPromise()
console.log('ADD IMAGE FORM DATA', formData)
console.log('add picture to chat', guid.path);
this.downloadFile(guid.path).subscribe(async (event) => {
/* const imageData = await this.fileToBase64Service.convert(file)
this.capturedImage = imageData; */
this.capturedImageTitle = file.name;
if (event.type === HttpEventType.DownloadProgress) {
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
//console.log('FILE TYPE 33', msg.file.type)
} else if (event.type === HttpEventType.Response) {
var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
let body = {
"message":
{
"rid": roomId,
"msg": "",
"attachments": [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}],
"file":{
"type": "application/img",
"guid": guid.path,
"image_url": ""
let body = {
"message":
{
"rid": roomId,
"msg": "",
"attachments": [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}],
"file": {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
}
}
}
}
console.log('SELECT PICTURE GALLERY', body)
console.log(this.capturedImage)
this.chatService.sendMessage(body).subscribe(res => {
console.log('Msg after send image', res);
}, (error) => {
console.log('Msg after send image error', error);
});
});
}
console.log('SELECT PICTURE GALLERY', body)
console.log(this.capturedImage)
});
this.chatService.sendMessage(body).subscribe(res=> {
/* const imageData = await this.fileToBase64Service.convert(file)
this.capturedImage = imageData; */
console.log('Msg after send image',res);
},(error) => {
console.log('Msg after send image error',error);
});
//console.log(this.capturedImage)
};
}
//console.log(this.capturedImage)
};
}
addDocumentToChat(roomId:string) {
const input = this.fileLoaderService.createInput({
+2 -7
View File
@@ -15,7 +15,7 @@ export class SortService {
});
}
}
sortArrayByDate(myArray: any) {
console.log(myArray[0].taskStartDate);
if(myArray.length > 0){
@@ -26,13 +26,8 @@ export class SortService {
}
sortDate(array = [], path: string) {
return array.sort( (a,b)=> {
return new Date(this.ObjectService.deepFind(b, path)).getTime() -
new Date(this.ObjectService.deepFind(a, path)).getTime()
return new Date(this.ObjectService.deepFind(b, path)).getTime() - new Date(this.ObjectService.deepFind(a, path)).getTime()
})
}
}