This commit is contained in:
Peter Maquiran
2022-03-28 16:37:32 +01:00
parent 18797a43ff
commit 2fab7e01d5
5 changed files with 36 additions and 33 deletions
+4 -6
View File
@@ -12,12 +12,12 @@ export class MessageModel extends models.Model {
rid = models.CharField() rid = models.CharField()
ts = JsonField({blank:true}) ts = JsonField({blank:true})
u = JsonField() u = JsonField()
_id = models.CharField({unique:true, blank:true}) _id = models.CharField({blank:true})
_updatedAt = models.IntegerField() _updatedAt = models.IntegerField()
messageSend = models.BooleanField() messageSend = models.BooleanField()
offline = models.BooleanField() offline = models.BooleanField()
viewed = ArrayField() viewed = ArrayField({blank:true})
received = ArrayField() received = ArrayField({blank:true})
localReference = models.CharField({blank:true}) localReference = models.CharField({blank:true})
attachments = ArrayField({blank:true}) attachments = ArrayField({blank:true})
file = JsonField({blank:true}) file = JsonField({blank:true})
@@ -28,10 +28,8 @@ export class DeleteMessageModel extends models.Model {
messageId = models.CharField() messageId = models.CharField()
rid = models.CharField() rid = models.CharField()
ts = JsonField()
u = JsonField() u = JsonField()
needToReceiveBy = ArrayField() needToReceiveBy = ArrayField()
} }
@@ -39,6 +37,6 @@ export class DeleteMessageModel extends models.Model {
models.register({ models.register({
databaseName: 'chat-storage', databaseName: 'chat-storage',
type: 'indexedDB', type: 'indexedDB',
version: 1, version: 4,
models: [MessageModel, DeleteMessageModel] models: [MessageModel, DeleteMessageModel]
}) })
-3
View File
@@ -222,7 +222,6 @@ export class MessageService {
if (event.type === HttpEventType.DownloadProgress) { if (event.type === HttpEventType.DownloadProgress) {
console.log('FILE TYPE 33', this.file.type)
} else if (event.type === HttpEventType.Response) { } else if (event.type === HttpEventType.Response) {
if (this.file.type == "application/img") { if (this.file.type == "application/img") {
downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
@@ -242,7 +241,6 @@ export class MessageService {
ts: this.attachments[0].ts ts: this.attachments[0].ts
} }
console.log(this.attachments)
// save the changes to the storage // save the changes to the storage
this.save() this.save()
} }
@@ -262,7 +260,6 @@ export class MessageService {
async delateDB() { async delateDB() {
// alert('delete data')
const message = await MessageModel.get({_id: this._id}) const message = await MessageModel.get({_id: this._id})
await message.delete() await message.delete()
+18 -17
View File
@@ -394,13 +394,13 @@ export class RoomService {
this.messages[i]?.delateDB() this.messages[i]?.delateDB()
console.log(_id,'==',this.messages[i]?._id, true) // console.log(_id,'==',this.messages[i]?._id, true)
this.messages.splice(i, 1) this.messages.splice(i, 1)
return true return true
} else { } else {
console.log(_id,'==',this.messages[i]?._id, false) // console.log(_id,'==',this.messages[i]?._id, false)
} }
} }
@@ -430,19 +430,20 @@ export class RoomService {
await message.delateStatusFalse() await message.delateStatusFalse()
this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe( this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe(
(response: any) => { async (response: any) => {
message.delateRequest = true message.delateRequest = true
message.save() await message.save()
this.deleteMessage(msgId) this.deleteMessage(msgId)
}, },
(response) => { async (response) => {
if (response.error.error.startsWith('No message found with the id of')) { if (response.error.error.startsWith('No message found with the id of')) {
this.deleteMessage(msgId) this.deleteMessage(msgId)
message.delateRequest = true message.delateRequest = true
await message.save()
} else { } else {
this.WsChatService.registerCallback({ this.WsChatService.registerCallback({
@@ -626,25 +627,25 @@ export class RoomService {
await this.restoreMessageFromDB() await this.restoreMessageFromDB()
} }
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { // await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
console.log('load chatHistory', JSON.stringify(chatHistory)) // console.log('load chatHistory', JSON.stringify(chatHistory))
const messagesId = this.messages.map((message)=> message._id) // const messagesId = this.messages.map((message)=> message._id)
chatHistory.result.messages.reverse().forEach(async(message: any) => { // chatHistory.result.messages.reverse().forEach(async(message: any) => {
if (!messagesId.includes(message._id)) { // if (!messagesId.includes(message._id)) {
const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message}); // const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message});
if(messagesToSave) { // if(messagesToSave) {
await messagesToSave.addMessageDB() // await messagesToSave.addMessageDB()
} // }
} // }
}) // })
}) // })
setTimeout(() => { setTimeout(() => {
this.scrollDown() this.scrollDown()
@@ -160,7 +160,10 @@ export class WsChatMethodsService {
} catch(e){} } catch(e){}
setTimeout(()=>{
this.sortRoomList() this.sortRoomList()
}, 1000)
} }
async getAllRooms () { async getAllRooms () {
@@ -204,7 +207,11 @@ export class WsChatMethodsService {
console.log('save rooms', rooms) console.log('save rooms', rooms)
await this.storage.set('Rooms', rooms); await this.storage.set('Rooms', rooms);
setTimeout(()=>{
this.sortRoomList() this.sortRoomList()
}, 1000)
this.loadingWholeList = false this.loadingWholeList = false
} }
+5 -5
View File
@@ -4,12 +4,12 @@
export const environment = { export const environment = {
production: false, production: false,
apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', //apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/',
// apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/', apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/',
apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/', //apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/',
apiWsChatUrl: 'wss://gabinetedigitalchat.dyndns.info/websocket', apiWsChatUrl: 'wss://gabinetedigitalchat.dyndns.info/websocket',
//apiChatUrl: 'https://www.tabularium.pt/api/v1/', apiChatUrl: 'https://www.tabularium.pt/api/v1/',
/* apiChatUrl: 'http://chat.gabinetedigital.local:3000/api/v1/', */ //apiChatUrl: 'http://chat.gabinetedigital.local:3000/api/v1/',
domain: 'gabinetedigital.local', //gabinetedigital.local domain: 'gabinetedigital.local', //gabinetedigital.local
defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local
defaultuserpwd: 'tabteste@006', //tabteste@006, defaultuserpwd: 'tabteste@006', //tabteste@006,