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

com.github.jamesnetherton.zulip.client.api.message.request.EditMessageApiRequest Maven / Gradle / Ivy

The newest version!
package com.github.jamesnetherton.zulip.client.api.message.request;

import static com.github.jamesnetherton.zulip.client.api.message.request.MessageRequestConstants.MESSAGES_ID_API_PATH;

import com.github.jamesnetherton.zulip.client.api.core.VoidExecutableApiRequest;
import com.github.jamesnetherton.zulip.client.api.core.ZulipApiRequest;
import com.github.jamesnetherton.zulip.client.api.core.ZulipApiResponse;
import com.github.jamesnetherton.zulip.client.api.message.PropagateMode;
import com.github.jamesnetherton.zulip.client.exception.ZulipClientException;
import com.github.jamesnetherton.zulip.client.http.ZulipHttpClient;

/**
 * Zulip API request builder for editing a message.
 *
 * @see https://zulip.com/api/update-message
 */
public class EditMessageApiRequest extends ZulipApiRequest implements VoidExecutableApiRequest {

    public static final String CONTENT = "content";
    public static final String PROPAGATE_MODE = "propagate_mode";
    public static final String SEND_NOTIFICATION_TO_OLD_THREAD = "send_notification_to_old_thread";
    public static final String SEND_NOTIFICATION_TO_NEW_THREAD = "send_notification_to_new_thread";
    public static final String STREAM_ID = "stream_id";
    public static final String TOPIC = "topic";

    private final long messageId;

    /**
     * Constructs a {@link EditMessageApiRequest}.
     *
     * @param client    The Zulip HTTP client
     * @param messageId The id of the message to edit
     */
    public EditMessageApiRequest(ZulipHttpClient client, long messageId) {
        super(client);
        this.messageId = messageId;
    }

    /**
     * Sets the optional edited message content.
     *
     * @see            https://zulip.com/api/update-message#parameter-content
     *
     * @param  content The modified message content
     * @return         This {@link EditMessageApiRequest} instance
     */
    public EditMessageApiRequest withContent(String content) {
        putParam(CONTENT, content);
        return this;
    }

    /**
     * Sets the optional propagation mode. Controls which messages(s) should be deleted.
     *
     * @see         https://zulip.com/api/update-message#parameter-propagate_mode
     *
     * @param  mode The propagation mode to use
     * @return      This {@link EditMessageApiRequest} instance
     */
    public EditMessageApiRequest withPropagateMode(PropagateMode mode) {
        putParam(PROPAGATE_MODE, mode.toString());
        return this;
    }

    /**
     * Sets the optional flag for whether to send a message to the old thread to
     * notify users where the message has moved to.
     *
     * @see         https://zulip.com/api/update-message#parameter-send_notification_to_old_thread
     *
     * @param  send {@code true} to send message notifications to the old thread. {@code false} to not send any notification
     * @return      This {@link EditMessageApiRequest} instance
     */
    public EditMessageApiRequest withSendNotificationToOldThread(boolean send) {
        putParam(SEND_NOTIFICATION_TO_OLD_THREAD, send);
        return this;
    }

    /**
     * Sets the optional flag for whether to send a message to the new thread to
     * notify users where the message came from.
     *
     * @see         https://zulip.com/api/update-message#parameter-send_notification_to_new_thread
     *
     * @param  send {@code true} to send message notifications to the new thread. {@code false} to not send any notification
     * @return      This {@link EditMessageApiRequest} instance
     */
    public EditMessageApiRequest withSendNotificationToNewThread(boolean send) {
        putParam(SEND_NOTIFICATION_TO_NEW_THREAD, send);
        return this;
    }

    /**
     * Sets the optional id of the stream to move the message to.
     *
     * @see             https://zulip.com/api/update-message#parameter-send_notification_to_new_thread
     *
     * @param  streamId The id of the stream to which the message should be moved to
     * @return          This {@link EditMessageApiRequest} instance
     */
    public EditMessageApiRequest withStreamId(long streamId) {
        putParam(STREAM_ID, streamId);
        return this;
    }

    /**
     * Sets the optional name of the topic to move the message to.
     *
     * @see          https://zulip.com/api/update-message#parameter-topic
     *
     * @param  topic The name of the topic that the message should use
     * @return       This {@link EditMessageApiRequest} instance
     */
    public EditMessageApiRequest withTopic(String topic) {
        putParam(TOPIC, topic);
        return this;
    }

    /**
     * Executes the Zulip API request for editing a message.
     *
     * @throws ZulipClientException if the request was not successful
     */
    @Override
    public void execute() throws ZulipClientException {
        String path = String.format(MESSAGES_ID_API_PATH, messageId);
        client().patch(path, getParams(), ZulipApiResponse.class);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy