Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to notify group members after the plugin processes group messages #158

Open
weiweipang opened this issue Jul 7, 2022 · 3 comments
Open
Labels
question Further information is requested

Comments

@weiweipang
Copy link

weiweipang commented Jul 7, 2022

I have a problem with…
I created a group chat with reference to the instance of tigase-tts-ng,and send messages to groups through users1,all group members can receive messages,But I don't know how to send a message to group members after processing the message in the plugin,please give me some examples,thank you

@Test(groups = {"Multi User Chat"}, description = "#8660: Delivery presence from offline user")
public void testOfflineUserSendsMessage() throws JaxmppException, InterruptedException {
    user1Jaxmpp.getEventBus()
            .addHandler(MucModule.MucMessageReceivedHandler.MucMessageReceivedEvent.class,
                    (sessionObject, message, room, nickname, timestamp) -> {
                        try {
                            mutex.notify("recv1:" + message.getBody());
                        } catch (XMLException e) {
                            Assert.fail(e.getMessage());
                        }
                    });

    final String mid = nextRnd();
    Element msg = ElementBuilder.create("message")
            .setAttribute("type", "groupchat")
            .setAttribute("to", roomJID.toString())
            .child("body")
            .setValue("test-" + mid)
            .getElement();

    user2Jaxmpp.send(Stanza.create(msg));
    mutex.waitFor(20_000, "recv1:test-" + mid);
    assertTrue(mutex.isItemNotified("recv1:test-" + mid),
            "User1 did not received message from offline user");
}

    //Here is the code snippet to simulate a group chat
        user1Jaxmpp.getEventBus()
                .addHandler(MucModule.MucMessageReceivedHandler.MucMessageReceivedEvent.class, new MucModule.MucMessageReceivedHandler() {
                    @Override
                    public void onMucMessageReceived(SessionObject sessionObject, Message message, Room room, String s, Date date) {
                        try {
                            System.out.println("user1:"+message.getBody());
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

        user2Jaxmpp.getEventBus()
                .addHandler(MucModule.MucMessageReceivedHandler.MucMessageReceivedEvent.class, new MucModule.MucMessageReceivedHandler() {
                    @Override
                    public void onMucMessageReceived(SessionObject sessionObject, Message message, Room room, String s, Date date) {
                        try {
                            System.out.println("user2:"+message.getBody());
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
        user3Jaxmpp.getEventBus()
                .addHandler(MucModule.MucMessageReceivedHandler.MucMessageReceivedEvent.class, new MucModule.MucMessageReceivedHandler() {
                    @Override
                    public void onMucMessageReceived(SessionObject sessionObject, Message message, Room room, String s, Date date) {
                        try {
                            System.out.println("user3:"+message.getBody());
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

Details (please complete the following information):

  • Tigase version: [e.g. 8.1.0]
  • JVM flavour and version [e.g. AdoptOpenJDK11]
  • Operating system/distribution/version [e.g. Linux Ubuntu 20.04]
@weiweipang weiweipang added the question Further information is requested label Jul 7, 2022
@woj-tek
Copy link
Contributor

woj-tek commented Jul 7, 2022

Could you clarify what you are trying to achieve? What is "plugin" In your case?

You posted your question in tigase-server project yet you use jaxmpp code.

@weiweipang
Copy link
Author

weiweipang commented Jul 8, 2022

ok,I customized a tigase plugin to process messages sent by group chat member,But I don't know how to notify all group members after processing the message,Below is a custom plugin

@Id(Solitaire.XMLNS_SOLITAIRE_DATA)
@Handles({@Handle(path = {"iq", "query"}, xmlns = Solitaire.XMLNS_SOLITAIRE_DATA)})
@Bean(name = Solitaire.XMLNS_SOLITAIRE_DATA, parent = SessionManager.class, active = true)
public class Solitaire extends AnnotatedXMPPProcessor implements XMPPProcessorIfc {

public static final String XMLNS_SOLITAIRE_DATA = "test:group-chat";
private static final Logger log = Logger.getLogger(Solitaire.class.getName());

    @Override
    public void process(Packet packet, XMPPResourceConnection session, NonAuthUserRepository repo, Queue<Packet> results, 
        Map<String, Object> settings) throws XMPPException {
        if (session == null || !session.isAuthorized()) {
            return;
        }
        if (StanzaType.get != packet.getType()) {
            return;
        }
        try {
            Element query = packet.getElemChild("query");
            
            //Referring to the tigase example I know how to return the result to a single person,but I do not know how to notify 
             //group members after processing messages here
           

        } catch (Exception e) {
            LogUtils.logExeption(log, e);
           
        }
    }
 
}

@woj-tek
Copy link
Contributor

woj-tek commented Jul 8, 2022

Once again: Could you clarify what you are trying to achieve?

In general if you are in groupchat (MUC or MIX) then sending message to such groupchat channel broadcast the message to all members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants