Skip to content

Commit

Permalink
Feat: pin messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Darker935 authored Jun 26, 2024
1 parent 0873de8 commit 48348ad
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/it/auties/whatsapp/api/Whatsapp.java
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,44 @@ public <T extends MessageInfo> CompletableFuture<T> editMessage(T oldMessage, Me
};
}

/**
* Pin a message
*
* @param messageKey non-null message key to pin
* @param pinTimer the default timer that message will be pinned
* @return a CompletableFuture
*/
public CompletableFuture<Void> pinMessage(ChatMessageKey messageKey, ChatMessagePinTimer pinTimer) {
if (messageKey.fromMe()) {
messageKey.setSenderJid(null);
}
var message = new PinInChatMessageBuilder()
.key(messageKey)
.pinType(PinInChatMessage.Type.PIN_FOR_ALL)
.senderTimestampMilliseconds(Clock.nowMilliseconds())
.build();
var deviceInfo = new DeviceContextInfoBuilder()
.messageAddOnDurationInSecs(pinTimer.periodSeconds())
.build();
var sender = messageKey.chatJid().hasServer(JidServer.GROUP) ? jidOrThrowError() : null;
var key = new ChatMessageKeyBuilder()
.id(ChatMessageKey.randomIdV2(sender, store().clientType()))
.chatJid(messageKey.chatJid())
.fromMe(true)
.senderJid(sender)
.build();
var pinInfo = new ChatMessageInfoBuilder()
.status(MessageStatus.PENDING)
.senderJid(sender)
.key(key)
.message(MessageContainer.of(message).withDeviceInfo(deviceInfo))
.timestampSeconds(Clock.nowSeconds())
.build();
var attrs = Map.of("edit", 2);
var request = new MessageSendRequest.Chat(pinInfo, null, false, false, attrs);
return socketHandler.sendMessage(request);
}

public CompletableFuture<ChatMessageInfo> sendStatus(String message) {
return sendStatus(MessageContainer.of(message));
}
Expand Down

0 comments on commit 48348ad

Please sign in to comment.