All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.yawenok.fcm.client.request.FcmTopicMessage Maven / Gradle / Ivy

The newest version!
package io.github.yawenok.fcm.client.request;

import com.alibaba.fastjson.annotation.JSONField;
import io.github.yawenok.fcm.client.options.FcmMessageOptions;

import java.util.List;

public class FcmTopicMessage extends FcmMessage {
    private final String to;
    private final String condition;

    public FcmTopicMessage(final FcmMessageOptions options, final String topic, final Object data, final Object notification) {
        super(options, data, notification);
        if (topic == null) {
            throw new IllegalArgumentException("topic");
        }

        this.to = "/topics/" + topic;
        this.condition = null;
    }

    public FcmTopicMessage(final FcmMessageOptions options, final List topics, final Object data, final Object notification) {
        super(options, data, notification);
        if (topics == null) {
            throw new IllegalArgumentException("topics");
        }

        StringBuffer topicsBuffer = new StringBuffer();
        for (int i = 0;;) {
            topicsBuffer.append("'" + topics.get(i) + "' in topics");
            i++;
            if (i < topics.size()) {
                topicsBuffer.append(" || ");
            } else {
                break;
            }
        }

        this.to = null;
        this.condition = topicsBuffer.toString();
    }

    @JSONField(name = "to")
    public String getTo() {
        return to;
    }

    @JSONField(name = "condition")
    public String getCondition() {
        return condition;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy