@Override public void pin(IMessage message) { PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.MANAGE_MESSAGES); if (!message.getChannel().equals(this)) throw new DiscordException("Message channel doesn't match current channel!"); if (message.isPinned()) throw new DiscordException("Message already pinned!"); ((DiscordClientImpl) client).REQUESTS.PUT.makeRequest(DiscordEndpoints.CHANNELS + id + "/pins/" + message.getStringID()); }
@Override public void unpin(IMessage message) { PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.MANAGE_MESSAGES); if (!message.getChannel().equals(this)) throw new DiscordException("Message channel doesn't match current channel!"); if (!message.isPinned()) throw new DiscordException("Message is not pinned!"); ((DiscordClientImpl) client).REQUESTS.DELETE.makeRequest(DiscordEndpoints.CHANNELS + id + "/pins/" + message.getStringID()); }
private void messageUpdate(MessageObject json) { Channel channel = (Channel) client.getChannelByID(Long.parseUnsignedLong(json.channel_id)); if (channel == null) return; IMessage toUpdate = channel.messages.get(json.id); if (toUpdate == null) { // Cannot resolve update type. MessageObject is incomplete, so we'll have to request for the full message. if (channel.isPrivate() || PermissionUtils.hasHierarchicalPermissions(channel, client.ourUser, channel.getGuild().getRolesForUser(client.ourUser), Permissions.READ_MESSAGE_HISTORY)) client.dispatcher.dispatch(new MessageUpdateEvent(null, channel.fetchMessage(Long.parseUnsignedLong(json.id)))); // else //FIXME: unable to fire message update events when the user doesn't have the read message history permission } else { IMessage oldMessage = toUpdate.copy(); IMessage updatedMessage = DiscordUtils.getUpdatedMessageFromJSON(client, toUpdate, json); if (json.pinned != null && oldMessage.isPinned() && !json.pinned) { client.dispatcher.dispatch(new MessageUnpinEvent(oldMessage, updatedMessage)); } else if (json.pinned != null && !oldMessage.isPinned() && json.pinned) { client.dispatcher.dispatch(new MessagePinEvent(oldMessage, updatedMessage)); } else if (oldMessage.getEmbeds().size() < updatedMessage.getEmbeds().size()) { client.dispatcher.dispatch(new MessageEmbedEvent(oldMessage, updatedMessage, oldMessage.getEmbeds())); } else if (json.content != null && !oldMessage.getContent().equals(json.content)) { client.dispatcher.dispatch(new MessageEditEvent(oldMessage, updatedMessage)); } else { client.dispatcher.dispatch(new MessageUpdateEvent(oldMessage, updatedMessage)); } } }