This commit is contained in:
Peter Maquiran
2023-01-24 15:56:47 +01:00
parent 0748612054
commit fbd50137f3
153 changed files with 5997 additions and 953 deletions
+6 -12
View File
@@ -24,22 +24,16 @@ export class AttachmentsService {
private changeProfileService: ChangeProfileService) {
this.changeProfileService.registerCallback(() => {
this.loggeduser = SessionStore.user
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
})
this.changeProfileService.registerLoginCallback(() => {
this.loggeduser = SessionStore.user
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
})
this.setHeader()
});
this.setHeader()
}
setHeader() {
this.loggeduser = SessionStore.user
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
}
uploadFile(formData:any) {
+4 -4
View File
@@ -25,7 +25,7 @@ import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
export class AuthService {
userData$ = new BehaviorSubject<any>('');
userId$ = new BehaviorSubject<any>('');
headers: HttpHeaders;
headers: HttpHeaders = new HttpHeaders();
public wsValidatedUserChat:any;
public isWsAuthenticated: boolean = false;
opts:any;
@@ -43,9 +43,7 @@ export class AuthService {
private storage: Storage,
private initialsService: InitialsService,
public p: PermissionService,
public ChatSystemService: ChatSystemService, ) {
this.headers = new HttpHeaders();
public ChatSystemService: ChatSystemService) {
if (SessionStore.exist) {
if(this.p.userPermission(this.p.permissionList.Chat.access) == true ) {
@@ -82,6 +80,8 @@ export class AuthService {
}
// async UpdateLogin() {}
SetSession(response: LoginUserRespose, user:UserForm) {
const session: UserSession = Object.assign(SessionStore.user, response)
@@ -25,6 +25,7 @@ export class ChatMethodsService {
"end_date": data.end,
"venue": data.venue,
"id": data.id,
"calendarId": data.calendarId
}
}
}
+20 -13
View File
@@ -18,7 +18,6 @@ import { ChatMethodsService } from './chat-methods.service';
import { AESEncrypt } from '../aesencrypt.service'
import { AttachmentsService } from 'src/app/services/attachments.service';
import { NetworkServiceService} from 'src/app/services/network-service.service';
import { JsonStore } from '../jsonStore.service';
import { ViewedMessageService } from './viewed-message.service'
@Injectable({
providedIn: 'root'
@@ -97,7 +96,7 @@ export class ChatSystemService {
}
loadChat() {
if(SessionStore.user.ChatData) {
if(SessionStore.user?.ChatData?.data) {
this.ReLoadChat()
}
}
@@ -185,14 +184,18 @@ export class ChatSystemService {
async getAllRooms () {
this.loadingWholeList = true
var rooms;
try {
rooms = await this.RochetChatConnectorService.getRooms();
} catch (error) {
console.error('chatgetrooms',error)
}
if(this.RochetChatConnectorService.isLogin) {
try {
await this.storage.remove('Rooms');
} catch(e) {}
rooms = await this.RochetChatConnectorService.getRooms();
} catch (error) {
this.loadingWholeList = false
console.error('chatgetrooms',error)
}
try {
await this.storage.remove('Rooms');
} catch(e) {}
}
let index = 0
@@ -317,8 +320,12 @@ export class ChatSystemService {
this.defaultSubtribe(id)
}
this.RochetChatConnectorService.streamNotifyLogged().then((subscription=>{
this.RochetChatConnectorService.streamNotifyLogged().then((subscription => {
console.log(subscription)
}))
this.RochetChatConnectorService.subStreamMessageUser().then((subscription => {
console.log(subscription)
}))
}
@@ -407,7 +414,7 @@ export class ChatSystemService {
let roomId = this.getRoomId(roomData);
if (setData.name != 'Rocket Cat') {
if (setData.name != 'Rocket Cat' && setData.name != 'general' ) {
// create room
if(!this.roomExist(roomId)) {
let room:RoomService = new RoomService(this.RochetChatConnectorService, new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this, this.ViewedMessageService)
@@ -615,7 +622,7 @@ export class ChatSystemService {
return !roomData.fname
}
getUsers = () =>{
getUsers = () => {
return this.users
}
+35 -9
View File
@@ -61,6 +61,9 @@ export class MessageService {
downloadAttachmentsTemp = 0;
UploadAttachmentsTemp = 0;
manualRetry = false
origin: 'history' | 'stream' | 'local'
rowInstance: MessageModel
constructor(
private NfService: NfService,
@@ -72,7 +75,7 @@ export class MessageService {
private ChatSystemService: ChatSystemService) {
}
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0 }:Message) {
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0, origin }:Message) {
this.channels = channels || []
this.mentions = mentions || []
@@ -90,6 +93,7 @@ export class MessageService {
this.delate = delate
this.delateRequest = delateRequest
this.sendAttempt = 0
this.origin = origin
if(this.attachments?.length >= 1 && attachments?.length >= 1) {
this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
@@ -257,6 +261,7 @@ export class MessageService {
} catch (error) {
this.uploadingFile = false
this.errorUploadingAttachment = true
this.UploadAttachmentsTemp++
console.error('beforeSendAttachment error:', error)
}
@@ -441,9 +446,11 @@ export class MessageService {
async delateDB() {
const message = await MessageModel.get({id: this.id})
await message.delete()
if(!this.rowInstance) {
this.rowInstance = await this.getRowInstance()
}
await this.rowInstance.delete()
}
@@ -467,6 +474,7 @@ export class MessageService {
u: this.u,
_id: this._id,
id: this.id,
origin: this.origin,
_updatedAt: this._updatedAt,
messageSend: this.messageSend,
offline: this.offline,
@@ -489,6 +497,7 @@ export class MessageService {
delete message.id
const createdMessage = await MessageModel.create(message)
this.rowInstance = createdMessage
this.id = createdMessage.id
if(this.earlySave) {
@@ -497,8 +506,8 @@ export class MessageService {
}
}
async saveChanges() {
async getRowInstance () {
if(this.save) {
const message = this.getChatObj()
@@ -516,12 +525,29 @@ export class MessageService {
a = await MessageModel.get({id: this.id})
}
if(a) {
for( const [name, value] of Object.entries(message)) {
a[name] = value
}
await a.save()
return a
}
}
async saveChanges() {
if(!this.rowInstance) {
this.rowInstance = await this.getRowInstance()
}
if(this.save && this.rowInstance) {
const message = this.getChatObj()
if(!message.id) {
delete message.id
}
for( const [name, value] of Object.entries(message)) {
this.rowInstance[name] = value
}
await this.rowInstance.save()
} else {
this.earlySave = true
@@ -437,6 +437,63 @@ export class RochetChatConnectorService {
}
subStreamNotifyUser(param?: any) {
const requestId = uuidv4()
let message = {
msg: "sub",
id: requestId,
name: "stream-notify-user",
params:[
`${SessionStore.user.ChatData.data.userId}/notification`,
param
]
}
this.ws.send({message, requestId})
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
}})
});
}
subStreamMessageUser(param?: any) {
const requestId = uuidv4()
let message = {
msg: "sub",
id: requestId,
name: "stream-notify-user",
params:[
`${SessionStore.user.ChatData.data.userId}/message`,
param
]
}
this.ws.send({message, requestId})
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
}})
});
}
receiveStreamNotifyRoom(funx: Function) {
this.ws.registerCallback({
+23 -7
View File
@@ -275,18 +275,25 @@ export class RoomService {
if(message.fields.eventName == this.id+'/'+'typing') {
const args = message.fields.args
if (typeof args[1] != 'object') {
this.userThatIsTyping = this.usernameToDisplayName(args[0])
this.isTyping = args[1]
this.otherUserType = args[1]
this.readAllMessage()
const user = args[0]
if(SessionStore.user.UserName != user) {
this.readAllMessage()
}
} else if(args[0]?.method == 'viewMessage' || args[1]?.method == 'viewMessage') {
this.readAllMessage()
const user = args[0]
if(SessionStore.user.UserName != user) {
this.readAllMessage()
}
} else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') {
this.deleteMessage(args[1]?.method?._id)
@@ -295,7 +302,6 @@ export class RoomService {
}
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
})
@@ -313,6 +319,7 @@ export class RoomService {
if(!found) {
ChatMessage.origin = 'stream'
const message = await this.prepareCreate({message: ChatMessage, save: true});
this.registerSendMessage(message)
@@ -445,7 +452,13 @@ export class RoomService {
"stream-notify-room",
async (ChatMessage) => {
const DeletedMessageId = ChatMessage.fields.args[0]._id;
this.deleteMessage(DeletedMessageId)
const message = this.messages.find((e) => e._id == DeletedMessageId)
if(message.delate == false) {
this.deleteMessage(DeletedMessageId)
}
}
)
}
@@ -556,7 +569,8 @@ export class RoomService {
attachments,
file,
temporaryData,
localReference
localReference,
origin: 'local'
}
this.message= ''
@@ -657,6 +671,7 @@ export class RoomService {
// this.typing(this.message)
this.chatOpen = true
this.messageUnread = false
this.sendReadMessage()
}
@@ -737,6 +752,7 @@ export class RoomService {
for(let message of chatHistory.result.messages.reverse()) {
if (!messagesId.includes(message._id)) {
message.origin = 'history'
const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message});
if(messagesToSave != null) {
@@ -27,9 +27,9 @@ export class ViewedMessageService {
for(let id of membersIds) {
if(message.addReceived(id)) {
n++
setTimeout(async() => {
// setTimeout(async() => {
await message.saveChanges()
}, 100 * n)
// }, 100 * n)
}
}
}
@@ -56,9 +56,9 @@ export class ViewedMessageService {
if(message.addViewed(id)) {
message.addReceived(id)
n++
setTimeout(async() => {
// setTimeout(async() => {
await message.saveChanges()
}, 100 * n)
// }, 100 * n)
}
}
+13 -1
View File
@@ -6,6 +6,7 @@ import { environment } from 'src/environments/environment';
import { AuthService } from '../services/auth.service';
import { LoginUserRespose } from '../models/user.model';
import { SessionStore } from '../store/session.service';
import { ChangeProfileService } from './change-profile.service';
@Injectable({
providedIn: 'root'
@@ -16,7 +17,18 @@ export class ContactsService {
loggeduser: LoginUserRespose;
headers: HttpHeaders;
constructor(private http: HttpClient, user: AuthService) {
constructor(
private http: HttpClient,
user: AuthService,
private changeProfileService: ChangeProfileService) {
this.setHeader()
this.changeProfileService.registerCallback(() => {
this.setHeader()
})
}
setHeader() {
this.loggeduser = SessionStore.user;
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
+66 -82
View File
@@ -4,7 +4,6 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable, from } from 'rxjs';
import { environment } from 'src/environments/environment';
import { AuthService } from '../services/auth.service';
import { UserSession } from '../models/user.model';
import { EventList } from '../models/agenda/AgendaEventList';
import { ChangeProfileService } from './change-profile.service';
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
@@ -20,7 +19,6 @@ import { SessionStore } from '../store/session.service';
export class EventsService {
authheader = {};
loggeduser: UserSession;
headers: HttpHeaders;
headersPrOficial: HttpHeaders;
@@ -37,25 +35,17 @@ export class EventsService {
headersSharedOficial: HttpHeaders;
headersSharedPessoal: HttpHeaders;
hasSharedCalendar = false
hasOwnCalendar = false
calendarIds = []
usersCalendarIds = []
hasSharedCalendar = false;
hasSharedOficial: boolean = false;
hasSharedPessoal: boolean = false;
hasOwnOficial: boolean = false;
hasOwnPessoal: boolean = false;
userCalendarNameSharedOficial = '';
userCalendarNameSharedPessoal = '';
userCalendarNameOwnOficial = '';
userCalendarNameOwnPessoal = '';
hasOwnCalendar = false
calendarNames = {}
@@ -73,7 +63,14 @@ export class EventsService {
private storage: Storage,
private backgroundservice: BackgroundService) {
this.loggeduser = SessionStore.user;
this.setHeader()
this.changeProfileService.registerCallback(() => {
this.setHeader()
})
}
async setHeader () {
this.headers = new HttpHeaders();
this.headersMdOficial = new HttpHeaders();
@@ -92,16 +89,14 @@ export class EventsService {
this.headerSharedOficial= new HttpHeaders();
this.headerSharedPessoal= new HttpHeaders();
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
this.setHeader()
this.changeProfileService.registerCallback(() => {
this.loggeduser = SessionStore.user;
this.setHeader()
})
}
async setHeader () {
this.usersCalendarIds = [];
this.calendarNames = {}
this.calendarIds = []
this.calendarNamesAry = []
this.calendarNamesType = {}
this.hasSharedCalendar = false
this.hasSharedOficial = false
@@ -110,32 +105,11 @@ export class EventsService {
this.hasOwnCalendar = false
this.hasOwnOficial = false
this.hasOwnPessoal = false
this.headers = new HttpHeaders();
this.headerOwnOficial= new HttpHeaders();
this.headerOwnPessoal= new HttpHeaders();
this.headerSharedOficial= new HttpHeaders();
this.headerSharedPessoal= new HttpHeaders();
if (SessionStore.user) {
if (SessionStore.user.Profile == 'MDGPR') {
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
this.userCalendarNameSharedOficial = '';
this.userCalendarNameSharedPessoal = '';
this.userCalendarNameOwnOficial = '';
this.userCalendarNameOwnPessoal = '';
this.usersCalendarIds = [];
this.calendarNames = {}
this.calendarNamesAry = []
this.calendarNamesType = {}
if (this.loggeduser) {
if (this.loggeduser.Profile == 'MDGPR') {
for (let calendar of this.loggeduser.OwnerCalendars) {
for (let calendar of SessionStore.user.OwnerCalendars) {
this.hasAnyCalendar = false
if (calendar.CalendarName == 'Oficial') {
@@ -143,7 +117,7 @@ export class EventsService {
this.hasOwnOficial = true
this.headersMdOficial = this.headersMdOficial.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersMdOficial = this.headersMdOficial.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersMdOficial = this.headersMdOficial.set('CalendarId', calendar.CalendarId);
this.headersMdOficial = this.headersMdOficial.set('CalendarRoleId', calendar.CalendarRoleId);
}
@@ -151,21 +125,21 @@ export class EventsService {
this.hasOwnPessoal = true
this.headersMdPessoal = this.headersMdPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersMdPessoal = this.headersMdPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersMdPessoal = this.headersMdPessoal.set('CalendarId', calendar.CalendarId);
this.headersMdPessoal = this.headersMdPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
}
}
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
this.hasAnyCalendar = false
if (sharedCalendar.CalendarName == 'Oficial') {
this.hasSharedOficial = true
this.headersSharedOficial = this.headersSharedOficial.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersSharedOficial = this.headersSharedOficial.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersSharedOficial = this.headersSharedOficial.set('CalendarId', sharedCalendar.CalendarId);
this.headersSharedOficial = this.headersSharedOficial.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
}
@@ -173,7 +147,7 @@ export class EventsService {
this.hasSharedPessoal = true
this.headersSharedPessoal = this.headersSharedPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersSharedPessoal = this.headersSharedPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersSharedPessoal = this.headersSharedPessoal.set('CalendarId', sharedCalendar.CalendarId);
this.headersSharedPessoal = this.headersSharedPessoal.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
}
@@ -181,15 +155,15 @@ export class EventsService {
}
else if (this.loggeduser.Profile == 'PR') {
else if (SessionStore.user.Profile == 'PR') {
for (let calendar of this.loggeduser.OwnerCalendars) {
for (let calendar of SessionStore.user.OwnerCalendars) {
this.hasAnyCalendar = false
if (calendar.CalendarName == 'Oficial') {
this.hasOwnOficial = true
this.headersPrOficial = this.headersPrOficial.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersPrOficial = this.headersPrOficial.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersPrOficial = this.headersPrOficial.set('CalendarId', calendar.CalendarId);
this.headersPrOficial = this.headersPrOficial.set('CalendarRoleId', calendar.CalendarRoleId);
}
@@ -197,7 +171,7 @@ export class EventsService {
this.hasOwnPessoal = true
this.headersPrPessoal = this.headersPrPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersPrPessoal = this.headersPrPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
this.headersPrPessoal = this.headersPrPessoal.set('CalendarId', calendar.CalendarId);
this.headersPrPessoal = this.headersPrPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
@@ -206,7 +180,7 @@ export class EventsService {
}
for (let calendar of this.loggeduser.OwnerCalendars) {
for (let calendar of SessionStore.user.OwnerCalendars) {
this.hasAnyCalendar = false
if(!this.usersCalendarIds.includes(calendar.OwnerUserId)) {
this.usersCalendarIds.push(calendar.OwnerUserId)
@@ -222,7 +196,7 @@ export class EventsService {
this.hasOwnOficial = true
this.headerOwnOficial = this.headerOwnOficial.set('Authorization', this.loggeduser.BasicAuthKey);
this.headerOwnOficial = this.headerOwnOficial.set('Authorization', SessionStore.user.BasicAuthKey);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarId', calendar.CalendarId);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarRoleId', calendar.CalendarRoleId);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarName', calendar.CalendarName);
@@ -231,14 +205,14 @@ export class EventsService {
this.hasOwnPessoal = true
this.headerOwnPessoal = this.headerOwnPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
this.headerOwnPessoal = this.headerOwnPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
this.headerOwnPessoal =this.headerOwnPessoal.set('CalendarId', calendar.CalendarId);
this.headerOwnPessoal =this.headerOwnPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
this.headerOwnPessoal = this.headerOwnPessoal.set('CalendarName', calendar.CalendarName);
}
}
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
this.hasAnyCalendar = false
if(!this.usersCalendarIds.includes(sharedCalendar.OwnerUserId)) {
@@ -254,7 +228,7 @@ export class EventsService {
if (sharedCalendar.CalendarName == 'Oficial') {
this.hasSharedOficial = true
this.headerSharedOficial = this.headerSharedOficial.set('Authorization',this.loggeduser.BasicAuthKey);
this.headerSharedOficial = this.headerSharedOficial.set('Authorization',SessionStore.user.BasicAuthKey);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarId', sharedCalendar.CalendarId);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarName', sharedCalendar.CalendarName);
@@ -263,7 +237,7 @@ export class EventsService {
this.hasSharedPessoal = true
this.headerSharedPessoal = this.headerSharedPessoal.set('Authorization',this.loggeduser.BasicAuthKey);
this.headerSharedPessoal = this.headerSharedPessoal.set('Authorization',SessionStore.user.BasicAuthKey);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarId', sharedCalendar.CalendarId);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarName', sharedCalendar.CalendarName);
@@ -271,7 +245,7 @@ export class EventsService {
}
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
this.hasAnyCalendar = false
if(sharedCalendar?.OwnerUserId) {
this.GetCalendarName(sharedCalendar.OwnerUserId).subscribe((e)=> {
@@ -291,7 +265,7 @@ export class EventsService {
}
for (let sharedCalendar of this.loggeduser.OwnerCalendars) {
for (let sharedCalendar of SessionStore.user.OwnerCalendars) {
this.hasAnyCalendar = false
this.calendarNames[sharedCalendar.CalendarId] = 'Meu calendario'
@@ -326,13 +300,13 @@ export class EventsService {
isMyEvent(event: any) {
for (let calendar of this.loggeduser.OwnerCalendars) {
for (let calendar of SessionStore.user.OwnerCalendars) {
if(event.CalendarId == calendar.CalendarId) {
return true
}
}
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
if(event.CalendarId == sharedCalendar.CalendarId) {
return false
}
@@ -438,12 +412,18 @@ export class EventsService {
let prO = [], prP = [];
for (let calendar of this.loggeduser.OwnerCalendars) {
for (let calendar of SessionStore.user.OwnerCalendars) {
if (calendar.CalendarName == 'Oficial') {
prO = await this.getAllMdOficialEvents(startdate, enddate).toPromise();
if(!Array.isArray(prO)) {
prO = []
}
}
if(calendar.CalendarName == 'Pessoal') {
prP = await this.getAllMdPessoalEvents(startdate, enddate).toPromise();
if(!Array.isArray(prP)) {
prP = []
}
}
}
@@ -462,10 +442,16 @@ export class EventsService {
if(this.hasOwnOficial) {
ownO = await this.getAllOwnOficialEvents(startdate, enddate).toPromise();
if(!Array.isArray(ownO)) {
ownO = []
}
}
if(this.hasOwnPessoal) {
ownP = await this.getAllOwnPessoalEvents(startdate, enddate).toPromise();
if(!Array.isArray(ownP)) {
ownP = []
}
}
const resFinal = ownO.concat(ownP);
@@ -509,10 +495,10 @@ export class EventsService {
let result = []
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
var header = new HttpHeaders();
header = header.set('Authorization', this.loggeduser.BasicAuthKey);
header = header.set('Authorization', SessionStore.user.BasicAuthKey);
header = header.set('CalendarId', sharedCalendar.CalendarId);
header = header.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
header = header.set('CalendarName', sharedCalendar.CalendarName);
@@ -579,7 +565,7 @@ export class EventsService {
let prO = [], prP = [];
for(let calendar of this.loggeduser.SharedCalendars) {
for(let calendar of SessionStore.user.SharedCalendars) {
if (calendar.CalendarName == 'Oficial') {
prO = await this.getAllSharedOficialEvents(startdate, enddate).toPromise();
}
@@ -596,8 +582,6 @@ export class EventsService {
});
}
getAllSharedOficialEvents(startdate: string, enddate: string): Observable<Event[]> {
let geturl = environment.apiURL + 'calendar/pr';
geturl = geturl.replace('/V4/', '/V5/')
@@ -733,10 +717,10 @@ export class EventsService {
this.headers['CalendarName'] = event.CalendarName
if (event.CalendarName == 'Oficial') {
if (this.loggeduser.Profile == 'MDGPR') {
if (SessionStore.user.Profile == 'MDGPR') {
this.headers = this.headersMdOficial;
}
else if (this.loggeduser.Profile == 'PR') {
else if (SessionStore.user.Profile == 'PR') {
this.headers = this.headersPrOficial;
} else {
@@ -755,10 +739,10 @@ export class EventsService {
}
}
else {
if (this.loggeduser.Profile == 'MDGPR') {
if (SessionStore.user.Profile == 'MDGPR') {
this.headers = this.headersMdPessoal;
}
else if (this.loggeduser.Profile == 'PR') {
else if (SessionStore.user.Profile == 'PR') {
this.headers = this.headersPrPessoal;
}
else {
@@ -904,7 +888,7 @@ export class EventsService {
let options;
switch (this.loggeduser.Profile) {
switch (SessionStore.user.Profile) {
case 'MDGPR':
if (calendarName == 'Pessoal') {
options = {
@@ -962,7 +946,7 @@ export class EventsService {
let options;
if(this.loggeduser.Profile == 'MDGPR') {
if(SessionStore.user.Profile == 'MDGPR') {
if (calendarName == 'Pessoal') {
options = {
headers: this.headersMdPessoal,
@@ -976,7 +960,7 @@ export class EventsService {
};
}
}
else if (this.loggeduser.Profile == 'PR') {
else if (SessionStore.user.Profile == 'PR') {
if (calendarName == 'Pessoal') {
options = {
headers: this.headersPrPessoal,
@@ -1038,7 +1022,7 @@ export class EventsService {
params = params.set("SerialNumber", serialNumber);
params = params.set("applicationID", applicationID);
switch (this.loggeduser.Profile) {
switch (SessionStore.user.Profile) {
case 'MDGPR':
if (body.CalendarName == 'Pessoal') {
options = {
@@ -1109,7 +1093,7 @@ export class EventsService {
params = params.set("SerialNumber", serialNumber);
params = params.set("applicationID", applicationID);
switch (this.loggeduser.Profile) {
switch (SessionStore.user.Profile) {
case 'MDGPR':
if (body.CalendarName == 'Pessoal') {
options = {
-1
View File
@@ -11,7 +11,6 @@ import { SessionStore } from '../store/session.service';
export class FirstEnterService {
constructor(private router:Router,
private platform: Platform,
public p: PermissionService,
private alertController: AlertController) { }
+103 -110
View File
@@ -1,22 +1,17 @@
/* eslint-disable */
/* tslint:disable */
import { Injectable, NgZone } from '@angular/core';
import { ActivatedRoute } from '@angular/router'
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { StorageService } from 'src/app/services/storage.service';
import { AuthConnstants } from 'src/app/config/auth-constants';
import { Tokenn } from '../models/token.model';
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
import { NavigationExtras, Router } from '@angular/router';
import { ToastService } from '../services/toast.service';
import { BackgroundService } from './background.service';
import { v4 as uuidv4 } from 'uuid';
import { AlertController, Platform } from '@ionic/angular';
import { Router } from '@angular/router';
import { EventTrigger } from '../services/eventTrigger.service';
import { SessionStore } from '../store/session.service';
// import { ActionPerformed, PushNotificationSchema, PushNotifications, Token, } from '@capacitor/push-notifications';
import { IdObject } from '../models/notifications';
/* import { Events } from 'ionic-angular' */
import { ActionPerformed, PushNotificationSchema, PushNotifications, Token, } from '@capacitor/push-notifications';
import { notificationObject } from '../models/notifications';
@Injectable({
providedIn: 'root'
@@ -27,52 +22,59 @@ export class NotificationsService {
folderId: string;
DataArray = new Array();
callbacks: {
type: string,
callbacks: {[key: string]: {
type: notificationObject,
funx: Function
id: string
}[] = []
}} = {}
active = false
constructor(
private http: HttpClient,
private storageService: StorageService,
private modalController: ModalController,
public modalCtrl: AlertController,
private animationController: AnimationController,
private platform: Platform,
private router: Router,
private toastService: ToastService,
private zone: NgZone,
private activeroute: ActivatedRoute,
private eventtrigger: EventTrigger,
private backgroundservice: BackgroundService,
/* private eventTriger: Events, */
/* private fcm: FCM */) {
private eventtrigger: EventTrigger,) {
}
registerCallback(type: IdObject, funx: Function, object: any = {}) {
const id = uuidv4()
this.callbacks.push({ type, funx, id })
if (!object.hasOwnProperty('desktop') && object['desktop'] != false) {
this.backgroundservice.registerBackService('Notification', funx, type)
}
return id;
}
// registerCallback({type, funx, id = uuidv4()} : {
// type: notificationObject,
// funx: Function
// id?: string
// }) {
// this.callbacks[id] = { funx, id, type}
// return id;
// }
deleteCallback(id) {
this.callbacks.forEach((e, index) => {
if (e.id == id) {
if (index > -1) {
this.callbacks.splice(index, 1);
}
}
})
}
// private async runNotificationCallback(notification) {
// for (const [key, value] of Object.entries(this.callbacks)) {
// if(value.type == notification.data.Object) {
// const dontRepeat = await value.funx(notification)
// if(dontRepeat) {
// delete this.callbacks[key]
// }
// } else if (value.type == '*') {
// const dontRepeat = await value.funx(notification)
// if(dontRepeat) {
// delete this.callbacks[key]
// }
// }
// }
// }
getTokenByUserIdAndId(user, userID) {
// const geturl = environment.apiURL + 'notifications/user/' + userID;
@@ -81,14 +83,14 @@ export class NotificationsService {
}
requestPermissions() {
// PushNotifications.requestPermissions().then(result => {
// if (result.receive === 'granted') {
// // Register with Apple / Google to receive push via APNS/FCM
// PushNotifications.register();
// } else {
// // Show some error
// }
// });
PushNotifications.requestPermissions().then(result => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
}
getAndpostToken(username) {
@@ -96,86 +98,77 @@ export class NotificationsService {
} else {
const geturl = environment.apiURL + 'notifications/token';
// PushNotifications.addListener('registration',
// (token: Token) => {
PushNotifications.addListener('registration',
(token: Token) => {
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {
UserId: SessionStore.user.UserId,
TokenId: token.value,
Status: 1,
Service: 1
};
// this.active = false
// this.storageService.store(username, token.value);
// this.storageService.get(username).then(value => {
// this.storageService.get(AuthConnstants.USER).then(res => {
// const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
// const body = {
// UserId: res.UserId,
// TokenId: token.value,
// Status: 1,
// Service: 1
// };
// this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
// //console.log(data)
// }, (error) => {
// //console.log(error)
// })
// }).catch((error) => {
// console.error('storage authorization', error)
// });;
// }).catch((error) => {
// console.error('storage getAndPostToken', error)
// });
// }
// );
this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
this.active = true
console.log(data)
}, (error) => {
console.log(error)
})
}
);
}
}
registrationError() {
// PushNotifications.addListener('registrationError',
// (error: any) => {
// this.active = false
// }
// );
PushNotifications.addListener('registrationError',
(error: any) => {
this.active = false
}
);
}
onReciveForeground() {
// PushNotifications.addListener('pushNotificationReceived',
// (notification: PushNotificationSchema) => {
// console.log(notification)
// //this.DataArray.push(notification)
// //console.log(this.DataArray)
PushNotifications.addListener('pushNotificationReceived',
(notification: PushNotificationSchema) => {
this.active = true
console.log(notification)
//this.DataArray.push(notification)
//console.log(this.DataArray)
// this.storageService.get("Notifications").then((store) => {
// store.push(notification)
// this.storageService.store("Notifications", store)
// }).catch((error) => {
// if(!error) {
// this.storageService.store("Notifications", [notification])
// }
// })
this.storageService.get("Notifications").then((store) => {
store.push(notification)
this.storageService.store("Notifications", store)
}).catch((error) => {
if(!error) {
this.storageService.store("Notifications", [notification])
}
})
// /* this.eventTriger.publish('notificatioRecive') */
// this.eventtrigger.publishSomeData({
// notification: "recive"
// })
// }
// );
// this.runNotificationCallback(notification)
/* this.eventTriger.publish('notificatioRecive') */
this.eventtrigger.publishSomeData({
notification: "recive"
})
}
);
}
onReciveBackground() {
// PushNotifications.addListener('pushNotificationActionPerformed',
// (notification: ActionPerformed) => {
// console.log(notification)
// /* this.DataArray.push(notification.notification)
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
this.active = true
console.log(notification)
/* this.DataArray.push(notification.notification)
// this.storageService.store("Notifications", this.DataArray)
// this.eventtrigger.publishSomeData({
// notification: "recive"
// }) */
// this.notificatinsRoutes(notification)
// }
// );
this.storageService.store("Notifications", this.DataArray)
this.eventtrigger.publishSomeData({
notification: "recive"
}) */
this.notificatinsRoutes(notification)
// this.runNotificationCallback(notification)
}
);
}
tempClearArray(data) {
+13 -1
View File
@@ -7,6 +7,7 @@ import { AuthService } from '../services/auth.service';
import { LoginUserRespose } from '../models/user.model';
import { OrganicEntity } from 'src/app/models/organic-entity.model';
import { SessionStore } from '../store/session.service';
import { ChangeProfileService } from './change-profile.service';
@Injectable({
providedIn: 'root'
@@ -17,7 +18,18 @@ export class OrganicEntityService {
loggeduser: LoginUserRespose;
headers: HttpHeaders;
constructor(private http: HttpClient, user: AuthService) {
constructor(
private http: HttpClient,
user: AuthService,
private changeProfileService: ChangeProfileService) {
this.setHeader()
this.changeProfileService.registerCallback(() => {
this.setHeader()
})
}
setHeader() {
this.loggeduser = SessionStore.user;
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
+12 -2
View File
@@ -9,6 +9,7 @@ import { Publication } from '../models/publication';
import { getUrl } from 'ionicons/dist/types/components/icon/utils';
import { ActivatedRoute, Router } from '@angular/router';
import { SessionStore } from '../store/session.service';
import { ChangeProfileService } from './change-profile.service';
@Injectable({
providedIn: 'root'
@@ -23,11 +24,20 @@ export class PublicationsService {
constructor(private http: HttpClient, user: AuthService,
private activatedRoute: ActivatedRoute,
private router: Router) {
private router: Router,
private changeProfileService: ChangeProfileService,) {
this.setHeader()
this.changeProfileService.registerCallback(() => {
this.setHeader()
})
}
setHeader () {
this.loggeduser = SessionStore.user;
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
}
GetPublicationFolderList(){
+41 -1
View File
@@ -8,6 +8,7 @@ import { LoginUserRespose } from '../models/user.model';
import { EventSearch } from "src/app/models/event-search";
import { TopSearch } from 'src/app/models/top-search';
import { SessionStore } from '../store/session.service';
import { ChangeProfileService } from './change-profile.service';
@Injectable({
providedIn: 'root'
@@ -21,7 +22,20 @@ export class SearchService {
categories= Array;
// setup
constructor(private http: HttpClient, user: AuthService) {
constructor(
private http: HttpClient,
user: AuthService,
private changeProfileService: ChangeProfileService) {
this.setHeader();
this.changeProfileService.registerCallback(() => {
this.setHeader()
})
}
setHeader() {
this.loggeduser = SessionStore.user;
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
@@ -52,6 +66,32 @@ export class SearchService {
return this.http.get<EventSearch>(`${geturl}`, options);
}
basicSearchPublication(subject:string, date:string = null, sender:string = null, organicEntity:string = null, docTypeId:string = null, applicationType:string): Observable<EventSearch>{
// Endpoint
const geturl = environment.apiURL + 'search';
// store params
let params = new HttpParams();
// set https params
params = params.set("assunto", subject);
params = params.set("data", date);
params = params.set("remetente", sender);
params = params.set("entidadeOrganica", organicEntity);
params = params.set("docTypeId", docTypeId);
params = params.set("applicationType", applicationType);
params = params.set("listOnlyFolders", true)
const options = {
headers: this.headers,
params: params
};
return this.http.get<EventSearch>(`${geturl}`, options);
}
mostSeachWord(size:string):Observable<any>{
// Endpoint