From 5b58ff4671a5e32bb24ec5259df2659934cee542 Mon Sep 17 00:00:00 2001 From: Matthew Weathers Date: Mon, 20 Aug 2018 10:39:36 -0500 Subject: [PATCH] Enable payloads for custom content types --- .../chatkit/messages/MessageHolders.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java index 4fce59d3..71b99839 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java @@ -483,6 +483,37 @@ MessageHolders registerContentType( return this; } + /** + * Registers custom content type (e.g. multimedia, events etc.) + * + * @param type unique id for content type + * @param incomingHolder holder class for incoming message + * @param outcomingHolder holder class for outcoming message + * @param incomingPayload payload for incoming message + * @param outcomingPayload payload for outcoming message + * @param incomingLayout layout resource for incoming message + * @param outcomingLayout layout resource for outcoming message + * @param contentChecker {@link MessageHolders.ContentChecker} for registered type + * @return {@link MessageHolders} for subsequent configuration. + */ + public + MessageHolders registerContentType( + byte type, + @NonNull Class> incomingHolder, Object incomingPayload, @LayoutRes int incomingLayout, + @NonNull Class> outcomingHolder, Object outcomingPayload, @LayoutRes int outcomingLayout, + @NonNull MessageHolders.ContentChecker contentChecker) { + + if (type == 0) + throw new IllegalArgumentException("content type must be greater or less than '0'!"); + + customContentTypes.add( + new MessageHolders.ContentTypeConfig<>(type, + new MessageHolders.HolderConfig<>(incomingHolder, incomingLayout, incomingPayload), + new MessageHolders.HolderConfig<>(outcomingHolder, outcomingLayout, outcomingPayload))); + this.contentChecker = contentChecker; + return this; + } + /* * INTERFACES * */