add typing

This commit is contained in:
Peter Maquiran
2022-01-28 16:15:20 +01:00
parent 66098ae4e8
commit 005efbd20b
12 changed files with 182 additions and 26 deletions
+72 -4
View File
@@ -10,6 +10,7 @@ import { Platform } from '@ionic/angular';
import { SqliteService } from 'src/app/services/sqlite.service';
import { NativeNotificationService } from 'src/app/services/native-notification.service';
import { SessionStore } from 'src/app/store/session.service';
import { capitalizeTxt } from 'src/plugin/text'
@Injectable({
providedIn: 'root'
})
@@ -27,6 +28,12 @@ export class RoomService {
_updatedAt = {}
private hasLoadHistory = false
duration = ''
isTyping = false
otherUserType = false
lastTimeType = null
message = ''
lastMessageTxt = ''
userThatIsTyping = ''
private ToastService = ToastsService
mgsArray = [];
@@ -95,10 +102,67 @@ export class RoomService {
}
)
this.WsChatService.receiveStreamNotifyRoom((message) => {
console.log(message.fields)
if(message.fields.eventName == this.id+'/'+'typing') {
this.userThatIsTyping = this.usernameToDisplayName(message.fields.args[0])
this.isTyping = message.fields.args[1]
this.otherUserType = message.fields.args[1]
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
})
}
send(msg) {
this.WsChatService.send(this.id, msg)
send() {
this.WsChatService.send(this.id, this.message)
this.message= ''
}
typing(text:string = this.message) {
if(this.lastMessageTxt == text) { return false }
this.lastTimeType = new Date().getTime()
const lastIsTyping = this.isTyping
if(text.length >= 1) {
this.isTyping = true
} else {
this.isTyping = false
}
if(lastIsTyping != this.isTyping) {
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', this.isTyping)
}
this.lastMessageTxt = this.message
this.typingWatch()
}
private typingWatch() {
setTimeout(()=>{
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)
}
} else {
console.log(now - this.lastTimeType)
}
}, 3000)
}
leave(rid?) {
@@ -324,7 +388,11 @@ export class RoomService {
}
// to add
countDownDate() { }
usernameToDisplayName(username) {
const firstName = capitalizeTxt(username.split('.')[0])
const lastName = capitalizeTxt(username.split('.')[1])
return firstName + ' ' + lastName
}
}
@@ -81,12 +81,16 @@ export class WsChatMethodsService {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log('streamRoomMessages', subscription)
})
this.WsChatService.subStreamNotifyRoom(id, 'typing', false)
}
for (const id in this.group) {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log('streamRoomMessages', subscription)
})
this.WsChatService.subStreamNotifyRoom(id, 'typing', false)
}
this.WsChatService.streamNotifyLogged().then((subscription=>{
+66
View File
@@ -231,8 +231,74 @@ export class WsChatService {
deleteMessage() {}
createRoom() {}
sendStreamNotifyRoom(roomId : string, username, event: 'typing', param: any) {
const requestId = uuidv4()
let message = {
msg: "method",
method: "stream-notify-room",
id: requestId,
params: [
`${roomId}/${event}`,
username,
param
]
};
this.ws.send({message, requestId})
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve('')
return true
}
}})
});
}
subStreamNotifyRoom(roomId : string , event: 'typing' | 'deleteMessage', param: any) {
const requestId = uuidv4()
let message = {
msg: "sub",
id: requestId,
name: "stream-notify-room",
params:[
`${roomId}/${event}`,
param
]
}
this.ws.send({message, requestId})
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId ) { // same request send
resolve('')
return true
}
}})
});
}
receiveStreamNotifyRoom(funx: Function) {
this.ws.registerCallback({
type:'Onmessage',
funx:(message)=> {
if(message.collection == "stream-notify-room" && message.msg == 'changed') {
funx(message)
}
}})
}
loadHistory(roomId, limit: number = 50) {
const requestId = uuidv4()