Search in sources :

Example 11 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelService method processChannelList.

public synchronized void processChannelList(List<ChannelFeed> channelFeedList) {
    if (channelFeedList != null && channelFeedList.size() > 0) {
        for (ChannelFeed channelFeed : channelFeedList) {
            Set<String> memberUserIds = channelFeed.getMembersName();
            Set<String> userIds = new HashSet<>();
            Channel channel = getChannel(channelFeed);
            if (channelDatabaseService.isChannelPresent(channel.getKey())) {
                channelDatabaseService.updateChannel(channel);
                channelDatabaseService.deleteChannelUserMappers(channel.getKey());
            } else {
                channelDatabaseService.addChannel(channel);
            }
            if (memberUserIds != null && memberUserIds.size() > 0) {
                for (String userId : memberUserIds) {
                    ChannelUserMapper channelUserMapper = new ChannelUserMapper(channelFeed.getId(), userId);
                    channelDatabaseService.addChannelUserMapper(channelUserMapper);
                    if (!baseContactService.isContactExists(userId)) {
                        userIds.add(userId);
                    }
                }
                if (userIds != null && userIds.size() > 0) {
                    userService.processUserDetailsByUserIds(userIds);
                }
            }
            if (channelFeed.getGroupUsers() != null && channelFeed.getGroupUsers().size() > 0) {
                for (ChannelUsersFeed channelUsers : channelFeed.getGroupUsers()) {
                    if (channelUsers.getRole() != null) {
                        channelDatabaseService.updateRoleInChannelUserMapper(channelFeed.getId(), channelUsers.getUserId(), channelUsers.getRole());
                    }
                }
            }
        }
    }
}
Also used : ChannelUsersFeed(com.applozic.mobicomkit.feed.ChannelUsersFeed) Channel(com.applozic.mobicommons.people.channel.Channel) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) HashSet(java.util.HashSet)

Example 12 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelService method processChannelFeedList.

public void processChannelFeedList(ChannelFeed[] channelFeeds, boolean isUserDetails) {
    if (channelFeeds != null && channelFeeds.length > 0) {
        for (ChannelFeed channelFeed : channelFeeds) {
            Set<String> memberUserIds = channelFeed.getMembersName();
            Set<String> userIds = new HashSet<>();
            Channel channel = getChannel(channelFeed);
            if (channelDatabaseService.isChannelPresent(channel.getKey())) {
                channelDatabaseService.updateChannel(channel);
            } else {
                channelDatabaseService.addChannel(channel);
            }
            if (channelFeed.getConversationPxy() != null) {
                channelFeed.getConversationPxy().setGroupId(channelFeed.getId());
                ConversationService.getInstance(context).addConversation(channelFeed.getConversationPxy());
            }
            if (memberUserIds != null && memberUserIds.size() > 0) {
                for (String userId : memberUserIds) {
                    ChannelUserMapper channelUserMapper = new ChannelUserMapper(channelFeed.getId(), userId);
                    if (channelDatabaseService.isChannelUserPresent(channelFeed.getId(), userId)) {
                        channelDatabaseService.updateChannelUserMapper(channelUserMapper);
                    } else {
                        channelDatabaseService.addChannelUserMapper(channelUserMapper);
                    }
                }
            }
            if (channelFeed.getGroupUsers() != null && channelFeed.getGroupUsers().size() > 0) {
                for (ChannelUsersFeed channelUsers : channelFeed.getGroupUsers()) {
                    if (channelUsers.getRole() != null) {
                        channelDatabaseService.updateRoleInChannelUserMapper(channelFeed.getId(), channelUsers.getUserId(), channelUsers.getRole());
                    }
                }
            }
            if (isUserDetails) {
                userService.processUserDetail(channelFeed.getUsers());
            }
        }
    }
}
Also used : ChannelUsersFeed(com.applozic.mobicomkit.feed.ChannelUsersFeed) Channel(com.applozic.mobicommons.people.channel.Channel) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) HashSet(java.util.HashSet)

Example 13 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method updateChannelSubTitle.

