This commit is contained in:
Peter Maquiran
2022-09-29 16:43:32 +01:00
parent 8c729e900d
commit a5521585c7
6 changed files with 23 additions and 28 deletions
+1
View File
@@ -72,6 +72,7 @@ export interface Message {
msg: string; msg: string;
ts: Ts; ts: Ts;
u: U; u: U;
from: 'Offline'|'History'|'stream'| 'send'
t: string; t: string;
_updatedAt: ''; _updatedAt: '';
mentions: any[]; mentions: any[];
@@ -136,7 +136,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
ngOnInit() { ngOnInit() {
this.chatService.refreshtoken();
this.loggedUser = this.loggedUserChat; this.loggedUser = this.loggedUserChat;
this.getRoomInfo(); this.getRoomInfo();
+2 -1
View File
@@ -47,6 +47,7 @@ export class MessageService {
uploadingFile = false uploadingFile = false
errorUploadingAttachment = false errorUploadingAttachment = false
loadHistory = false loadHistory = false
from: 'Offline'|'History'|'stream'| 'send'
duration = '' duration = ''
localReference = null localReference = null
viewed = [] viewed = []
@@ -71,7 +72,7 @@ export class MessageService {
private NetworkServiceService: NetworkServiceService) { private NetworkServiceService: NetworkServiceService) {
} }
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) { setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, from }:Message) {
this.channels = channels || [] this.channels = channels || []
this.mentions = mentions || [] this.mentions = mentions || []
+17 -21
View File
@@ -39,7 +39,6 @@ export class RoomService {
name = '' name = ''
_updatedAt = {} _updatedAt = {}
hasLoadHistory = false hasLoadHistory = false
hasLoadHistoryMessageRF = []
restoreFromOffline = false restoreFromOffline = false
duration = '' duration = ''
isTyping = false isTyping = false
@@ -48,7 +47,6 @@ export class RoomService {
message = '' message = ''
lastMessageTxt = '' lastMessageTxt = ''
userThatIsTyping = '' userThatIsTyping = ''
mgsArray = [];
messagesLocalReference = [] messagesLocalReference = []
members = [] members = []
u u
@@ -276,6 +274,8 @@ export class RoomService {
const message = await this.prepareCreate({message: ChatMessage, save: true}); const message = await this.prepareCreate({message: ChatMessage, save: true});
message.messageSend = true message.messageSend = true
message.from = 'stream'
message.loadHistory = this.hasLoadHistory
this.lastMessage = message; this.lastMessage = message;
this.calDateDuration(ChatMessage._updatedAt); this.calDateDuration(ChatMessage._updatedAt);
@@ -291,8 +291,9 @@ export class RoomService {
}); });
} }
message.addMessageDB() if(this.hasLoadHistory == true) {
await message.addMessageDB()
}
if(this.chatOpen == false) { if(this.chatOpen == false) {
this.messageUnread = true this.messageUnread = true
@@ -574,6 +575,8 @@ export class RoomService {
} }
message.send() message.send()
message.from = 'send'
message.loadHistory = this.hasLoadHistory
if (environment.chatOffline) { if (environment.chatOffline) {
@@ -586,10 +589,6 @@ export class RoomService {
this.calDateDuration(message._updatedAt) this.calDateDuration(message._updatedAt)
this.sortRoomList() this.sortRoomList()
} }
if(this.hasLoadHistory == false) {
this.hasLoadHistoryMessageRF.push(localReference)
}
} }
@@ -671,14 +670,21 @@ export class RoomService {
for (let ChatMessage of messages) { for (let ChatMessage of messages) {
const wewMessage = await this.simplePrepareMessage(ChatMessage) const wewMessage = await this.simplePrepareMessage(ChatMessage)
wewMessage.from = 'Offline'
wewMessage.loadHistory = this.hasLoadHistory
if(wewMessage.offline == false) { if(wewMessage.offline == false) {
const message = await this.prepareMessageCreateIfNotExist_iD({message:ChatMessage}) const message = await this.prepareMessageCreateIfNotExist_iD({message:ChatMessage})
message.from = 'Offline'
message.loadHistory = this.hasLoadHistory
message?.decryptMessage() message?.decryptMessage()
} else { } else {
const offlineMessage = await this.prepareMessageCreateIfNotExist({message:ChatMessage}) const offlineMessage = await this.prepareMessageCreateIfNotExist({message:ChatMessage})
offlineMessage.from = 'Offline'
offlineMessage.loadHistory = this.hasLoadHistory
if(offlineMessage) { if(offlineMessage) {
this.messagesLocalReference.push(offlineMessage.localReference) this.messagesLocalReference.push(offlineMessage.localReference)
@@ -745,13 +751,13 @@ export class RoomService {
async messageReorder() { async messageReorder() {
const reorderMessage: MessageService[] = this.messages.filter((message) => const reorderMessage: MessageService[] = this.messages.filter((message) =>
this.hasLoadHistoryMessageRF.includes(message?.localReference) message.from == 'send' && !message.loadHistory || message.from == 'stream' && !message.loadHistory
); );
let i = 0 let i = 0
for(let message of this.messages) { for(let message of this.messages) {
if(this.hasLoadHistoryMessageRF.includes(message?.localReference)) { if(message.from == 'send' && !message.loadHistory || message.from == 'stream' && !message.loadHistory) {
this.messages.splice(i, 1) this.messages.splice(i, 1)
} }
i++; i++;
@@ -759,19 +765,9 @@ export class RoomService {
for(let message of reorderMessage) { for(let message of reorderMessage) {
this.messages.push(message) this.messages.push(message)
message.addMessageDB()
} }
for(let message of this.messages) {
if(this.hasLoadHistoryMessageRF.includes(message?.localReference)) {
if(!message.addToDb) {
message.addMessageDB()
}
}
}
this.hasLoadHistoryMessageRF = [];
} }
@@ -143,8 +143,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
this.chatService.refreshtoken();
this.getRoomInfo(); this.getRoomInfo();
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({}); this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({});
// //
@@ -130,10 +130,9 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
this.chatService.refreshtoken();
this.wsChatMethodsService.getAllRooms(); this.wsChatMethodsService.getAllRooms();
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({}) // this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({})
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked