Search in sources :

Example 26 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelServiceTest method removeMemberFromChannel_withSuccess.

@Test
public void removeMemberFromChannel_withSuccess() {
    ApiResponse response = (ApiResponse) GsonUtils.getObjectFromJson(MockConstants.removeMemberSuccessResponse, ApiResponse.class);
    when(channelClientService.removeMemberFromChannel(8905836, "reytum7")).thenReturn(response);
    String status = channelService.removeMemberFromChannelProcess(8905836, "reytum7");
    assertEquals(AlResponse.SUCCESS, status);
}
Also used : ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) Test(org.junit.Test)

Example 27 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelServiceTest method addMemberToChannel_withSuccess.

@Test
public void addMemberToChannel_withSuccess() {
    ApiResponse response = (ApiResponse) GsonUtils.getObjectFromJson(MockConstants.addMemberSuccessResponse, ApiResponse.class);
    when(channelClientService.addMemberToChannel(8905836, "reytum6")).thenReturn(response);
    assertEquals(AlResponse.SUCCESS, channelService.addMemberToChannelProcess(8905836, "reytum6"));
}
Also used : ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) Test(org.junit.Test)

Example 28 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelServiceTest method addMemberToChannel_withError.

@Test
public void addMemberToChannel_withError() {
    ApiResponse response = (ApiResponse) GsonUtils.getObjectFromJson(MockConstants.addMemberErrorResponse, ApiResponse.class);
    when(channelClientService.addMemberToChannel(8905836, "reytum6")).thenReturn(response);
    assertEquals(AlResponse.ERROR, channelService.addMemberToChannelProcess(8905836, "reytum6"));
}
Also used : ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) Test(org.junit.Test)

Example 29 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelServiceTest method removeMemberFromChannel_withError.

@Test
public void removeMemberFromChannel_withError() {
    ApiResponse response = (ApiResponse) GsonUtils.getObjectFromJson(MockConstants.removeMemberErrorResponse, ApiResponse.class);
    when(channelClientService.removeMemberFromChannel(8905836, "reytum700")).thenReturn(response);
    assertEquals(AlResponse.ERROR, channelService.removeMemberFromChannelProcess(8905836, "reytum700"));
}
Also used : ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) Test(org.junit.Test)

Example 30 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method getAlConversationList.

/**
 * @deprecated This method is no longer used and will be deprecated soon.
 */
@Deprecated
public synchronized List<Message> getAlConversationList(int status, int pageSize, Long lastFetchTime, boolean makeServerCall) throws Exception {
    List<Message> conversationList = new ArrayList<>();
    List<Message> cachedConversationList = messageDatabaseService.getAlConversationList(status, lastFetchTime);
    if (!makeServerCall && !cachedConversationList.isEmpty()) {
        return cachedConversationList;
    }
    AlConversationResponse alConversationResponse = null;
    try {
        ApiResponse<AlConversationResponse> apiResponse = (ApiResponse<AlConversationResponse>) GsonUtils.getObjectFromJson(messageClientService.getAlConversationList(status, pageSize, lastFetchTime), new TypeToken<ApiResponse<AlConversationResponse>>() {
        }.getType());
        if (apiResponse != null) {
            alConversationResponse = apiResponse.getResponse();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    if (alConversationResponse == null) {
        return null;
    }
    try {
        if (alConversationResponse.getUserDetails() != null) {
            processUserDetails(alConversationResponse.getUserDetails());
        }
        if (alConversationResponse.getGroupFeeds() != null) {
            ChannelService.getInstance(context).processChannelFeedList(alConversationResponse.getGroupFeeds(), false);
        }
        Message[] messages = alConversationResponse.getMessage();
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
        if (messages != null && messages.length > 0 && cachedConversationList.size() > 0 && cachedConversationList.get(0).isLocalMessage()) {
            if (cachedConversationList.get(0).equals(messages[0])) {
                Utils.printLog(context, TAG, "Both messages are same.");
                deleteMessage(cachedConversationList.get(0));
            }
        }
        for (Message message : messages) {
            if (!message.isCall() || userPreferences.isDisplayCallRecordEnable()) {
                if (message.getTo() == null) {
                    continue;
                }
                if (message.hasAttachment() && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(message);
                }
                if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(message);
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (isHideActionMessage && message.isActionMessage()) {
                    message.setHidden(true);
                }
                if (messageDatabaseService.isMessagePresent(message.getKeyString(), Message.ReplyMessage.HIDE_MESSAGE.getValue())) {
                    messageDatabaseService.updateMessageReplyType(message.getKeyString(), Message.ReplyMessage.NON_HIDDEN.getValue());
                } else {
                    messageDatabaseService.createMessage(message);
                }
                if (message.hasHideKey()) {
                    if (message.getGroupId() != null) {
                        Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
                        if (newChannel != null) {
                            getMessagesWithNetworkMetaData(null, null, null, newChannel, null, true, false);
                        }
                    } else {
                        getMessagesWithNetworkMetaData(null, null, new Contact(message.getContactIds()), null, null, true, false);
                    }
                }
            }
            conversationList.add(message);
        }
        Intent intent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    List<Message> finalMessageList = messageDatabaseService.getAlConversationList(status, lastFetchTime);
    List<String> messageKeys = new ArrayList<>();
    for (Message msg : finalMessageList) {
        if (msg.getTo() == null) {
            continue;
        }
        if (Message.MetaDataType.HIDDEN.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
            continue;
        }
        if (msg.getMetadata() != null && msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
            messageKeys.add(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
        }
    }
    if (messageKeys != null && messageKeys.size() > 0) {
        Message[] replyMessageList = getMessageListByKeyList(messageKeys);
        if (replyMessageList != null) {
            for (Message replyMessage : replyMessageList) {
                if (replyMessage.getTo() == null) {
                    continue;
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(replyMessage);
                }
                if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(replyMessage);
                }
                replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
                messageDatabaseService.createMessage(replyMessage);
            }
        }
    }
    if (!conversationList.isEmpty()) {
        Collections.sort(conversationList, new Comparator<Message>() {

            @Override
            public int compare(Message lhs, Message rhs) {
                return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
            }
        });
    }
    return finalMessageList;
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) Intent(android.content.Intent) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) JsonSyntaxException(com.google.gson.JsonSyntaxException) Contact(com.applozic.mobicommons.people.contact.Contact)

Aggregations

ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)54 SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)23 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)22 JSONException (org.json.JSONException)19 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)16 RegisteredUsersApiResponse (com.applozic.mobicomkit.feed.RegisteredUsersApiResponse)16 Test (org.junit.Test)14 MultipleChannelFeedApiResponse (com.applozic.mobicomkit.MultipleChannelFeedApiResponse)12 MockedConstants.userDetailsApiResponse (com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 Nullable (androidx.annotation.Nullable)8 Contact (com.applozic.mobicommons.people.contact.Contact)8 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)3 ArrayList (java.util.ArrayList)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 ProgressDialog (android.app.ProgressDialog)2 Toast (android.widget.Toast)2 UserBlockTask (com.applozic.mobicomkit.api.account.user.UserBlockTask)2 MuteNotificationAsync (com.applozic.mobicomkit.api.notification.MuteNotificationAsync)2 MuteNotificationRequest (com.applozic.mobicomkit.api.notification.MuteNotificationRequest)2