public void updateChannelSubTitle() {
    channelUserMapperList = ChannelService.getInstance(getActivity()).getListOfUsersFromChannelUserMapper(channel.getKey());
    if (channelUserMapperList != null && channelUserMapperList.size() > 0) {
        if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
            String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
            if (!TextUtils.isEmpty(userId)) {
                Contact withUserContact = appContactService.getContactById(userId);
                if (withUserContact != null) {
                    if (withUserContact.isBlocked()) {
                        ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle("");
                    } else {
                        if (withUserContact.isConnected()) {
                            ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getActivity().getString(R.string.user_online));
                        } else if (withUserContact.getLastSeenAt() != 0) {
                            ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getActivity().getString(R.string.subtitle_last_seen_at_time) + " " + DateUtils.getDateAndTimeForLastSeen(withUserContact.getLastSeenAt()));
                        } else {
                            ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle("");
                        }
                    }
                }
            }
        } else {
            StringBuffer stringBuffer = new StringBuffer();
            Contact contactDisplayName;
            String youString = null;
            int i = 0;
            for (ChannelUserMapper channelUserMapper : channelUserMapperList) {
                i++;
                if (i > 20)
                    break;
                contactDisplayName = appContactService.getContactById(channelUserMapper.getUserKey());
                if (!TextUtils.isEmpty(channelUserMapper.getUserKey())) {
                    if (MobiComUserPreference.getInstance(getActivity()).getUserId().equals(channelUserMapper.getUserKey())) {
                        youString = getString(R.string.you_string);
                    } else {
                        stringBuffer.append(contactDisplayName.getDisplayName()).append(",");
                    }
                }
            }
            if (!TextUtils.isEmpty(stringBuffer)) {
                if (channelUserMapperList.size() <= 20) {
                    if (!TextUtils.isEmpty(youString)) {
                        stringBuffer.append(youString).append(",");
                    }
                    int lastIndex = stringBuffer.lastIndexOf(",");
                    String userIds = stringBuffer.replace(lastIndex, lastIndex + 1, "").toString();
                    ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(userIds);
                } else {
                    ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(stringBuffer.toString());
                }
            } else {
                ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(youString);
            }
        }
    }
}
Also used : AppCompatActivity(android.support.v7.app.AppCompatActivity) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) Collections.disjoint(java.util.Collections.disjoint) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 14 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelDatabaseServiceTest method createDb.

@Before
public void createDb() {
    Context context = ApplicationProvider.getApplicationContext();
    dbHelper = new MobiComDatabaseHelper(ApplicationProvider.getApplicationContext(), null, null, MobiComDatabaseHelper.DB_VERSION);
    channelDatabaseService = ChannelDatabaseService.getTestInstance(context, dbHelper);
    messageDatabaseService = new MessageDatabaseService(context, dbHelper);
    channel = new Channel();
    Map<String, String> metadata = new HashMap<>();
    metadata.put("met1", "1");
    metadata.put("met2", "2");
    channel.setMetadata(metadata);
    channel.setKey(12345);
    channel.setParentKey(123);
    channel.setParentClientGroupId("parentId");
    channel.setClientGroupId("clientId");
    channel.setName("dname");
    channel.setAdminKey("adminKey");
    channel.setType((short) 1);
    channel.setUnreadCount(10);
    channel.setImageUrl("imageUrl");
    channel.setLocalImageUri("localImageUri");
    channel.setNotificationAfterTime(123456L);
    channel.setDeletedAtTime(123456L);
    channel.setKmStatus(1);
    channel1 = new Channel();
    Map<String, String> metadata1 = new HashMap<>();
    metadata.put("met11", "1");
    metadata.put("met21", "2");
    channel1.setMetadata(metadata1);
    channel1.setKey(123451);
    channel1.setParentKey(1231);
    channel1.setParentClientGroupId("parentId1");
    channel1.setClientGroupId("clientId");
    channel1.setName("bname1");
    channel1.setAdminKey("adminKey1");
    channel1.setType((short) 11);
    channel1.setUnreadCount(101);
    channel1.setImageUrl("imageUrl1");
    channel1.setLocalImageUri("localImageUri1");
    channel1.setNotificationAfterTime(12345L);
    channel1.setDeletedAtTime(12345L);
    channel1.setKmStatus(11);
    channel2 = new Channel();
    Map<String, String> metadata2 = new HashMap<>();
    metadata.put("met12", "1");
    metadata.put("met22", "2");
    channel2.setMetadata(metadata2);
    channel2.setKey(123452);
    channel2.setParentKey(1232);
    channel2.setParentClientGroupId("parentId2");
    channel2.setClientGroupId("clientId2");
    channel2.setName("aname2");
    channel2.setAdminKey("adminKey2");
    channel2.setType((short) 12);
    channel2.setUnreadCount(102);
    channel2.setImageUrl("imageUrl2");
    channel2.setLocalImageUri("localImageUri2");
    channel2.setNotificationAfterTime(1234L);
    channel2.setDeletedAtTime(1234L);
    channel2.setKmStatus(12);
    channel3 = new Channel();
    Map<String, String> metadata3 = new HashMap<>();
    metadata.put("met13", "1");
    metadata.put("met23", "2");
    channel3.setMetadata(metadata3);
    channel3.setKey(123453);
    channel3.setParentKey(1233);
    channel3.setParentClientGroupId("parentId3");
    channel3.setClientGroupId("clientId3");
    channel3.setName("cname3");
    channel3.setAdminKey("adminKey3");
    channel3.setType((short) 13);
    channel3.setUnreadCount(103);
    channel3.setImageUrl("imageUrl3");
    channel3.setLocalImageUri("localImageUri3");
    channel3.setNotificationAfterTime(123L);
    channel3.setDeletedAtTime(123L);
    channel3.setKmStatus(13);
    // ChannelUserMapper objects
    channelUserMapper = new ChannelUserMapper();
    // for channel1
    channelUserMapper.setKey(123451);
    channelUserMapper.setUserKey("clientId");
    channelUserMapper.setUnreadCount(20);
    channelUserMapper.setStatus((short) 2);
    channelUserMapper.setParentKey(123);
    channelUserMapper.setRole(4);
    channelUserMapper1 = new ChannelUserMapper();
    // for channel1
    channelUserMapper1.setKey(123451);
    channelUserMapper1.setUserKey("clientId1");
    channelUserMapper1.setUnreadCount(201);
    channelUserMapper1.setStatus((short) 2);
    channelUserMapper1.setParentKey(1231);
    channelUserMapper1.setRole(41);
    channelUserMapper2 = new ChannelUserMapper();
    // for channel2
    channelUserMapper2.setKey(123452);
    channelUserMapper2.setUserKey("clientId2");
    channelUserMapper2.setUnreadCount(202);
    channelUserMapper2.setStatus((short) 3);
    channelUserMapper2.setParentKey(1232);
    channelUserMapper2.setRole(42);
}
Also used : Context(android.content.Context) HashMap(java.util.HashMap) Channel(com.applozic.mobicommons.people.channel.Channel) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService) Before(org.junit.Before)

