mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
need to change branch
This commit is contained in:
@@ -30,8 +30,7 @@ export class DeleteMessageModel extends models.Model {
|
||||
rid = models.CharField()
|
||||
ts = models.CharField()
|
||||
u = models.IndDbJsonField()
|
||||
_id = models.CharField({unique:true})
|
||||
receivedBy = models.IndDbJsonField()
|
||||
needToReceiveBy = models.IndDbJsonField()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,8 @@ export interface Message {
|
||||
localReference?: string,
|
||||
viewed: string[],
|
||||
received: string[],
|
||||
delate: boolean,
|
||||
delateRequest: boolean
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,4 +50,5 @@ export interface ChatMessageInterface {
|
||||
|
||||
export interface falseTypingMethod{
|
||||
method: 'viewMessage' | 'deleteMessage'
|
||||
params: object
|
||||
}
|
||||
@@ -51,7 +51,7 @@ export class AuthService {
|
||||
if (SessionStore.exist) {
|
||||
this.ValidatedUser = SessionStore.user
|
||||
|
||||
console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
|
||||
// console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
|
||||
this.loginToChatWs()
|
||||
|
||||
}
|
||||
@@ -176,7 +176,7 @@ export class AuthService {
|
||||
|
||||
return true
|
||||
} catch(e) {
|
||||
console.log(e)
|
||||
console.log('failed to upload to server', e)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ export class ChatService {
|
||||
return this.http.get(environment.apiChatUrl+'im.history', opts);
|
||||
}
|
||||
|
||||
sendMessage(body:any){
|
||||
sendMessage(body:any) {
|
||||
let opts = {
|
||||
headers: this.headers,
|
||||
}
|
||||
|
||||
@@ -46,5 +46,14 @@ export class ChatMethodsService {
|
||||
|
||||
return this.chatService.sendMessage(body)
|
||||
}
|
||||
|
||||
|
||||
deleteMessage(body) {
|
||||
return this.chatService.deleteMessage(body)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import { SessionStore } from 'src/app/store/session.service';
|
||||
import { capitalizeTxt } from 'src/plugin/text'
|
||||
import { NfService } from 'src/app/services/chat/nf.service'
|
||||
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { showDateDuration } from 'src/plugin/showDateDuration';
|
||||
import { ChatStorageService } from './chat-storage.service'
|
||||
import { ChatMethodsService } from './chat-methods.service'
|
||||
@@ -52,6 +51,8 @@ export class MessageService {
|
||||
addToDb = false
|
||||
|
||||
messageSend = false
|
||||
delate = false
|
||||
delateRequest = false
|
||||
|
||||
constructor(private storage: Storage,
|
||||
private NfService: NfService,
|
||||
@@ -61,7 +62,7 @@ export class MessageService {
|
||||
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.mentions = mentions || []
|
||||
@@ -77,6 +78,8 @@ export class MessageService {
|
||||
this.temporaryData = temporaryData
|
||||
this.localReference = localReference || null
|
||||
this.id = id
|
||||
this.delate = delate
|
||||
this.delateRequest = delateRequest
|
||||
|
||||
this.viewed = [...new Set([...viewed,...this.viewed])];
|
||||
this.received = [...new Set([...received,...this.received])];
|
||||
@@ -231,15 +234,12 @@ export class MessageService {
|
||||
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) {
|
||||
return SessionStore.user.RochetChatUser != ChatMessage.u.username
|
||||
@@ -267,7 +267,8 @@ export class MessageService {
|
||||
received: this.received,
|
||||
localReference: this.localReference,
|
||||
attachments: this.attachments,
|
||||
file: this.file
|
||||
file: this.file,
|
||||
delate: this.delate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +279,6 @@ export class MessageService {
|
||||
|
||||
delete message.id
|
||||
const createdMessage = await MessageModel.create(message)
|
||||
console.log('done add to db')
|
||||
|
||||
this.id = createdMessage.id
|
||||
}
|
||||
|
||||
@@ -89,6 +89,9 @@ export class RoomService {
|
||||
const membersIds = this.members.map((user)=> user._id)
|
||||
|
||||
if(membersIds.includes(userId)) {
|
||||
|
||||
this.deleteMessageToReceive(userId)
|
||||
|
||||
this.messages.forEach((message, index) => {
|
||||
if(!message.messageOwnerById(userId)) {
|
||||
|
||||
@@ -207,6 +210,9 @@ export class RoomService {
|
||||
if(message.fields.eventName == this.id+'/'+'typing') {
|
||||
|
||||
const args = message.fields.args
|
||||
|
||||
console.log(args)
|
||||
|
||||
if (typeof args[0] != 'object') {
|
||||
this.userThatIsTyping = this.usernameToDisplayName(args[0])
|
||||
console.log(this.userThatIsTyping, 'this.userThatIsTyping')
|
||||
@@ -250,6 +256,48 @@ export class RoomService {
|
||||
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() {
|
||||
|
||||
@@ -271,22 +319,25 @@ export class RoomService {
|
||||
* @description delete message in the view
|
||||
* @param id message ID
|
||||
*/
|
||||
deleteMessage(id) {
|
||||
this.messages.forEach((message, index) => {
|
||||
async deleteMessage(id) {
|
||||
await this.messages.forEach(async(message, index) => {
|
||||
if(message._id == id) {
|
||||
|
||||
this.messages.splice(index, 1)
|
||||
const allMemberThatIsNotOffline = this.getAllMemberThatIsNotOffline()
|
||||
message.delete()
|
||||
const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
|
||||
message.deleteFromDB()
|
||||
|
||||
DeleteMessageModel.create({
|
||||
await DeleteMessageModel.create({
|
||||
messageId: message._id,
|
||||
rid: message.rid,
|
||||
ts: message.ts,
|
||||
u: message.u,
|
||||
receivedBy: allMemberThatIsNotOffline
|
||||
needToReceiveBy: allMemberThatIsOffline
|
||||
})
|
||||
|
||||
const DBmessage = await MessageModel.get({_id: message._id})
|
||||
DBmessage.delete()
|
||||
|
||||
//Get previous last message from room
|
||||
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()
|
||||
|
||||
@@ -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
|
||||
@@ -329,8 +405,6 @@ export class RoomService {
|
||||
this.message= ''
|
||||
|
||||
const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline})
|
||||
|
||||
console.log(message, 'message')
|
||||
|
||||
this.messagesLocalReference.push(localReference)
|
||||
await message.addMessageDB()
|
||||
@@ -374,8 +448,8 @@ export class RoomService {
|
||||
this.typingWatch()
|
||||
}
|
||||
|
||||
sendFalseTypingReadMessage() {
|
||||
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', {method:'viewMessage'} as falseTypingMethod)
|
||||
sendFalseTypingReadMessage(method,param: object) {
|
||||
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', {method:method, params: param} as falseTypingMethod)
|
||||
this.setTypingOff()
|
||||
}
|
||||
|
||||
@@ -434,8 +508,13 @@ export class RoomService {
|
||||
if(wewMessage.offline == false) {
|
||||
const message = await this.prepareMessageCreateIfNotExist({message:ChatMessage})
|
||||
|
||||
|
||||
message?.decryptMessage()
|
||||
} else if(wewMessage.delate && wewMessage.offline && !wewMessage.delateRequest) {
|
||||
|
||||
console.log('offline delete message')
|
||||
|
||||
wewMessage.deleteFromDB()
|
||||
this.sendDeleteRequest(wewMessage._id)
|
||||
} else {
|
||||
|
||||
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)
|
||||
|
||||
console.log('read all ===========')
|
||||
|
||||
await this.messages.forEach( async (message, index) => {
|
||||
if(message._id) {
|
||||
@@ -670,7 +750,7 @@ export class RoomService {
|
||||
|
||||
sendReadMessage() {
|
||||
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>
|
||||
<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>
|
||||
</div>
|
||||
<div class="title">
|
||||
<ion-label>{{msg.u.name}} </ion-label>
|
||||
<ion-label>{{msg.u.name}}</ion-label>
|
||||
<span class="time">{{msg.duration}}</span>
|
||||
</div>
|
||||
<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-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>
|
||||
<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>
|
||||
</div>
|
||||
<div class="title">
|
||||
|
||||
@@ -249,9 +249,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
|
||||
}
|
||||
|
||||
deleteMessage(msgId: string) {
|
||||
const room = this.wsChatMethodsService.getDmRoom(this.roomId)
|
||||
this.alertService.confirmDeleteMessage(msgId, room);
|
||||
deleteMessage(msgId: string, msg:MessageService) {
|
||||
|
||||
msg.deleteFromDB()
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId)
|
||||
|
||||
}
|
||||
|
||||
async viewDocument(msg: any, url?: string) {
|
||||
@@ -759,9 +761,14 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
ts: msg.attachments[0].ts
|
||||
}
|
||||
|
||||
msg.save()
|
||||
|
||||
// msg.attachments[0].image_url = 'sdfsdf'
|
||||
|
||||
await this.storage.set(msg.file.guid, this.downloadFile).then(() => {
|
||||
console.log('IMAGE SAVED')
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user