Merge branch 'bugfix/message-order' into develop

This commit is contained in:
gilson.manuel
2022-07-26 15:14:48 +01:00
14 changed files with 160 additions and 89 deletions
+2 -1
View File
@@ -45,7 +45,8 @@
</ion-buttons>
</div>
<div class="line"></div>
<ion-label (click)="asyncNotification()">{{notificationdata.length}} novas notificações</ion-label>
<ion-label (click)="asyncNotification()" *ngIf="notificationdata">{{notificationdata.length}} novas notificações</ion-label>
<ion-label (click)="asyncNotification()" *ngIf="!notificationdata">0 novas notificações</ion-label>
</div>
</ion-header>
+1
View File
@@ -37,6 +37,7 @@
</ion-segment-button>
</ion-segment>
</ion-toolbar>
<div class=" aside overflow-y-auto d-flex flex-wrap flex-grow-1">
<div class="width-100" [ngSwitch]="segment">
<ion-list *ngSwitchCase="'Contactos'">
+3 -4
View File
@@ -125,6 +125,8 @@ export class ChatPage implements OnInit {
this.showLoader = true;
this.segment = 'Contactos'
}
ngOnInit() {
@@ -320,7 +322,6 @@ export class ChatPage implements OnInit {
async setIntervenient(data) {
this.taskParticipants = removeDuplicate(data)
}
async setIntervenientCC(data) {
@@ -339,12 +340,11 @@ export class ChatPage implements OnInit {
}
onSegmentChange() {
//this.load();
this.wsChatMethodsService.getAllRooms();
}
doRefresh(event) {
setTimeout(() => {
//this.load();
event.target.complete();
}, 1000);
}
@@ -357,7 +357,6 @@ export class ChatPage implements OnInit {
});
}
getDirectMessagesDB() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storageservice.get("rooms").then((rooms) =>{
@@ -150,7 +150,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
})
//this.loadFiles();
}
setStatus(status: string) {
@@ -104,7 +104,6 @@ export class ContactsPage implements OnInit {
this.room = res['room'];
await this.WsChatMethodsService.getAllRooms();
this.getDirectMessage(this.room._id);
});
@@ -148,7 +147,6 @@ export class ContactsPage implements OnInit {
/* this.getDirectMessage(this.room._id); */
/* const modal = await this.modalController.create({
component: MessagesPage,
cssClass: 'group-messages',
@@ -126,7 +126,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
private sqlservice: SqliteService,
public wsChatMethodsService: WsChatMethodsService,
private AttachmentsService: AttachmentsService,
private CameraService: CameraService,
private processesService: ProcessesService,
private storage: Storage,
@@ -150,7 +149,6 @@ 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)
+13 -1
View File
@@ -13,7 +13,11 @@ import { ThemeService } from 'src/app/services/theme.service';
import { StorageService } from 'src/app/services/storage.service';
import { PermissionService } from 'src/app/services/permission.service';
import { PermissionList } from 'src/app/models/permission/permissionList';
import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'
import { MessageModel, DeleteMessageModel } from '../../models/beast-orm';
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { Storage } from '@ionic/storage';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { ChatService } from 'src/app/services/chat.service';
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
@@ -46,6 +50,10 @@ export class LoginPage implements OnInit {
public ThemeService: ThemeService,
private storageservice: StorageService,
public p: PermissionService,
private WsChatService: WsChatService,
private storage: Storage,
public WsChatMethodsService: WsChatMethodsService,
private ChatService: ChatService
) {}
ngOnInit() {
@@ -124,6 +132,7 @@ export class LoginPage implements OnInit {
await this.authService.loginChat(attempt.ChatData.data);
await this.authService.loginToChatWs();
this.ChatService.setheader()
}
@@ -134,7 +143,9 @@ export class LoginPage implements OnInit {
} else {
this.WsChatService.logout();
this.clearStoreService.clear();
this.WsChatMethodsService.clearChat();
SessionStore.delete();
window.localStorage.clear();
await MessageModel.deleteAll()
@@ -148,6 +159,7 @@ export class LoginPage implements OnInit {
if(attempt.ChatData) {
await this.authService.loginChat(attempt.ChatData.data);
await this.authService.loginToChatWs();
this.ChatService.setheader()
}
this.getToken();
+8 -2
View File
@@ -20,7 +20,7 @@ import { RoomService } from './chat/room.service';
import { Storage } from '@ionic/storage';
import { InitialsService } from './functions/initials.service';
import { PermissionService } from './permission.service';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
@Injectable({
providedIn: 'root'
})
@@ -48,7 +48,8 @@ export class AuthService {
private AttachmentsService: AttachmentsService,
private storage: Storage,
private initialsService: InitialsService,
public p: PermissionService, ) {
public p: PermissionService,
public WsChatMethodsService: WsChatMethodsService, ) {
this.headers = new HttpHeaders();
@@ -201,6 +202,11 @@ export class AuthService {
this.WsChatService.setStatus('online')
setTimeout(() => {
this.WsChatMethodsService.getAllRooms();
}, 200);
// alert('wsLogin')
}).catch((message) => {
+31 -25
View File
@@ -1,14 +1,13 @@
import { HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AuthService } from './auth.service';
import { HttpService } from './http.service';
import { StorageService } from './storage.service';
import { HttpClient, HttpHeaderResponse } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { Storage } from '@ionic/storage';
import { PermissionService } from './permission.service';
import { SessionStore } from '../store/session.service';
import { ChangeProfileService } from 'src/app/services/change-profile.service';
@Injectable({
providedIn: 'root'
})
@@ -24,19 +23,21 @@ export class ChatService {
constructor(
private http: HttpClient,
private httpService: HttpService,
private authService: AuthService,
private storage: Storage,
private storageService: StorageService,
public p: PermissionService) {
public p: PermissionService,
private changeProfileService: ChangeProfileService,) {
this.setheader()
this.changeProfileService.registerCallback(() => {
this.setheader();
})
}
getDocumentDetails(url: string) {
let headersc = new HttpHeaders();
headersc = headersc.set('X-User-Id', this.loggedUserChat['data'].userId);
headersc = headersc.set('X-Auth-Token', this.loggedUserChat['data'].authToken);
headersc = headersc.set('X-User-Id', SessionStore.user.ChatData.data.userId);
headersc = headersc.set('X-Auth-Token', SessionStore.user.ChatData.data.authToken);
headersc = headersc.set('Sec-Fetch-Dest', 'attachment');
headersc = headersc.set('Sec-Fetch-Mode', 'navigate');
headersc = headersc.set('Cookie', 'rc_uid=fsMwcNdufWvdnChj7');
@@ -342,7 +343,6 @@ export class ChatService {
setheader() {
try {
if (this.p.userPermission(this.p.permissionList.Chat.access)) {
this.loggedUserChat = this.authService.ValidatedUserChat;
this.headers = new HttpHeaders();
if (this.p.userPermission(this.p.permissionList.Chat.access)) {
@@ -360,24 +360,30 @@ export class ChatService {
}
refreshtoken() {
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
let options = {
headers: this.headers
};
return this.http.get(environment.apiURL + 'UserAuthentication/RegenereChatToken', options).subscribe(async res => {
let data = {
status: res['status'],
data: {
userId: res['data'].userId,
authToken: res['data'].authToken
if(this.headers) {
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
let options = {
headers: this.headers
};
return this.http.get(environment.apiURL + 'UserAuthentication/RegenereChatToken', options).subscribe(async res => {
let data = {
status: res['status'],
data: {
userId: res['data'].userId,
authToken: res['data'].authToken
}
}
}
SessionStore.user.ChatData = data
SessionStore.save()
SessionStore.user.ChatData = data
SessionStore.save()
this.setheader()
// console.log(res)
// console.log(SessionStore.user.ChatData)
});
} else {
this.setheader()
// console.log(res)
// console.log(SessionStore.user.ChatData)
});
}
}
}
+2 -2
View File
@@ -77,7 +77,7 @@ export class MessageService {
this.ts = ts
this.u = u || { name: this.usernameToDisplayName(SessionStore.user.UserName), username: SessionStore.user.UserName, _id: ""}
this.t = t
this._id = _id
this._id = _id || ""
this._updatedAt = _updatedAt || new Date().getTime()
this.file = file
this.temporaryData = temporaryData
@@ -310,7 +310,7 @@ export class MessageService {
async addMessageDB() {
if(!this.addToDb) {
this.addToDb= true
this.addToDb = true
const message = this.getChatObj()
delete message.id
+77 -26
View File
@@ -39,6 +39,7 @@ export class RoomService {
name = ''
_updatedAt = {}
hasLoadHistory = false
hasLoadHistoryMessageRF = []
restoreFromOffline = false
duration = ''
isTyping = false
@@ -179,7 +180,7 @@ export class RoomService {
if(difference < 0) {
this.deleteRoom()
this.deleteRoom();
} else {
setTimeout(() => {
@@ -236,18 +237,20 @@ export class RoomService {
let IncomingChatMessageArgs = IncomingChatMessage.fields.args[0]
let ChatMessage : ChatMessageInterface = this.fix_updatedAt(IncomingChatMessageArgs)
if(!this.messagesLocalReference.includes(ChatMessage.localReference)) {
const allMessageIds = this.messages.map((e)=> e._id);
if(!this.messagesLocalReference.includes(ChatMessage.localReference) && !allMessageIds.includes(ChatMessage?._id)) {
this.messagesLocalReference.push(ChatMessage.localReference);
const message = await this.prepareCreate({message: ChatMessage, save: true})
const message = await this.prepareCreate({message: ChatMessage, save: true});
message.messageSend = true
this.lastMessage = message
this.calDateDuration(ChatMessage._updatedAt)
this.lastMessage = message;
this.calDateDuration(ChatMessage._updatedAt);
if (message.t == 'r') {
this.name = message.msg
this.name = message.msg;
}
if(this.isSenderIsNotMe(ChatMessage)) {
@@ -312,19 +315,17 @@ export class RoomService {
this.otherUserType = args[1]
this.readAllMessage()
//
// alert(JSON.stringify(args))
} else if(args[0]?.method == 'viewMessage' || args[1]?.method == 'viewMessage') {
this.readAllMessage()
} else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') {
// alert('delete')
//
this.deleteMessage(args[1]?.method?._id)
} else {
// alert('miss')
}
@@ -468,7 +469,7 @@ export class RoomService {
deleteAll() {
this.messages.forEach((message)=>{
this.messages.forEach((message) => {
if(message?._id) {
this.sendDeleteRequest(message._id)
}
@@ -477,7 +478,7 @@ export class RoomService {
async delateMessageToSendToOthers(userId) {
const deleteMessage = await DeleteMessageModel.all()
const deleteMessage = await DeleteMessageModel.all();
const toSend = deleteMessage.filter((DeleteMessage:string[])=> ! DeleteMessage.includes(userId))
@@ -493,8 +494,8 @@ export class RoomService {
this.WsChatService.deleteMessage(msgId).then(async() => {
message.delateRequest = true
await message.save()
this.deleteMessage(msgId)
await message.save();
this.deleteMessage(msgId);
})
} else {
@@ -516,7 +517,7 @@ export class RoomService {
*/
async send({file = null, attachments = null, temporaryData = {}}) {
const localReference = uuidv4()
const localReference = uuidv4();
let offlineChatMessage = {
rid: this.id,
@@ -529,9 +530,9 @@ export class RoomService {
this.message= ''
this.messagesLocalReference.push(localReference)
const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline})
this.messagesLocalReference.push(localReference)
await message.addMessageDB()
message.send()
@@ -547,7 +548,9 @@ export class RoomService {
this.sortRoomList()
}
if(this.hasLoadHistory == false) {
this.hasLoadHistoryMessageRF.push(localReference)
}
}
@@ -679,17 +682,17 @@ export class RoomService {
}
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
// console.log('load history', chatHistory)
//
const messagesId = this.messages.map((message)=> message._id)
chatHistory.result.messages.reverse().forEach(async(message: any) => {
await chatHistory.result.messages.reverse().forEach(async(message: any) => {
if (!messagesId.includes(message._id)) {
const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message});
if(messagesToSave) {
await messagesToSave.addMessageDB()
messagesToSave.addMessageDB()
}
}
@@ -703,6 +706,28 @@ export class RoomService {
}, 50)
this.hasLoadHistory = true
this.messageReorder();
}
async messageReorder() {
const reorderMessage: MessageService[] = this.messages.filter((message) =>
this.hasLoadHistoryMessageRF.includes(message?.localReference)
);
await this.messages.forEach( async (message, i) => {
if(this.hasLoadHistoryMessageRF.includes(message?.localReference)) {
this.messages.splice(i, 1)
}
})
this.hasLoadHistoryMessageRF = [];
reorderMessage.forEach((message) => {
this.messages.push(message)
});
}
@@ -714,10 +739,10 @@ export class RoomService {
await this.messages.forEach( async (message, index) => {
if(message._id) {
if(message._id) {
if(message.viewed.length == 0) {
this.messages[index].viewed = membersIds
this.messages[index].received = membersIds
this.messages[index].viewed = membersIds;
this.messages[index].received = membersIds;
await this.messages[index].save()
}
@@ -797,7 +822,33 @@ export class RoomService {
wewMessage.setData(message)
wewMessage.loadHistory = this.hasLoadHistory
this.messages.push(wewMessage)
let found;
if(wewMessage.localReference != null) {
found = this.messages.find((MessageService, index) => {
if ( MessageService.localReference == wewMessage.localReference ) {
return true
} else {
return false
}
})
} else {
found = this.messages.find((MessageService, index) => {
if ( MessageService._id == wewMessage._id) {
return true
} else {
return false
}
})
}
if (!found) {
this.messages.push(wewMessage)
return wewMessage
}
return wewMessage
}
@@ -840,7 +891,7 @@ export class RoomService {
message = this.fix_updatedAt(message)
const found = this.messages.find((MessageService, index) => {
if (MessageService._id == message._id ) {
if (MessageService._id == message._id) {
return true
} else {
return false
@@ -14,7 +14,6 @@ import { SortService } from '../functions/sort.service';
import { chatUser } from 'src/app/models/chatMethod';
import { NfService } from 'src/app/services/chat/nf.service'
import { ChangeProfileService } from '../change-profile.service';
import { AuthService } from '../auth.service';
import { ChatStorageService } from './chat-storage.service';
import { ChatMethodsService } from './chat-methods.service';
import { AESEncrypt } from '../aesencrypt.service'
@@ -41,7 +40,7 @@ export class WsChatMethodsService {
users: chatUser[] = []
sessionStore = SessionStore
loggedUser: any;
delete = []
@@ -56,7 +55,6 @@ export class WsChatMethodsService {
private NfService: NfService,
private changeProfileService: ChangeProfileService,
private chatService: ChatService,
private authService: AuthService,
private ChatStorageService: ChatStorageService,
private ChatMethodsService:ChatMethodsService,
private AESEncrypt: AESEncrypt,
@@ -64,7 +62,7 @@ export class WsChatMethodsService {
private NetworkServiceService: NetworkServiceService,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
this.loadChat()
@@ -93,13 +91,6 @@ export class WsChatMethodsService {
})
// on change profile remove a rooms
this.changeProfileService.registerCallback(() => {
this.clearChat()
this.ReLoadChat()
this.storage.remove('Rooms');
})
}
private loadChat() {
@@ -173,8 +164,10 @@ export class WsChatMethodsService {
async getAllRooms () {
this.loadingWholeList = true
const rooms = await this.WsChatService.getRooms();
try {
await this.storage.remove('Rooms');
} catch(e) {}
await this.storage.remove('Rooms');
await rooms.result.update.forEach( async (roomData: room, index) => {
const roomId = this.getRoomId(roomData);
+12 -2
View File
@@ -78,7 +78,6 @@ export class WsChatService {
//
if(message.result) {
if(message.result.token) {
this.isLogin = true
this.loginResponse = message
@@ -106,6 +105,7 @@ export class WsChatService {
getRooms(roomOlder = 1480377601) {
//const requestId = uuidv4()
const requestId = uuidv4()
const message = {
@@ -121,7 +121,6 @@ export class WsChatService {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId) { // same request send
resolve(message)
//
return true
}
}})
@@ -186,6 +185,7 @@ export class WsChatService {
logout() {
this.isLogin = false
this.ws.connected = false
this.ws.disconnect()
}
// send message to room
@@ -749,6 +749,7 @@ export class WsChatService {
const data = JSON.parse(event.data)
//
// console.log(data)
for (const [key, value] of Object.entries(this.wsCallbacks)) {
if(value.type== 'Onmessage') {
@@ -777,6 +778,15 @@ export class WsChatService {
onerror: (event: any) => {
},
disconnect:() => {
if(this.socket) {
this.socket.onopen = (event: any) => {}
this.socket.onmessage = (event: any) => {}
this.socket.onclose = (event: any) => {}
this.socket.onerror = (event: any) => {}
this.socket.close()
}
}
}}
@@ -49,8 +49,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
@ViewChild('message-item') messageContainer: ElementRef;
loggedUser: any;
messages: any;
dm: any;
userPresence = '';
@@ -126,7 +124,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
private platform: Platform,
private fileOpener: FileOpener,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
this.checkAudioPermission()
}
@@ -448,15 +445,15 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
else {
var str = msg.attachments[0].image_url;
str = str.substring(1, ((str.length) - 1));
// var str = msg.attachments[0].image_url;
// str = str.substring(1, ((str.length) - 1));
const encodedData = btoa(str);
// const encodedData = btoa(str);
let file = this.base64toBlob(encodedData, 'application/pdf')
let fileURL = URL.createObjectURL(file)
// let file = this.base64toBlob(encodedData, 'application/pdf')
// let fileURL = URL.createObjectURL(file)
window.open(fileURL);
// window.open(fileURL);
}
}