Example 15 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelDatabaseServiceTest method addAndRetrieveChannelUserMapper.

// ChannelUserMapper methods >>
// addChannelUserMapper, getChannelUserByChannelKeyAndUserId, getChannelUserList, getChannelByChannelKey, getGroupOfTwoChannelUserId
@Test
public void addAndRetrieveChannelUserMapper() {
    channelDatabaseService.addChannelUserMapper(channelUserMapper);
    channelDatabaseService.addChannelUserMapper(channelUserMapper1);
    channelDatabaseService.addChannelUserMapper(channelUserMapper2);
    assertThat(channelDatabaseService.getChannelUserByChannelKeyAndUserId(channel1.getKey(), "clientId").toString()).isEqualTo(channelUserMapper.toString());
    assertThat(channelDatabaseService.getChannelUserByChannelKeyAndUserId(channel1.getKey(), "clientId1").toString()).isEqualTo(channelUserMapper1.toString());
    assertThat(channelDatabaseService.getChannelByChannelKey(channel2.getKey())).isNull();
    List<ChannelUserMapper> channelUserMappersChannel1 = channelDatabaseService.getChannelUserList(channel1.getKey());
    List<ChannelUserMapper> channelUserMappersChannel2 = channelDatabaseService.getChannelUserList(channel2.getKey());
    assertThat(channelUserMappersChannel1.get(0).toString()).isEqualTo(channelUserMapper.toString());
    assertThat(channelUserMappersChannel1.get(1).toString()).isEqualTo(channelUserMapper1.toString());
    assertThat(channelUserMappersChannel2.get(0).toString()).isEqualTo(channelUserMapper2.toString());
    // get group of two channel user id, NOTE: the function needed to be tampered to provide getting the logged in user id
    // Reason: MobicomUserPreference is used inside the function
    // I have tested it by manually providing a mock userId
    ChannelDatabaseService channelDatabaseService = Mockito.mock(ChannelDatabaseService.class);
    String userKey = channelDatabaseService.getGroupOfTwoReceiverId(channel1.getKey());
// assertThat(userKey).isEqualTo("clientId1"); //see user mapper objects for explanation
}
Also used : ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) ChannelDatabaseService(com.applozic.mobicomkit.channel.database.ChannelDatabaseService) Test(org.junit.Test)

Aggregations

ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)22 Channel (com.applozic.mobicommons.people.channel.Channel)7 ChannelUsersFeed (com.applozic.mobicomkit.feed.ChannelUsersFeed)4 Contact (com.applozic.mobicommons.people.contact.Contact)4 Cursor (android.database.Cursor)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)3 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)3 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 AdapterView (android.widget.AdapterView)2 ChannelDatabaseService (com.applozic.mobicomkit.channel.database.ChannelDatabaseService)2 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)2 Collections.disjoint (java.util.Collections.disjoint)2 Test (org.junit.Test)2 Context (android.content.Context)1 Intent (android.content.Intent)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 SpannableString (android.text.SpannableString)1