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
+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')