need to change branch

This commit is contained in:
Peter Maquiran
2022-03-15 15:49:59 +01:00
parent 616566bf77
commit 00cf4f7eaa
10 changed files with 138 additions and 37 deletions
+1 -2
View File
@@ -30,8 +30,7 @@ export class DeleteMessageModel extends models.Model {
rid = models.CharField() rid = models.CharField()
ts = models.CharField() ts = models.CharField()
u = models.IndDbJsonField() u = models.IndDbJsonField()
_id = models.CharField({unique:true}) needToReceiveBy = models.IndDbJsonField()
receivedBy = models.IndDbJsonField()
} }
+2
View File
@@ -85,6 +85,8 @@ export interface Message {
localReference?: string, localReference?: string,
viewed: string[], viewed: string[],
received: string[], received: string[],
delate: boolean,
delateRequest: boolean
} }
+1
View File
@@ -50,4 +50,5 @@ export interface ChatMessageInterface {
export interface falseTypingMethod{ export interface falseTypingMethod{
method: 'viewMessage' | 'deleteMessage' method: 'viewMessage' | 'deleteMessage'
params: object
} }
+2 -2
View File
@@ -51,7 +51,7 @@ export class AuthService {
if (SessionStore.exist) { if (SessionStore.exist) {
this.ValidatedUser = SessionStore.user this.ValidatedUser = SessionStore.user
console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password) // console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
this.loginToChatWs() this.loginToChatWs()
} }
@@ -176,7 +176,7 @@ export class AuthService {
return true return true
} catch(e) { } catch(e) {
console.log(e) console.log('failed to upload to server', e)
return false return false
} }
+1 -1
View File
@@ -119,7 +119,7 @@ export class ChatService {
return this.http.get(environment.apiChatUrl+'im.history', opts); return this.http.get(environment.apiChatUrl+'im.history', opts);
} }
sendMessage(body:any){ sendMessage(body:any) {
let opts = { let opts = {
headers: this.headers, headers: this.headers,
} }
@@ -47,4 +47,13 @@ export class ChatMethodsService {
return this.chatService.sendMessage(body) return this.chatService.sendMessage(body)
} }
deleteMessage(body) {
return this.chatService.deleteMessage(body)
}
} }
+11 -11
View File
@@ -5,7 +5,6 @@ import { SessionStore } from 'src/app/store/session.service';
import { capitalizeTxt } from 'src/plugin/text' import { capitalizeTxt } from 'src/plugin/text'
import { NfService } from 'src/app/services/chat/nf.service' import { NfService } from 'src/app/services/chat/nf.service'
import { WsChatService } from 'src/app/services/chat/ws-chat.service'; import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { environment } from 'src/environments/environment';
import { showDateDuration } from 'src/plugin/showDateDuration'; import { showDateDuration } from 'src/plugin/showDateDuration';
import { ChatStorageService } from './chat-storage.service' import { ChatStorageService } from './chat-storage.service'
import { ChatMethodsService } from './chat-methods.service' import { ChatMethodsService } from './chat-methods.service'
@@ -52,6 +51,8 @@ export class MessageService {
addToDb = false addToDb = false
messageSend = false messageSend = false
delate = false
delateRequest = false
constructor(private storage: Storage, constructor(private storage: Storage,
private NfService: NfService, private NfService: NfService,
@@ -61,7 +62,7 @@ export class MessageService {
private AESEncrypt: AESEncrypt) { private AESEncrypt: AESEncrypt) {
} }
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = []}:Message) { setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) {
this.channels = channels || [] this.channels = channels || []
this.mentions = mentions || [] this.mentions = mentions || []
@@ -77,6 +78,8 @@ export class MessageService {
this.temporaryData = temporaryData this.temporaryData = temporaryData
this.localReference = localReference || null this.localReference = localReference || null
this.id = id this.id = id
this.delate = delate
this.delateRequest = delateRequest
this.viewed = [...new Set([...viewed,...this.viewed])]; this.viewed = [...new Set([...viewed,...this.viewed])];
this.received = [...new Set([...received,...this.received])]; this.received = [...new Set([...received,...this.received])];
@@ -231,15 +234,12 @@ export class MessageService {
this.duration = showDateDuration(date || this._updatedAt); this.duration = showDateDuration(date || this._updatedAt);
} }
private messageReceptor() {
return this.u.username != SessionStore.user.RochetChatUser async deleteFromDB() {
this.delate = true
this.save()
} }
async delete() {
const message = await MessageModel.get({_id: this._id})
await message.delete()
}
isSenderIsNotMe(ChatMessage) { isSenderIsNotMe(ChatMessage) {
return SessionStore.user.RochetChatUser != ChatMessage.u.username return SessionStore.user.RochetChatUser != ChatMessage.u.username
@@ -267,7 +267,8 @@ export class MessageService {
received: this.received, received: this.received,
localReference: this.localReference, localReference: this.localReference,
attachments: this.attachments, attachments: this.attachments,
file: this.file file: this.file,
delate: this.delate
} }
} }
@@ -278,7 +279,6 @@ export class MessageService {
delete message.id delete message.id
const createdMessage = await MessageModel.create(message) const createdMessage = await MessageModel.create(message)
console.log('done add to db')
this.id = createdMessage.id this.id = createdMessage.id
} }
+94 -14
View File
@@ -89,6 +89,9 @@ export class RoomService {
const membersIds = this.members.map((user)=> user._id) const membersIds = this.members.map((user)=> user._id)
if(membersIds.includes(userId)) { if(membersIds.includes(userId)) {
this.deleteMessageToReceive(userId)
this.messages.forEach((message, index) => { this.messages.forEach((message, index) => {
if(!message.messageOwnerById(userId)) { if(!message.messageOwnerById(userId)) {
@@ -207,6 +210,9 @@ export class RoomService {
if(message.fields.eventName == this.id+'/'+'typing') { if(message.fields.eventName == this.id+'/'+'typing') {
const args = message.fields.args const args = message.fields.args
console.log(args)
if (typeof args[0] != 'object') { if (typeof args[0] != 'object') {
this.userThatIsTyping = this.usernameToDisplayName(args[0]) this.userThatIsTyping = this.usernameToDisplayName(args[0])
console.log(this.userThatIsTyping, 'this.userThatIsTyping') console.log(this.userThatIsTyping, 'this.userThatIsTyping')
@@ -250,6 +256,48 @@ export class RoomService {
return AllMemberThatIsNotOffline return AllMemberThatIsNotOffline
} }
getAllMemberThatIsOffline(): string[] {
const membersIds = this.getRoomMembersIds()
const allChatUsers = this.getAllUsers()
const AllMemberThatIsNotOffline = []
for(let user of allChatUsers) {
if(membersIds.includes(user._id)) {
if(user.status == 'offline') {
AllMemberThatIsNotOffline.push(user._id)
}
}
}
return AllMemberThatIsNotOffline
}
async deleteMessageToReceive(userId) {
const allDeleteMessages = await DeleteMessageModel.all()
for(let message of allDeleteMessages) {
console.log('delete messages',message)
if(message.needToReceiveBy.includes(userId)) {
message.needToReceiveBy = message.needToReceiveBy.filter((e)=> e != userId)
this.sendFalseTypingReadMessage('deleteMessage',{_id:message.messageId})
console.log(message,'update::')
DeleteMessageModel.update(message)
}
}
}
async receiveMessageDelete() { async receiveMessageDelete() {
@@ -271,22 +319,25 @@ export class RoomService {
* @description delete message in the view * @description delete message in the view
* @param id message ID * @param id message ID
*/ */
deleteMessage(id) { async deleteMessage(id) {
this.messages.forEach((message, index) => { await this.messages.forEach(async(message, index) => {
if(message._id == id) { if(message._id == id) {
this.messages.splice(index, 1) this.messages.splice(index, 1)
const allMemberThatIsNotOffline = this.getAllMemberThatIsNotOffline() const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
message.delete() message.deleteFromDB()
DeleteMessageModel.create({ await DeleteMessageModel.create({
messageId: message._id, messageId: message._id,
rid: message.rid, rid: message.rid,
ts: message.ts, ts: message.ts,
u: message.u, u: message.u,
receivedBy: allMemberThatIsNotOffline needToReceiveBy: allMemberThatIsOffline
}) })
const DBmessage = await MessageModel.get({_id: message._id})
DBmessage.delete()
//Get previous last message from room //Get previous last message from room
const previousLastMessage = this.messages.slice(-1)[0]; const previousLastMessage = this.messages.slice(-1)[0];
@@ -299,7 +350,7 @@ export class RoomService {
} }
async delateMessageToSend(userId) { async delateMessageToSendToOthers(userId) {
const deleteMessage = await DeleteMessageModel.all() const deleteMessage = await DeleteMessageModel.all()
@@ -309,6 +360,31 @@ export class RoomService {
} }
async sendDeleteRequest(msgId) {
const message = this.messages.find((e)=>e._id = msgId)
message.deleteFromDB()
this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe(
(response: any) => {
console.log(response)
message.delateRequest = true
message.save()
},
(error) => {
this.WsChatService.registerCallback({
type: 'reConnect',
funx: async ()=> {
this.sendDeleteRequest(msgId)
return true
}
})
}
)
}
/** /**
* @description sen text message * @description sen text message
@@ -330,8 +406,6 @@ export class RoomService {
const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline}) const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline})
console.log(message, 'message')
this.messagesLocalReference.push(localReference) this.messagesLocalReference.push(localReference)
await message.addMessageDB() await message.addMessageDB()
message.send() message.send()
@@ -374,8 +448,8 @@ export class RoomService {
this.typingWatch() this.typingWatch()
} }
sendFalseTypingReadMessage() { sendFalseTypingReadMessage(method,param: object) {
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', {method:'viewMessage'} as falseTypingMethod) this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', {method:method, params: param} as falseTypingMethod)
this.setTypingOff() this.setTypingOff()
} }
@@ -434,8 +508,13 @@ export class RoomService {
if(wewMessage.offline == false) { if(wewMessage.offline == false) {
const message = await this.prepareMessageCreateIfNotExist({message:ChatMessage}) const message = await this.prepareMessageCreateIfNotExist({message:ChatMessage})
message?.decryptMessage() message?.decryptMessage()
} else if(wewMessage.delate && wewMessage.offline && !wewMessage.delateRequest) {
console.log('offline delete message')
wewMessage.deleteFromDB()
this.sendDeleteRequest(wewMessage._id)
} else { } else {
const offlineMessage = await this.prepareMessageCreateIfNotExist({message:ChatMessage}) const offlineMessage = await this.prepareMessageCreateIfNotExist({message:ChatMessage})
@@ -488,6 +567,8 @@ export class RoomService {
}) })
console.log('load chatHistory', chatHistory)
}) })
@@ -505,7 +586,6 @@ export class RoomService {
const membersIds = this.members.map((user)=> user._id) const membersIds = this.members.map((user)=> user._id)
console.log('read all ===========')
await this.messages.forEach( async (message, index) => { await this.messages.forEach( async (message, index) => {
if(message._id) { if(message._id) {
@@ -670,7 +750,7 @@ export class RoomService {
sendReadMessage() { sendReadMessage() {
this.WsChatService.readMessage(this.id) this.WsChatService.readMessage(this.id)
this.sendFalseTypingReadMessage() this.sendFalseTypingReadMessage('viewMessage', {})
} }
} }
@@ -45,15 +45,18 @@
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"> <fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">
</fa-icon> </fa-icon>
<mat-menu #beforeMenu="matMenu" xPosition="before"> <mat-menu #beforeMenu="matMenu" xPosition="before">
<button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button> <button (click)="deleteMessage(msg._id, msg)" class="menuButton">Apagar mensagem</button>
</mat-menu> </mat-menu>
</div> </div>
<div class="title"> <div class="title">
<ion-label>{{msg.u.name}} </ion-label> <ion-label>{{msg.u.name}}</ion-label>
<span class="time">{{msg.duration}}</span> <span class="time">{{msg.duration}}</span>
</div> </div>
<div class="d-flex justify-space-between"> <div class="d-flex justify-space-between">
<ion-label class="flex-0">{{msg.msg}} </ion-label>
<ion-label *ngIf="msg.delate == false" class="flex-0">{{msg.msg}}</ion-label>
<ion-label *ngIf="msg.delate == true" class="flex-0">Apagou a mensagem</ion-label>
<ion-label class="float-status-all float-status" > <ion-label class="float-status-all float-status" >
<ion-icon *ngIf="msg.messageSend == false" src="assets/images/clock-regular.svg"></ion-icon> <ion-icon *ngIf="msg.messageSend == false" src="assets/images/clock-regular.svg"></ion-icon>
@@ -72,7 +75,7 @@
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"> <fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">
</fa-icon> </fa-icon>
<mat-menu #beforeMenu="matMenu" xPosition="before"> <mat-menu #beforeMenu="matMenu" xPosition="before">
<button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button> <button (click)="deleteMessage(msg._id, msg)" class="menuButton">Apagar mensagem</button>
</mat-menu> </mat-menu>
</div> </div>
<div class="title"> <div class="title">
+10 -3
View File
@@ -249,9 +249,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.wsChatMethodsService.getDmRoom(this.roomId).send({}) this.wsChatMethodsService.getDmRoom(this.roomId).send({})
} }
deleteMessage(msgId: string) { deleteMessage(msgId: string, msg:MessageService) {
const room = this.wsChatMethodsService.getDmRoom(this.roomId)
this.alertService.confirmDeleteMessage(msgId, room); msg.deleteFromDB()
this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId)
} }
async viewDocument(msg: any, url?: string) { async viewDocument(msg: any, url?: string) {
@@ -759,9 +761,14 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
ts: msg.attachments[0].ts ts: msg.attachments[0].ts
} }
msg.save()
// msg.attachments[0].image_url = 'sdfsdf'
await this.storage.set(msg.file.guid, this.downloadFile).then(() => { await this.storage.set(msg.file.guid, this.downloadFile).then(() => {
console.log('IMAGE SAVED') console.log('IMAGE SAVED')
}); });
} }
}); });