mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
improve
This commit is contained in:
@@ -3,6 +3,7 @@ import { Message } from 'src/app/models/chatMethod';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { capitalizeTxt } from 'src/plugin/text'
|
||||
import { NfService } from 'src/app/services/chat/nf.service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -23,9 +24,12 @@ export class MessageService {
|
||||
attachments
|
||||
offline = true
|
||||
displayType = ''
|
||||
temporaryData = {}
|
||||
temporaryData: any = {}
|
||||
hasFile = false
|
||||
hasSendAttachment = false
|
||||
|
||||
constructor(private storage: Storage) {
|
||||
constructor(private storage: Storage,
|
||||
private NfService: NfService) {
|
||||
}
|
||||
|
||||
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData}:Message) {
|
||||
@@ -49,18 +53,20 @@ export class MessageService {
|
||||
this.offline = false
|
||||
}
|
||||
|
||||
|
||||
if (this.file) {
|
||||
this.getFileFromDb()
|
||||
if(this.file.type) {
|
||||
if(this.file.type != 'application/webtrix' && typeof(this.file.type) == 'string') {
|
||||
this.displayType = this.file.type.replace('application/','').toUpperCase()
|
||||
if(typeof(this.file.type) == 'string') {
|
||||
this.hasFile = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(this.hasFile) {
|
||||
this.getFileFromDb()
|
||||
if(this.file.type != 'application/webtrix') {
|
||||
this.displayType = this.file.type.replace('application/','').toUpperCase()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private usernameToDisplayName(username) {
|
||||
@@ -71,13 +77,13 @@ export class MessageService {
|
||||
}
|
||||
|
||||
getFileFromDb() {
|
||||
if (this.file) {
|
||||
|
||||
if(this.hasFile) {
|
||||
if (this.file.guid) {
|
||||
this.storage.get(this.file.guid).then((image) => {
|
||||
if(image != null) {
|
||||
this.file.image_url = image
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageService } from './message.service';
|
||||
import { RoomService } from './room.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NfService {
|
||||
|
||||
beforeSendAttachment = (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)))
|
||||
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { SortService } from '../functions/sort.service';
|
||||
import { chatUser } from 'src/app/models/chatMethod';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
import { NfService } from 'src/app/services/chat/nf.service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -63,11 +64,12 @@ export class RoomService {
|
||||
private NativeNotificationService: NativeNotificationService,
|
||||
private sortService: SortService,
|
||||
private chatService: ChatService,
|
||||
private NfService: NfService
|
||||
) {
|
||||
this.NativeNotificationService.askForPermission()
|
||||
}
|
||||
|
||||
setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage), _updatedAt }) {
|
||||
setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage, this.NfService), _updatedAt }) {
|
||||
this.customFields = customFields
|
||||
this.id = id
|
||||
this.name = name
|
||||
@@ -232,19 +234,21 @@ export class RoomService {
|
||||
})
|
||||
} else {
|
||||
console.log('complex send')
|
||||
return {
|
||||
message: message,
|
||||
updateMessage: (update)=> {
|
||||
offlineChatMessage = Object.assign(offlineChatMessage, update)
|
||||
|
||||
const result = this.NfService.beforeSendAttachment(message, this)
|
||||
|
||||
delete message.temporaryData;
|
||||
|
||||
if(result) {
|
||||
message.hasSendAttachment = true
|
||||
|
||||
this.WsChatService.send({roomId:this.id, msg:message.msg,attachments:offlineChatMessage.attachments, file:offlineChatMessage.file}).then((data: any) => {
|
||||
console.log('send sucees', data.result)
|
||||
let ChatMessage = data.result
|
||||
this.redefinedMessage(message, ChatMessage)
|
||||
})
|
||||
|
||||
}
|
||||
this.WsChatService.send({roomId:this.id, msg:message.msg, attachments:offlineChatMessage.attachments, file:offlineChatMessage.file}).then((data: any) => {
|
||||
console.log('send sucees', data.result)
|
||||
let ChatMessage = data.result
|
||||
this.redefinedMessage(message, ChatMessage)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -398,7 +402,7 @@ export class RoomService {
|
||||
|
||||
prepareMessage(message): MessageService {
|
||||
message = this.fix_updatedAt(message)
|
||||
const wewMessage = new MessageService(this.storage)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService)
|
||||
wewMessage.setData(message)
|
||||
this.messages.push(wewMessage)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { ChatService } from 'src/app/services/chat.service';
|
||||
import { NativeNotificationService } from 'src/app/services/native-notification.service';
|
||||
import { SortService } from '../functions/sort.service';
|
||||
import { chatUser } from 'src/app/models/chatMethod';
|
||||
|
||||
import { NfService } from 'src/app/services/chat/nf.service'
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -41,7 +41,8 @@ export class WsChatMethodsService {
|
||||
private sqlservice: SqliteService,
|
||||
private NativeNotificationService: NativeNotificationService,
|
||||
private sortService: SortService,
|
||||
private ChatService: ChatService
|
||||
private ChatService: ChatService,
|
||||
private NfService: NfService
|
||||
) {
|
||||
(async()=>{
|
||||
await this.getAllRooms();
|
||||
@@ -203,7 +204,7 @@ export class WsChatMethodsService {
|
||||
prepareRoom(roomData) {
|
||||
let room:RoomService;
|
||||
|
||||
room = new RoomService(this.WsChatService, new MessageService(this.storage), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService)
|
||||
room = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService)
|
||||
|
||||
room.setData({
|
||||
customFields: roomData.customFields,
|
||||
|
||||
Reference in New Issue
Block a user