mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 13:55:51 +00:00
Merge branch 'feature/websocket' of bitbucket.org:equilibriumito/gabinete-digital into feature/websocket
This commit is contained in:
@@ -65,6 +65,7 @@ interface FirstUnread {
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
customFields:any;
|
||||
_id: string;
|
||||
rid: string;
|
||||
msg: string;
|
||||
|
||||
@@ -120,27 +120,27 @@
|
||||
<div class="item-title" [class.item-title-active]="group.value.id ==idSelected">
|
||||
<ion-label>{{group.value.name.split('-').join(' ')}}</ion-label>
|
||||
</div>
|
||||
<!-- <div class="item-date" [class.item-date-active]="group.value.id ==idSelected" *ngIf="group.value.lastMessage && !group.customFields.countDownDate">{{group.value.duration}}</div>
|
||||
<div class="item-date" [class.item-date-active]="group.value.id ==idSelected" *ngIf="group.value.customFields.countDownDate">{{countDownDate(group.value.customFields.countDownDate, group.value.id)}}</div> -->
|
||||
<div class="item-date" [class.item-date-active]="group.value.id ==idSelected" *ngIf="group.value.lastMessage && !group.value.customFields.countDownDate">{{group.value.duration}}</div>
|
||||
<div class="item-date" [class.item-date-active]="group.value.id ==idSelected" *ngIf="group.value.customFields.countDownDate">{{countDownDate(group.value.customFields.countDownDate, group.value.id)}}</div>
|
||||
</div>
|
||||
<!-- <div *ngIf="group.value.lastMessage" class="item-description d-flex align-items-center" [class.item-description-active]="group.value.id ==idSelected">
|
||||
<div class="item-message">{{group.value.lastMessage.u.name}}: {{group.lastMessage.msg}} </div>
|
||||
<div class="item-files add-ellipsis" *ngIf="group.value.lastMessage.file">
|
||||
<div *ngIf="group.value.lastMessage" class="item-description d-flex align-items-center" [class.item-description-active]="group.value.id ==idSelected">
|
||||
<div class="item-message">{{group.value.lastMessage.u.name}}: {{group.value.lastMessage.msg}} </div>
|
||||
<div class="item-files add-ellipsis" *ngIf="group.value.file">
|
||||
<fa-icon *ngIf="group.value.lastMessage.file.type != 'application/meeting'" icon="file-alt" class="file-icon" [class.set-active-item-font-to-white]="group.value.id == idSelected"></fa-icon>
|
||||
<fa-icon *ngIf="group.value.lastMessage.file.type == 'application/meeting'" icon="calendar-alt" class="file-icon" [class.set-active-item-font-to-white]="group.value.id == idSelected"></fa-icon>
|
||||
<span class="item-files-title"> {{group.value.lastMessage.file.name || group.value.lastMessage.file.subject}}</span>
|
||||
<span class="item-files-title"> {{group.value.lastMessage.file.name || group.value.file.subject}}</span>
|
||||
</div>
|
||||
<div class="item-files" *ngIf="group.value.lastMessage.attachments">
|
||||
<div class="item-files" *ngIf="group.value.attachments">
|
||||
<div *ngIf="group.value.value.lastMessage.attachments[0].image_url">
|
||||
<fa-icon icon="image" class="file-icon" [class.set-active-item-font-to-white]="group.value.id == idSelected"></fa-icon>
|
||||
<span> Fotografia</span>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ion-item-sliding>
|
||||
<ion-item-sliding *ngIf="wsChatMethodsService.loadingWholeList || wsChatMethodsService.groupCount">
|
||||
<ion-item-sliding *ngIf="wsChatMethodsService.loadingWholeList || wsChatMethodsService.groupCount < 1">
|
||||
<div *ngFor="let n of numSequence(8); let i = index;" class="item item-hover width-100 d-flex ion-no-padding ion-no-margin">
|
||||
<div class="item-icon"><ion-icon class="icon" slot="start" src="assets/icon/icons-group-chat-grey.svg"></ion-icon></div>
|
||||
<div class="item-content flex-grow-1 cursor-pointer">
|
||||
|
||||
@@ -32,7 +32,6 @@ import { ThemeService } from 'src/app/services/theme.service'
|
||||
import { DataService } from 'src/app/services/data.service';
|
||||
import { SqliteService } from 'src/app/services/sqlite.service';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { WebsocketService } from 'src/app/services/websocket.service';
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +39,6 @@ import { WebsocketService } from 'src/app/services/websocket.service';
|
||||
selector: 'app-chat',
|
||||
templateUrl: './chat.page.html',
|
||||
styleUrls: ['./chat.page.scss'],
|
||||
providers: [WebsocketService, ChatService]
|
||||
})
|
||||
export class ChatPage implements OnInit {
|
||||
|
||||
@@ -146,7 +144,7 @@ export class ChatPage implements OnInit {
|
||||
console.log("Response from Websocket server: "+msg);
|
||||
}); */
|
||||
|
||||
this.load()
|
||||
//this.load()
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -158,9 +156,9 @@ export class ChatPage implements OnInit {
|
||||
this.authService.userData$.subscribe((res: any) => {
|
||||
this.loggedUser = res;
|
||||
//console.log(this.loggedUser);
|
||||
this.load();
|
||||
//this.load();
|
||||
|
||||
this.getDirectMessagesDB();
|
||||
//this.getDirectMessagesDB();
|
||||
});
|
||||
|
||||
/* websocket functions */
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
</ion-refresher-content>
|
||||
</ion-refresher> -->
|
||||
<div (click)="handleClick()" class="messages" #scrollMe>
|
||||
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getRoom(this.roomId).massages; let last = last"
|
||||
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getDmRoom(this.roomId).massages; let last = last"
|
||||
[class.messages-list-item-wrapper-active]="msg._id == selectedMsgId" >
|
||||
<div (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}' (click)="openPreview(msg)" *ngIf="msg.msg !=''">
|
||||
<div class="title">
|
||||
|
||||
@@ -108,7 +108,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
};
|
||||
|
||||
this.wsChatMethodsService.getRoom(this.roomId).loadHistory()
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ export class LoginPage implements OnInit {
|
||||
// login to API successfully
|
||||
if (attempt) {
|
||||
|
||||
if (attempt.UserId == SessionStore.user.UserId) {
|
||||
if (attempt.UserId == SessionStore.user.UserId) {
|
||||
await this.authService.SetSession(attempt, this.userattempt);
|
||||
await this.authService.loginChat(this.userattempt);
|
||||
this.getToken();
|
||||
|
||||
@@ -8,7 +8,6 @@ import { environment } from 'src/environments/environment';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { Message } from 'src/app/models/message.model';
|
||||
import { Observable, Subject } from "rxjs/Rx";
|
||||
import { WebsocketService } from './websocket.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -31,7 +30,6 @@ export class ChatService {
|
||||
private authService: AuthService,
|
||||
private storage: Storage,
|
||||
private storageService:StorageService,
|
||||
private wsService: WebsocketService,
|
||||
)
|
||||
{
|
||||
this.loggedUserChat = authService.ValidatedUserChat;
|
||||
@@ -42,45 +40,6 @@ export class ChatService {
|
||||
headers: this.headers,
|
||||
};
|
||||
|
||||
/* console.log("CHAT SERVICE");
|
||||
|
||||
wsService.messages = <Subject<any>>this.wsService
|
||||
.connect(environment.apiWsChatUrl)
|
||||
.map((response: MessageEvent): any => {
|
||||
let data = JSON.parse(response.data);
|
||||
console.log(data);
|
||||
|
||||
if(data.msg == 'ping'){
|
||||
wsService.messages.next({msg:'pong'});
|
||||
if(!this.authService.isWsAuthenticated){
|
||||
//this.authService.loginWsChat();
|
||||
|
||||
let msg = {
|
||||
"msg": "method",
|
||||
"method": "login",
|
||||
"id":"1",
|
||||
"params":[
|
||||
{
|
||||
"user": { "username": "paulo.pinto" },
|
||||
"password": "tabteste@006"
|
||||
}
|
||||
]
|
||||
}
|
||||
wsService.messages.next(msg);
|
||||
console.log('Authenticate');
|
||||
this.authService.isWsAuthenticated = true;
|
||||
|
||||
}
|
||||
//this.authService.loginWsChat();
|
||||
}
|
||||
if(data.id == '1'){
|
||||
this.authService.wsValidatedUserChat = data;
|
||||
}
|
||||
return (JSON.stringify(data));
|
||||
});
|
||||
|
||||
console.log(wsService.messages) */;
|
||||
|
||||
}
|
||||
|
||||
getDocumentDetails(url:string){
|
||||
|
||||
@@ -7,6 +7,7 @@ import { chatHistory, ChatMessage, File } from 'src/app/models/chatMethod'
|
||||
})
|
||||
export class MessageService {
|
||||
|
||||
customFields
|
||||
channels = []
|
||||
mentions = []
|
||||
msg = ''
|
||||
@@ -20,7 +21,8 @@ export class MessageService {
|
||||
|
||||
constructor() { }
|
||||
|
||||
setData({channels, mentions, msg ,rid ,ts, u, _id, _updatedAt, file, attachments}:Message) {
|
||||
setData({customFields, channels, mentions, msg ,rid ,ts, u, _id, _updatedAt, file, attachments}:Message) {
|
||||
this.customFields = customFields
|
||||
this.channels = channels
|
||||
this.mentions = mentions
|
||||
this.msg = msg
|
||||
|
||||
@@ -14,12 +14,13 @@ export class RoomService {
|
||||
lastMessage: MessageService;
|
||||
|
||||
chatUser: ChatUserService[] = []
|
||||
customFields:any;
|
||||
id = ''
|
||||
name = ''
|
||||
_updatedAt = {}
|
||||
private hasLoadHistory = false
|
||||
duration = ''
|
||||
|
||||
|
||||
private ToastService = ToastsService
|
||||
|
||||
constructor(
|
||||
@@ -27,7 +28,8 @@ export class RoomService {
|
||||
private MessageService: MessageService,
|
||||
) {}
|
||||
|
||||
setData({id, name, lastMessage, _updatedAt}) {
|
||||
setData({customFields, id, name, lastMessage, _updatedAt}) {
|
||||
this.customFields = customFields
|
||||
this.id = id
|
||||
this.name = name
|
||||
this.lastMessage = lastMessage
|
||||
@@ -62,17 +64,17 @@ export class RoomService {
|
||||
|
||||
this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => {
|
||||
console.log('loadHistory', chatHistory)
|
||||
|
||||
|
||||
chatHistory.result.messages.reverse().forEach(message => {
|
||||
|
||||
|
||||
message = this.fix_updatedAt(message)
|
||||
const wewMessage = new MessageService()
|
||||
wewMessage.setData(message)
|
||||
this.massages.push(wewMessage)
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
this.hasLoadHistory = true
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ export class WsChatMethodsService {
|
||||
this.loadingWholeList = true
|
||||
|
||||
const rooms = await this.WsChatService.getRooms();
|
||||
|
||||
|
||||
// console.log("ROOMS" + JSON.stringify(rooms))
|
||||
|
||||
rooms.result.update.forEach((roomData: room) => {
|
||||
@@ -47,10 +47,11 @@ export class WsChatMethodsService {
|
||||
|
||||
room = new RoomService(this.WsChatService, new MessageService())
|
||||
room.setData({
|
||||
customFields: roomData.customFields,
|
||||
id: this.getRoomId(roomData),
|
||||
name: this.getRoomName(roomData),
|
||||
lastMessage: this.getRoomLastMessage(roomData),
|
||||
_updatedAt: roomData._updatedAt['$date']
|
||||
_updatedAt: new Date(roomData._updatedAt['$date'])
|
||||
})
|
||||
|
||||
room.receiveMessage()
|
||||
@@ -65,10 +66,10 @@ export class WsChatMethodsService {
|
||||
this.groupCount++
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
console.log('this.group', this.group)
|
||||
this.loadingWholeList = false
|
||||
}
|
||||
@@ -87,12 +88,16 @@ export class WsChatMethodsService {
|
||||
}
|
||||
}
|
||||
|
||||
getRoom(id): RoomService {
|
||||
getDmRoom(id): RoomService {
|
||||
try {
|
||||
return this.dm[id]
|
||||
} catch(e) {
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
getGroupRoom(id): RoomService {
|
||||
try {
|
||||
return this.group[id]
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
getRoomName(roomData: room) {
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
</ion-label>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="room.customFields.countDownDate" class="d-flex align-items-center yellow-orange pl-10">
|
||||
<!-- <div *ngIf="room.customFields.countDownDate" class="d-flex align-items-center yellow-orange pl-10">
|
||||
<i class="far fa-clock font-15" ></i>
|
||||
<ion-label class="font-15 pl-10" color="warning">{{countDownDate()}}</ion-label>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
@@ -44,7 +44,7 @@
|
||||
<ion-label>A conversa original mantêm-se como chat individual</ion-label>
|
||||
</div>
|
||||
|
||||
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of messages; let last = last">
|
||||
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getGroupRoom(roomId).massages; let last = last">
|
||||
<div class="message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45" *ngIf="msg.t != 'r' && msg.t != 'ul' && msg.t != 'ru' && msg.msg !=''" >
|
||||
<div class="message-item-options d-flex justify-content-end">
|
||||
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon>
|
||||
|
||||
@@ -22,6 +22,7 @@ import { ThemeService } from 'src/app/services/theme.service'
|
||||
import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page';
|
||||
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
|
||||
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
|
||||
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
|
||||
|
||||
/*
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
@@ -72,8 +73,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
|
||||
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
|
||||
|
||||
pdfurl = "http://www.africau.edu/images/default/sample.pdf";
|
||||
|
||||
constructor(
|
||||
private menu: MenuController,
|
||||
private modalController: ModalController,
|
||||
@@ -90,7 +89,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
private processesService: ProcessesService,
|
||||
private fileService: FileService,
|
||||
public ThemeService: ThemeService,
|
||||
private changeDetectorRef: ChangeDetectorRef
|
||||
private changeDetectorRef: ChangeDetectorRef,
|
||||
public wsChatMethodsService: WsChatMethodsService
|
||||
) {
|
||||
this.loggedUserChat = authService.ValidatedUserChat['data'];
|
||||
this.isGroupCreated = true;
|
||||
@@ -101,9 +101,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
this.getRoomInfo();
|
||||
//this.scrollToBottom();
|
||||
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
|
||||
console.log('MESSAGES'+this.wsChatMethodsService.getGroupRoom(this.roomId).massages);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
//console.log(this.wsChatMethodsService.getRoom(this.roomId).massages);
|
||||
|
||||
this.loggedUser=this.loggedUserChat;
|
||||
this.getRoomInfo();
|
||||
this.serverLongPull();
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
</ion-refresher-content>
|
||||
</ion-refresher>
|
||||
<div class="messages" #scrollMe>
|
||||
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getRoom(roomId).massages; let last = last">
|
||||
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getDmRoom(roomId).massages; let last = last">
|
||||
<div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.msg !=''">
|
||||
<div class="message-item-options d-flex justify-content-end">
|
||||
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon>
|
||||
|
||||
@@ -84,7 +84,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
}
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
this.wsChatMethodsService.getRoom(this.roomId).loadHistory()
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory()
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -214,7 +214,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
sendMessage() {
|
||||
this.wsChatMethodsService.getRoom(this.roomId).send(this.message)
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).send(this.message)
|
||||
this.message = "";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user