This commit is contained in:
tiago.kayaya
2022-01-28 17:34:27 +01:00
parent 666a51e710
commit 202e09231b
4 changed files with 29 additions and 16 deletions
+13 -8
View File
@@ -48,7 +48,8 @@ export class RoomService {
private platform: Platform,
private sqlservice: SqliteService,
private NativeNotificationService: NativeNotificationService,
) {
private sortService: SortService,
) {
this.NativeNotificationService.askForPermission()
}
@@ -90,11 +91,11 @@ export class RoomService {
if(SessionStore.user.RochetChatUser != ChatMessage.u.username) {
this.NativeNotificationService.sendNotificationChat({
message: message.msg,
message: message.msg,
title: this.name
});
}
// save to ionic storage
this.storage.get('chatmsg' + this.id).then((messages: any) => {
const newListMessages = messages.push(ChatMessage)
@@ -110,7 +111,7 @@ export class RoomService {
this.WsChatService.receiveStreamNotifyRoom((message) => {
console.log(message.fields)
if(message.fields.eventName == this.id+'/'+'typing') {
@@ -167,7 +168,7 @@ export class RoomService {
const lastIsTyping = this.isTyping
if(text.length >= 1) {
this.isTyping = true
this.isTyping = true
} else {
this.isTyping = false
}
@@ -175,7 +176,7 @@ export class RoomService {
if(lastIsTyping != this.isTyping) {
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', this.isTyping)
}
this.lastMessageTxt = this.message
this.typingWatch()
@@ -187,7 +188,7 @@ export class RoomService {
const now = new Date().getTime()
if((now - this.lastTimeType) >= 2888) {
if(this.isTyping == true) {
this.isTyping = false
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', this.isTyping)
@@ -291,9 +292,10 @@ export class RoomService {
this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => {
console.log('loadHistory', chatHistory)
let localMessages = []
//const sortedRoomList = this.sortService.sortDate(chatHistory.result.messages, "_updatedAt.$date")
chatHistory.result.messages.reverse().forEach(message => {
message = this.fix_updatedAt(message)
@@ -304,6 +306,9 @@ export class RoomService {
this.messages = localMessages
console.log(chatHistory.result.messages);
this.storage.set('chatmsg' + this.id, chatHistory.result.messages.reverse())
@@ -45,9 +45,15 @@ export class WsChatMethodsService {
const rooms = await this.WsChatService.getRooms();
// console.log("ROOMS" + JSON.stringify(rooms))
const sortedRoomList = this.sortService.sortDate(rooms.result.update, "_updatedAt.$date")
rooms.result.update.forEach((roomData: room) => {
console.log(rooms.result.update);
console.log(sortedRoomList);
//console.log("ROOMS" + JSON.stringify(rooms))
sortedRoomList.forEach((roomData: room) => {
this.prepareRoom(roomData);
});
@@ -106,7 +112,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)
room = new RoomService(this.WsChatService, new MessageService(this.storage), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService)
room.setData({
customFields: roomData.customFields,
@@ -123,8 +129,6 @@ export class WsChatMethodsService {
let roomId = this.getRoomId(roomData)
if(this.isIndividual(roomData)) {
console.log(room);
this.dm[roomId] = room
this.dmCount++
} else {
+2 -2
View File
@@ -8,11 +8,11 @@ export class ObjectService {
constructor() { }
deepFind(obj, path) {
deepFind(obj, path):any {
var paths = path.split('.')
, current = obj
, i;
for (i = 0; i < paths.length; ++i) {
if (current[paths[i]] == undefined) {
return undefined;
+5 -1
View File
@@ -27,7 +27,11 @@ export class SortService {
sortDate(array = [], path: string) {
return array.sort( (a,b)=> {
return new Date(this.ObjectService.deepFind(b, path)).getTime() - new Date(this.ObjectService.deepFind(a, path)).getTime()
console.log("AAA"+new Date(this.ObjectService.deepFind(a, path)));
console.log("BB"+new Date(this.ObjectService.deepFind(b, path)));
//return (new Date(this.ObjectService.deepFind(a, path)) < new Date(this.ObjectService.deepFind(b, path))) ? -1 : ((new Date(this.ObjectService.deepFind(a, path)) > new Date(this.ObjectService.deepFind(b, path))) ? 1 : 0);
return new Date(this.ObjectService.deepFind(b, path)).getTime() - new Date(this.ObjectService.deepFind(a, path)).getTime();
})
}
}