mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
create direct message
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
||||
import { ModalController } from '@ionic/angular';
|
||||
import { GroupMessagesPage } from '../group-messages/group-messages.page';
|
||||
import { ThemeService } from 'src/app/services/theme.service'
|
||||
import { UserContacts } from 'src/app/services/Repositorys/contacts/data-source/contacts-data-source.service';
|
||||
import { ContactRepositoryService } from 'src/app/services/Repositorys/contacts/repository/contacts-repository.service';
|
||||
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
|
||||
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { MessageEnum } from 'src/app/module/chat/domain/use-case/message-create-use-case.service';
|
||||
import { MessageEntity } from 'src/app/module/chat/domain/entity/message';
|
||||
// import { ChatSystemService } from 'src/app/services/chat/chat-system.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-contacts',
|
||||
templateUrl: './contacts.page.html',
|
||||
styleUrls: ['./contacts.page.scss'],
|
||||
})
|
||||
export class ContactsPage implements OnInit {
|
||||
options:any;
|
||||
|
||||
loading = false
|
||||
userList: UserContacts[] = []
|
||||
currentMembers:UserContacts[];
|
||||
allChatUsers: UserContacts[] = [];
|
||||
userContainer: {[key: string]: ( UserContacts & {isChecked: boolean})[] } = {}
|
||||
|
||||
@Output() openMessage: EventEmitter<any> = new EventEmitter<any>();
|
||||
@Output() emptyTextDescriptionOpen: EventEmitter<any> = new EventEmitter<any>();
|
||||
@Output() backToChat: EventEmitter<any> = new EventEmitter<any>();
|
||||
@Output() closeAllDesktopComponents: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
roomId= ''
|
||||
|
||||
constructor(
|
||||
private modalController: ModalController,
|
||||
public ThemeService: ThemeService,
|
||||
private contactsRepositoryService: ContactRepositoryService,
|
||||
private httpErrorHandle: HttpErrorHandle,
|
||||
private toastService: ToastService,
|
||||
private chatServiceService: ChatServiceService
|
||||
)
|
||||
{}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadUsers();
|
||||
|
||||
}
|
||||
|
||||
async loadUsers() {
|
||||
|
||||
this.loading = true
|
||||
const getallChatUsers = await this.contactsRepositoryService.getUsers()
|
||||
|
||||
if(getallChatUsers.isOk()) {
|
||||
|
||||
this.allChatUsers = getallChatUsers.value.data.result.sort((a,b) => {
|
||||
if(a.wxFullName < b.wxFullName) {
|
||||
return -1;
|
||||
}
|
||||
if(a.wxFullName > b.wxFullName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
|
||||
for(const user of this.allChatUsers) {
|
||||
const firstLetter = user.wxFullName.charAt(0)
|
||||
|
||||
if(!this.userContainer[firstLetter]) {
|
||||
user['isChecked'] = false
|
||||
this.userContainer[firstLetter] = [user as any]
|
||||
} else {
|
||||
const userIds = this.userContainer[firstLetter].map( e => e.wxUserId)
|
||||
if(!userIds.includes(user.wxUserId)) {
|
||||
user['isChecked'] = false
|
||||
this.userContainer[firstLetter].push(user as any)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (getallChatUsers.isErr() ) {
|
||||
console.log(getallChatUsers.error)
|
||||
} else {
|
||||
this.toastService._badRequest("Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico.")
|
||||
}
|
||||
|
||||
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
separateLetter(record, recordIndex, records){
|
||||
|
||||
if(recordIndex == 0){
|
||||
return record.first[0];
|
||||
}
|
||||
|
||||
let first_prev = records[recordIndex - 1].first[0];
|
||||
let first_current = record.first[0];
|
||||
|
||||
if(first_prev != first_current){
|
||||
return first_current;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
doRefresh(event){
|
||||
|
||||
}
|
||||
close(roomId) {
|
||||
if (roomId) {
|
||||
this.backToChat.emit({ roomId: roomId });
|
||||
} else {
|
||||
this.closeAllDesktopComponents.emit();
|
||||
}
|
||||
}
|
||||
|
||||
onChange(event) {
|
||||
|
||||
}
|
||||
|
||||
clicked() {}
|
||||
|
||||
|
||||
selectOnce = true
|
||||
async select(user: UserContacts) {
|
||||
|
||||
const message = new MessageEntity();
|
||||
|
||||
message.sender = {
|
||||
userPhoto: '',
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
|
||||
message.receiverId = user.wxUserId
|
||||
message.message = 'hello'
|
||||
|
||||
const result = await this.chatServiceService.sendMessage(message, MessageEnum.Direct)
|
||||
|
||||
if(result.isOk()) {
|
||||
this.close(result.value.roomId)
|
||||
} else {
|
||||
console.log(result.error)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user