reconnect rocketchat socket

This commit is contained in:
Eudes Inácio
2023-09-14 11:58:24 +01:00
parent 9cc97dfc0f
commit 540750e0e9
10 changed files with 193 additions and 80 deletions
-3
View File
@@ -13,9 +13,6 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter> </intent-filter>
</activity> </activity>
<provider android:authorities="${applicationId}.fileprovider" android:exported="false" <provider android:authorities="${applicationId}.fileprovider" android:exported="false"
+45 -15
View File
@@ -21,6 +21,10 @@ import { NetworkServiceService, ConnectionStatus } from 'src/app/services/networ
import { UserSession } from '../models/user.model'; import { UserSession } from '../models/user.model';
import { PermissionList } from '../models/permission/permissionList'; import { PermissionList } from '../models/permission/permissionList';
import { Plugins } from '@capacitor/core';
const { App } = Plugins;
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
@@ -89,10 +93,10 @@ export class HomePage implements OnInit {
public eventService: EventsService, public eventService: EventsService,
public ActiveTabService: ActiveTabService, public ActiveTabService: ActiveTabService,
private RoleIdService: RoleIdService private RoleIdService: RoleIdService
) { ) {
if (SessionStore.exist) { if (SessionStore.exist) {
this.user = SessionStore.user; this.user = SessionStore.user;
} }
this.router.events.subscribe((val) => { this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove()) document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
@@ -124,14 +128,12 @@ export class HomePage implements OnInit {
} }
/* navigator.serviceWorker.ready.then((registration) => { /* navigator.serviceWorker.ready.then((registration) => {
console.log('yes please') console.log('yes please')
registration.active.postMessage( registration.active.postMessage(
"Test message sent immediately after creation", "Test message sent immediately after creation",
); );
}); */ }); */
} }
@@ -220,18 +222,34 @@ export class HomePage implements OnInit {
(()=>{ (() => {
document.addEventListener('click', (e: any) => { document.addEventListener('click', (e: any) => {
const closest = e.target.closest(".mat-datepicker-content"); const closest = e.target.closest(".mat-datepicker-content");
if(closest) { if (closest) {
e.preventDefault() e.preventDefault()
document.activeElement['blur'](); document.activeElement['blur']();
} }
}) })
})() })()
}, 1000) }, 1000)
/* if (!this.platform.is('desktop')) {
App.addListener('appStateChange', ({ isActive }) => {
if (isActive) {
// The app is in the foreground.
console.log('App is in the foreground');
this.RochetChatConnectorService.connect()
this.reloadComponent(true)
} else {
// The app is in the background.
console.log('App is in the background');
// You can perform actions specific to the background state here.
}
});
} */
} }
clearTabButtonSelection() { clearTabButtonSelection() {
@@ -322,4 +340,16 @@ export class HomePage implements OnInit {
// this.sqliteservice.deleteAllTables(); // this.sqliteservice.deleteAllTables();
} }
reloadComponent(self:boolean,urlToNavigateTo ?:string){
//skipLocationChange:true means dont update the url to / when navigating
console.log("Current route I am on:",this.router.url);
const url=self ? this.router.url :urlToNavigateTo;
this.router.navigateByUrl('/',{skipLocationChange:true}).then(()=>{
this.router.navigate([`/${url}`]).then(()=>{
console.log(`After navigation I am on:${this.router.url}`)
})
})
}
} }
@@ -23,7 +23,7 @@ export class EditProfilePage implements OnInit {
SessionStore = SessionStore SessionStore = SessionStore
production = environment.production production = environment.production
environment = environment environment = environment
capturedImage = ''; capturedImage: any;
capturedImageTitle = ''; capturedImageTitle = '';
profilePicture = ""; profilePicture = "";
@@ -39,7 +39,8 @@ export class EditProfilePage implements OnInit {
) { } ) { }
ngOnInit() { ngOnInit() {
this.getProfilpictureFromStorage()
this.getProfilpictureFromStorage();
} }
getProfilpictureFromStorage() { getProfilpictureFromStorage() {
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => { this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
@@ -49,15 +50,15 @@ export class EditProfilePage implements OnInit {
this.profilePicture = ""; this.profilePicture = "";
}) })
} }
getProfilpicture(guid) { /* getProfilpicture(guid) {
console.log('Get picture ', guid.path) console.log('Get picture ', guid.path)
this.attachmentService.downloadFile(guid.path).subscribe(async (picture: any) => { this.attachmentService.getUserProfilePhoto().subscribe(async (picture: any) => {
console.log('Get picture ', picture)
let downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(picture.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); this.storageService.store(this.SessionStore.user.RoleID.toString() + "guid", guid.path)
console.log('Get picture ', downloadFile) this.storageService.store(this.SessionStore.user.RoleID.toString(), picture).then((value) => {
this.storageService.store(this.SessionStore.user.RoleID.toString()+"guid", guid.path) this.profilePicture = picture
this.storageService.store(this.SessionStore.user.RoleID.toString(), downloadFile).then((value) => { this.SessionStore.user.UserPhoto = picture;
console.log('picture saved') console.log('picture saved')
@@ -69,7 +70,7 @@ export class EditProfilePage implements OnInit {
console.log('Error get profile picture: ', error) console.log('Error get profile picture: ', error)
})) }))
} } */
close() { close() {
this.modalController.dismiss(); this.modalController.dismiss();
@@ -177,20 +178,27 @@ export class EditProfilePage implements OnInit {
source: CameraSource.Camera source: CameraSource.Camera
}); });
this.capturedImageTitle = SessionStore.user.Profile; this.capturedImage = capturedImage.base64String;
this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String; var object = JSON.stringify({
"ImageBase64": this.capturedImage
}
)
console.log('ATTACHME ', object)
const blob = this.dataURItoBlob(this.capturedImage) this.attachmentService.addUserProfilePhoto(object).subscribe((guid) => {
const formData = new FormData();
formData.append("blobFile", blob);
this.attachmentService.uploadFile(formData).subscribe((guid) => {
console.log('GUID ', guid) console.log('GUID ', guid)
console.log(this.SessionStore.user.RoleID.toString()) console.log(this.SessionStore.user.RoleID.toString())
this.getProfilpicture(guid); this.storageService.store(this.SessionStore.user.RoleID.toString(), this.capturedImage).then((value) => {
this.profilePicture = 'data:image/jpeg;base64,' +this.capturedImage;
console.log('picture saved')
}).catch((error) => {
console.log('picture not saved')
});
/* this.getProfilpicture(guid); */
}, ((error) => { }, ((error) => {
console.log('Erro Upload profile picture ',error) console.log('Erro Upload profile picture ', error)
})) }))
} }
+4 -2
View File
@@ -85,14 +85,16 @@ export class ProfilePage implements OnInit {
ngOnInit() { ngOnInit() {
this.getNotificationData(); this.getNotificationData();
this.getProfilpicture();
this.getProfilpicture();
} }
getProfilpicture() { getProfilpicture() {
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => { this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
console.log(picture) console.log(picture)
this.profilePicture = picture this.profilePicture = 'data:image/jpeg;base64,' +picture
}).catch((error ) => { }).catch((error ) => {
this.profilePicture = ""; this.profilePicture = "";
}) })
+1
View File
@@ -96,4 +96,5 @@ export class UserSession {
Inactivity: boolean Inactivity: boolean
UrlBeforeInactivity: string; UrlBeforeInactivity: string;
UserPermissions: any; UserPermissions: any;
UserPhoto: string;
} }
+40 -1
View File
@@ -5,6 +5,7 @@ import {
ViewChild, ViewChild,
ViewContainerRef, ViewContainerRef,
Output, Output,
NgZone,
} from '@angular/core'; } from '@angular/core';
import { ModalController, Platform } from '@ionic/angular'; import { ModalController, Platform } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service'; import { AuthService } from 'src/app/services/auth.service';
@@ -28,8 +29,13 @@ import { StorageService } from 'src/app/services/storage.service';
import { SessionStore } from 'src/app/store/session.service'; import { SessionStore } from 'src/app/store/session.service';
import { ChatDebuggingPage } from 'src/app/shared/popover/chat-debugging/chat-debugging.page'; import { ChatDebuggingPage } from 'src/app/shared/popover/chat-debugging/chat-debugging.page';
import { EventTrigger } from 'src/app/services/eventTrigger.service'; import { EventTrigger } from 'src/app/services/eventTrigger.service';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
import { Plugins } from '@capacitor/core';
const { App } = Plugins;
@Component({ @Component({
selector: 'app-chat', selector: 'app-chat',
templateUrl: './chat.page.html', templateUrl: './chat.page.html',
@@ -115,7 +121,9 @@ export class ChatPage implements OnInit {
private storageservice: StorageService, private storageservice: StorageService,
public ChatSystemService: ChatSystemService, public ChatSystemService: ChatSystemService,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private eventTriger: EventTrigger private eventTriger: EventTrigger,
private RochetChatConnectorService: RochetChatConnectorService,
private zone: NgZone
) { ) {
this.headers = new HttpHeaders(); this.headers = new HttpHeaders();
@@ -140,6 +148,7 @@ export class ChatPage implements OnInit {
ngOnInit() { ngOnInit() {
console.log("Loading TestComponent")
this.segment = "Contactos"; this.segment = "Contactos";
this.authService.userData$.subscribe((res: any) => { this.authService.userData$.subscribe((res: any) => {
@@ -164,6 +173,22 @@ export class ChatPage implements OnInit {
}); });
this.routeCheck() this.routeCheck()
if (!this.platform.is('desktop')) {
App.addListener('appStateChange', ({ isActive }) => {
if (isActive) {
// The app is in the foreground.
console.log('App is in the foreground');
this.RochetChatConnectorService.connect()
this.reloadComponent(true)
} else {
// The app is in the background.
console.log('App is in the background');
// You can perform actions specific to the background state here.
}
});
}
} }
routeCheck() { routeCheck() {
@@ -409,6 +434,7 @@ export class ChatPage implements OnInit {
onSegmentChange() { onSegmentChange() {
this.ChatSystemService.getAllRooms(); this.ChatSystemService.getAllRooms();
this.ChatSystemService._dm
} }
doRefresh(event) { doRefresh(event) {
@@ -830,5 +856,18 @@ export class ChatPage implements OnInit {
await modal.present(); await modal.present();
} }
reloadComponent(self:boolean,urlToNavigateTo ?:string){
//skipLocationChange:true means dont update the url to / when navigating
console.log("Current route I am on:",this.router.url);
const url=self ? this.router.url :urlToNavigateTo;
this.zone.run(() =>this.router.navigateByUrl('/',{skipLocationChange:true}).then(()=>{
this.zone.run(() => this.router.navigate([`/${url}`]).then(()=>{
console.log(`After navigation I am on:${this.router.url}`)
}))
}))
}
} }
+41 -19
View File
@@ -36,7 +36,7 @@ export class AttachmentsService {
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey); this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
} }
uploadFile(formData:any) { uploadFile(formData: any) {
@@ -50,7 +50,7 @@ export class AttachmentsService {
return this.http.post(`${geturl}`, formData, options); return this.http.post(`${geturl}`, formData, options);
} }
getFile(guid:any) { getFile(guid: any) {
const geturl = environment.apiURL + 'lakefs/StreamFile'; const geturl = environment.apiURL + 'lakefs/StreamFile';
let params = new HttpParams(); let params = new HttpParams();
@@ -66,9 +66,9 @@ export class AttachmentsService {
return this.http.get<any>(`${geturl}`, options); return this.http.get<any>(`${geturl}`, options);
} }
downloadFile(guid:any) { downloadFile(guid: any) {
let downloadUrl = environment.apiURL +'objectserver/streamfiles?path='+guid; let downloadUrl = environment.apiURL + 'objectserver/streamfiles?path=' + guid;
var name = new Date().getTime(); var name = new Date().getTime();
return this.http.get(downloadUrl, { return this.http.get(downloadUrl, {
responseType: "arraybuffer", responseType: "arraybuffer",
@@ -77,30 +77,30 @@ export class AttachmentsService {
} }
downloadFileAndStore(guid:any) { downloadFileAndStore(guid: any) {
var name = new Date().getTime(); var name = new Date().getTime();
const downloadPath = ( const downloadPath = (
this.platform.is('android') this.platform.is('android')
) ? this.file.externalDataDirectory : this.file.documentsDirectory; ) ? this.file.externalDataDirectory : this.file.documentsDirectory;
let vm = this; let vm = this;
/** HttpClient - @angular/common/http */ /** HttpClient - @angular/common/http */
this.http.get( this.http.get(
environment.apiURL +'objectserver/streamfiles?path='+guid, environment.apiURL + 'objectserver/streamfiles?path=' + guid,
{ {
responseType: 'arraybuffer', responseType: 'arraybuffer',
} }
).subscribe((fileBlob: Uint8Array) => { ).subscribe((fileBlob: Uint8Array) => {
/** File - @ionic-native/file/ngx */ /** File - @ionic-native/file/ngx */
vm.file.writeFile(downloadPath, "YourFileName.pdf", fileBlob, {replace: true}); vm.file.writeFile(downloadPath, "YourFileName.pdf", fileBlob, { replace: true });
}); });
} }
getAttachmentsBySerial(serialNumber: string): Observable<Attachment[]>{ getAttachmentsBySerial(serialNumber: string): Observable<Attachment[]> {
let geturl = environment.apiURL + 'attachments/GetAttachments'; let geturl = environment.apiURL + 'attachments/GetAttachments';
let params = new HttpParams(); let params = new HttpParams();
@@ -150,7 +150,7 @@ export class AttachmentsService {
let options = { let options = {
headers: this.headers, headers: this.headers,
} }
return this.http.post(`${geturl}`, body, options); return this.http.post(`${geturl}`, body, options);
} }
deleteEventAttachmentById(attachmentId) { deleteEventAttachmentById(attachmentId) {
@@ -166,7 +166,7 @@ export class AttachmentsService {
params: params params: params
} }
return this.http.delete(`${geturl}`, options); return this.http.delete(`${geturl}`, options);
} }
AddAttachment(body: any) { AddAttachment(body: any) {
@@ -175,7 +175,29 @@ export class AttachmentsService {
let options = { let options = {
headers: this.headers, headers: this.headers,
} }
return this.http.post(`${geturl}`, body, options); return this.http.post(`${geturl}`, body, options);
}
addUserProfilePhoto(formData: any) {
const geturl = environment.apiURL + 'UserAuthentication/AddPhoto';
this.headers = this.headers.set('content-type', "application/json");
this.headers = this.headers.set('accept', "application/json");
let options = {
headers: this.headers
};
return this.http.post(`${geturl}`, formData, options);
}
getUserProfilePhoto() {
const geturl = environment.apiURL + 'UserAuthentication/GetPhoto';
let options = {
headers: this.headers
};
return this.http.get(`${geturl}`, options);
} }
} }
@@ -18,12 +18,23 @@ export class RochetChatConnectorService {
constructor(private backgroundservice: BackgroundService,) { constructor(private backgroundservice: BackgroundService,) {
} }
reConnect() {
console.log('Connect1 ',this.ws.connected)
if(!this.ws.connected) {
this.ws.connect()
console.log('Connect2 ',this.ws.connected)
}
}
connect() { connect() {
console.log('Check conetion 11')
// dont connect if is already connected // dont connect if is already connected
if(this.ws.connected == true) { if(this.ws.connected == true) {
console.log('Check conetion 22')
return false return false
} }
console.log('Check conetion 33')
this.ws.connect(); this.ws.connect();
const message = { const message = {
+7 -4
View File
@@ -75,17 +75,20 @@ export class HeaderPage implements OnInit {
} }
async ngOnInit() { ngOnInit() {
this.hideSearch(); this.hideSearch();
/* this.notificationLengthData(); */
this.getProfilpicture(); this.getProfilpicture();
} }
ng
getProfilpicture() { getProfilpicture() {
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => { this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
console.log(picture) console.log(picture)
this.profilePicture = picture this.profilePicture = 'data:image/jpeg;base64,' +picture
}).catch((error ) => { }).catch((error ) => {
this.profilePicture = ""; this.profilePicture = "";
}) })
+2 -2
View File
@@ -59,7 +59,7 @@ self.addEventListener('message', function(event){
}); });
self.addEventListener('notificationclick', function(event) { /* self.addEventListener('notificationclick', function(event) {
console.log("Push Clicked ", event); console.log("Push Clicked ", event);
// Enviar uma mensagem para o cliente (componente) // Enviar uma mensagem para o cliente (componente)
self.clients.matchAll().then((clients) => { self.clients.matchAll().then((clients) => {
@@ -70,4 +70,4 @@ self.addEventListener('notificationclick', function(event) {
}); });
} }
}); });
}); }); */