简体   繁体   中英

Send Message only to one chat room

I'm making web application chat room,my problem is that if there was two rooms first room called "Funny" that have only one user "liam" and the second "Happy" that have only one user "jack", now if jack send message in room "Happy" it keep reaching both rooms "Happy" and "Funny" how can i stop that and make the messages reach the room that meant to be.

private void doNotify(String author, String message, Session skip) throws IOException{    
    for (Entry<Session,ChatUser> user : chatUsers.entrySet()){
        Session session = user.getKey();
        if (!session.equals(skip) && session.isOpen()){

            session.getBasicRemote().sendText((author != null ?
                    //Message Model
                    "<li class='media'><div class='media-left'><a href='#'><img src='' class='media-object' alt='"+author
                    +"'/>" +" </a></div><div class='media-body'><h4 class='media-heading'>"+author+
                    "<small><i>"+"("+new Date()+")</i>" : "")+ 
                    "</h4><p>"+message
                    +"<br><button id='Reply' type='button' ng-click='ReplayMessage('"+author+"')'>"
                    +"Reply</button><button id='OpenBtn' type='button' ng-click=''>Open</button></br></div>");          

        }   

    }
}

Check the room of the user and store same on server. In sendText, add validation for room.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM