Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

i have a problem with multichat #175

Open
LucaC98 opened this issue Oct 13, 2020 · 0 comments
Open

i have a problem with multichat #175

LucaC98 opened this issue Oct 13, 2020 · 0 comments
Labels

Comments

@LucaC98
Copy link

LucaC98 commented Oct 13, 2020

When send a message 1 to 1 I haven't problem not even recover history ofchat, but if open a socket with a second user don't switched the channel and create problem sending message.
The destinatary don't recived message despite the message arrived on the socket(topic/chat).

let stompClient = this.webSocketService.connect();
stompClient.connect({}, frame => {

        // Subscribe to notification topic
        stompClient.subscribe('/topic/notification', notifications => {

            // Update notifications attribute with the recent messsage sent from the server
            this.notifications = JSON.parse(notifications.body).count;
        })

        stompClient.subscribe('/topic/chat', notifications => {
            let chat: any = {};
            console.log(notifications);
            chat = JSON.parse(notifications.body)

            // Update notifications attribute with the recent messsage sent from the server
            if (!(this.listChanneli.includes(chat.channel))) {
                let idUser = this.accountService.userValue.data.id;
                let index = 0;
                if (chat.id.indexOf(idUser) === 0) {
                    index = 1;
                }
                let array: number[]=[];
                let userId = this.accountService.userValue.data.id;
                chat.id.forEach(element=>{
                    array.push(element);
                })
                
                
                if (!this.listChannel.includes(this.channel)){
                    array=chat.id;
                if (array.includes(userId)) {
                    let element:string;
                    this.listaCanali.forEach(element => {
                      let index = element.indexOf('-');
                      let firstID : any = '';
                      for(let i = 0;i < index;i++) {
                        firstID = firstID + element[index]
                      }
                      if (userId !== Number(firstID)){
                        this.listCanaliFinale[firstID]=element;
                      }
                      let secondID : any = '';
                      for(let i = index;i < element.length;i++) {
                        secondID = secondID + element[index]
                      }
                      
                      if (userId !== Number(secondID)){
                        this.listCanaliFinale[secondID]=element;
                      }
                      
                    });
                    
                // this.service.changeListaCanaliFinale(this.listCanaliFinale);
                this.service.changeIdChannel(chat.channnel);
                this.listChannel[index] = chat.canale;
                if (chat.id.indexOf(idUser) !== -1) {
                    stompClient.subscribe('/topic/chat/' + chat.channel, notifications => {
                        if (notifications.body) {
                            this.flag = !this.flag;
                            this.service.changeMessageHistory(this.flag);
                        }
                        this.service.changeMessage(notifications.body);
                        chat = JSON.parse(notifications.body)

                        // Update notifications attribute with the recent messsage sent from the server
                        this.message= JSON.parse(notifications.body)
                        service.changeMessage(JSON.parse(notifications.body));
                
                    })
                    this.listaCanali.push(chat.channel)
                }
            }
       } }else{      
                    chat.channel= null;
                    console.log("channel exist")
        }
    })
    });
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants