Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message Draft v2 #12

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ endif()

option(RUN_TESTS "Run tests" OFF)

option(COMPILE_EXAMPLES "Compile examples" OFF)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/pubnub_chat)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) # not public imports
Expand All @@ -46,7 +48,9 @@ if(WIN32 OR WIN64 OR MSVC)
endif()

# TODO: pnsdk should be different for each SDK (C++, EU, Unity, etc.)
set(PUBNUB_SDK_VERSION_SUFFIX "/CA-SDKC++/${PROJECT_VERSION}")
#set(PUBNUB_SDK_VERSION_SUFFIX "\\\"/CA-SDKC++/${PROJECT_VERSION}\\\"")
#set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -DPUBNUB_SDK_VERSION_SUFFIX=\\\"/CA-UNREAL/x.x.x\\\")


FetchContent_Declare(
pubnub
Expand All @@ -59,6 +63,8 @@ FetchContent_Declare(

FetchContent_MakeAvailable(pubnub)

target_compile_options(pubnub PUBLIC -DPUBNUB_SDK_VERSION_SUFFIX=\"/CA-Unreal/x.x.x\")

FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json.git
Expand All @@ -70,13 +76,27 @@ FetchContent_Declare(

FetchContent_MakeAvailable(json)

FetchContent_Declare(
diff-match-patch
GIT_REPOSITORY https://github.com/leutloff/diff-match-patch-cpp-stl
GIT_TAG ba3bbe3cdba5d461e241b756a50085c3602a3b5a
GIT_SHALLOW TRUE
GIT_PROGRESS ON
SYSTEM
)

#TODO no need to build tests
FetchContent_MakeAvailable(diff-match-patch)

include_directories(${pubnub_SOURCE_DIR}/posix)
include_directories(${pubnub_SOURCE_DIR}/core)
include_directories(${pubnub_SOURCE_DIR})

include_directories(${json_SOURCE_DIR})
include_directories(${json_SOURCE_DIR}/include)

include_directories(${diff-match-patch_SOURCE_DIR})

include_directories(${CURRENT_SOURCE_DIR}/include)

set(INFRA_SOURCES
Expand All @@ -100,7 +120,8 @@ set(DOMAIN_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/domain/access_manager_logic.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/domain/typing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/domain/timetoken.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/domain/restrictions.cpp)
${CMAKE_CURRENT_SOURCE_DIR}/src/domain/restrictions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/domain/message_draft_entity.cpp)

set(APP_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/application/chat_service.cpp
Expand All @@ -112,10 +133,12 @@ set(APP_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/application/membership_service.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/application/callback_service.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/application/access_manager_service.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/application/draft_service.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/application/dao/channel_dao.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/application/dao/user_dao.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/application/dao/message_dao.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/application/dao/membership_dao.cpp)
${CMAKE_CURRENT_SOURCE_DIR}/src/application/dao/membership_dao.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/application/dao/message_draft_dao.cpp)

set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/presentation/chat.cpp
Expand Down Expand Up @@ -159,9 +182,13 @@ add_library(pubnub-chat SHARED ${SOURCES})
target_link_libraries(pubnub-chat PRIVATE pubnub)

add_executable(pubnub-chat-example example/main.cpp)

target_link_libraries(pubnub-chat-example PUBLIC pubnub-chat)

if(${COMPILE_EXAMPLES})
add_executable(pubnub-message-draft-example example/message_draft.cpp)
target_link_libraries(pubnub-message-draft-example PRIVATE pubnub-chat)
endif()

if(${RUN_TESTS})
message(STATUS "Running tests")
enable_testing()
Expand All @@ -182,6 +209,8 @@ if(${RUN_TESTS})
add_test(NAME ${name} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cgreen/build/tools/cgreen-runner ${CMAKE_CURRENT_SOURCE_DIR}/build/lib${name}.dylib)
endfunction()

add_test(NAME diff-match-patch-test COMMAND ${diff-match-patch_SOURCE_DIR}/../diffmatchpatch-build/diff_match_patch_test_string)

test_suite(string-unit ${CMAKE_CURRENT_SOURCE_DIR}/test/unit/string_unit.cpp)
test_suite(json-unit ${CMAKE_CURRENT_SOURCE_DIR}/test/unit/json_unit.cpp)
test_suite(typing-unit ${CMAKE_CURRENT_SOURCE_DIR}/test/unit/typing_unit.cpp)
Expand All @@ -192,4 +221,8 @@ if(${RUN_TESTS})
test_suite(channel-entity-unit ${CMAKE_CURRENT_SOURCE_DIR}/test/unit/channel_entity_unit.cpp)
test_suite(prarsers-unit ${CMAKE_CURRENT_SOURCE_DIR}/test/unit/parsers_unit.cpp)
test_suite(member-entity-unit ${CMAKE_CURRENT_SOURCE_DIR}/test/unit/membership_entity_unit.cpp)
test_suite(message-draft-entity-unit ${CMAKE_CURRENT_SOURCE_DIR}/test/unit/message_draft_entity_unit.cpp)

#TODO: e/e
#test_suite(message-draft-e2e ${CMAKE_CURRENT_SOURCE_DIR}/test/e2e/message_draft_e2e.cpp)
endif()
16 changes: 10 additions & 6 deletions c_abi/include/c_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,15 @@ PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_channel_send_text_dirty(

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_channel_get_users_restrictions(Pubnub::Channel* channel, const char* sort, int limit, const char* next, const char* prev, char* result);

//PN_CHAT_EXTERN PN_CHAT_EXPORT Pubnub::MessageDraft* pn_channel_create_message_draft_dirty(Pubnub::Channel* channel,
// char* user_suggestion_source,
// bool is_typing_indicator_triggered,
// int user_limit,
// int channel_limit);
//
#define PN_MESSAGE_DRAFT_SUGGESTION_SOURCE int
#define PN_MESSAGE_DRAFT_USER_SUGGESTION_SOURCE_CHANNEL 0
#define PN_MESSAGE_DRAFT_USER_SUGGESTION_SOURCE_GLOBAL 1

PN_CHAT_EXTERN PN_CHAT_EXPORT Pubnub::MessageDraft* pn_channel_create_message_draft_dirty(Pubnub::Channel* channel,
PN_MESSAGE_DRAFT_SUGGESTION_SOURCE user_suggestion_source,
bool is_typing_indicator_triggered,
int user_limit,
int channel_limit);

#endif // PN_CHAT_C_CHANNEL_H

35 changes: 35 additions & 0 deletions c_abi/include/c_message_draft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,42 @@
#include "user.hpp"
#include "helpers/export.hpp"
#include "helpers/extern.hpp"
#include "c_errors.hpp"

PN_CHAT_EXTERN PN_CHAT_EXPORT void pn_message_draft_delete(Pubnub::MessageDraft* message_draft);

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_message_draft_insert_text(Pubnub::MessageDraft* message_draft, std::size_t position, const char* text_to_insert);

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_message_draft_remove_text(Pubnub::MessageDraft* message_draft, std::size_t position, std::size_t length);

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_message_draft_insert_suggested_mention(Pubnub::MessageDraft* message_draft, std::size_t offset, const char* replace_from, const char* replace_to, const char* target_json, const char* text);

#define PN_MESSAGE_DRAFT_MENTION_TARGET_TYPE_USER 0
#define PN_MESSAGE_DRAFT_MENTION_TARGET_TYPE_CHANNEL 1
#define PN_MESSAGE_DRAFT_MENTION_TARGET_TYPE_URL 2

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_message_draft_add_mention(Pubnub::MessageDraft* message_draft, std::size_t start, std::size_t length, const char* target);

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_message_draft_remove_mention(Pubnub::MessageDraft* message_draft, std::size_t start);

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_message_draft_update(Pubnub::MessageDraft* message_draft, const char* text);

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_message_draft_send(
Pubnub::MessageDraft* message_draft,
bool store_in_history,
bool send_by_post,
const char* meta,
int mentioned_users_length,
int* mentioned_users_indexes,
Pubnub::User** mentioned_users,
int referenced_channels_length,
int* referenced_channels_indexes,
Pubnub::Channel** referenced_channels,
const char* text_links_json,
Pubnub::Message* quoted_message);

PN_CHAT_EXTERN PN_CHAT_EXPORT PnCResult pn_message_draft_consume_callback_data(Pubnub::MessageDraft* message_draft, char* data);

PN_CHAT_EXTERN PN_CHAT_EXPORT void pn_message_draft_set_search_for_suggestions(Pubnub::MessageDraft* message_draft, bool search_for_suggestions);

#endif // PN_CHAT_C_MESSAGE_DRAFT_H
42 changes: 21 additions & 21 deletions c_abi/src/c_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,25 +720,25 @@ PnCResult pn_channel_get_users_restrictions(Pubnub::Channel* channel, const char
return PN_C_OK;
}

Pubnub::MessageDraft* pn_channel_create_message_draft_dirty(Pubnub::Channel* channel,
int user_suggestion_source,
bool is_typing_indicator_triggered,
int user_limit,
int channel_limit)
{
try {
Pubnub::MessageDraftConfig config;
config.user_suggestion_source = user_suggestion_source == PN_MESSAGE_DRAFT_USER_SUGGESTION_SOURCE_CHANNEL ?
Pubnub::MessageDraftConfig::MessageDraftSuggestionSource::Channel : Pubnub::MessageDraftConfig::MessageDraftSuggestionSource::Global;
config.is_typing_indicator_triggered = is_typing_indicator_triggered;
config.user_limit = user_limit;
config.channel_limit = channel_limit;

return new Pubnub::MessageDraft(channel->create_message_draft(config));
}
catch (std::exception& e) {
pn_c_set_error_message(e.what());

//Pubnub::MessageDraft* pn_channel_create_message_draft_dirty(Pubnub::Channel* channel,
// char* user_suggestion_source,
// bool is_typing_indicator_triggered,
// int user_limit,
// int channel_limit)
//{
// try {
// Pubnub::MessageDraftConfig config;
// config.user_suggestion_source = user_suggestion_source;
// config.is_typing_indicator_triggered = is_typing_indicator_triggered;
// config.user_limit = user_limit;
// config.channel_limit = channel_limit;
//
// return new Pubnub::MessageDraft(channel->create_message_draft(config));
// }
// catch (std::exception& e) {
// pn_c_set_error_message(e.what());
//
// return PN_C_ERROR_PTR;
// }
//}
return PN_C_ERROR_PTR;
}
}
2 changes: 0 additions & 2 deletions c_abi/src/c_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,10 @@ const char* jsonize_reactions(std::vector<Pubnub::MessageAction> reactions) {

Pubnub::String result = "[";
for (auto reaction : reactions) {
//result += "\"";
nlohmann::json json;
message_action_to_json(json, reaction);
result += json.dump().c_str();
result += ",";
//result += "\,";
}

result.erase(result.length() - 1);
Expand Down
Loading