protected User getUser() { return user != null ? user : ChatSDK.currentUser(); }
protected User getUser () { return user != null ? user : ChatSDK.currentUser(); }
@Override public List<User> contactsWithType(ConnectionType type) { if (ChatSDK.currentUser() != null) { return ChatSDK.currentUser().getContacts(type); } return new ArrayList<>(); }
@Override public List<User> contacts() { if (ChatSDK.currentUser() != null) { return ChatSDK.currentUser().getContacts(); } return new ArrayList<>(); }
public boolean isMe(){ return getId().longValue() == ChatSDK.currentUser().getId().longValue(); }
@Override public void deleteContactLocal(User user, ConnectionType type) { if (ChatSDK.currentUser() != null && !user.isMe()) { ChatSDK.currentUser().deleteContact(user, type); ChatSDK.core().userOff(user); } }
public List<Thread> allThreads () { List<UserThreadLink> links = DaoCore.fetchEntitiesWithProperty(UserThreadLink.class, UserThreadLinkDao.Properties.UserId, ChatSDK.currentUser().getId()); ArrayList<Thread> threads = new ArrayList<>(); for(UserThreadLink link : links) { threads.add(link.getThread()); } return threads; }
@Override public void addContactLocal(User user, ConnectionType type) { if (ChatSDK.currentUser() != null && !user.isMe()) { ChatSDK.currentUser().addContact(user, type); ChatSDK.core().userOn(user); } }
public List<Thread> fetchThreadsForUserWithID (Long userId) { List<Thread> threads = new ArrayList<>(); List<UserThreadLink> links = DaoCore.fetchEntitiesWithProperty(UserThreadLink.class, UserThreadLinkDao.Properties.UserId, ChatSDK.currentUser().getId()); for (UserThreadLink link : links) { Thread thread = link.getThread(); if (thread != null) { threads.add(thread); } else { // Delete the link - it's obviously corrupted DaoCore.deleteEntity(link); } } return threads; }
public static Message newMessage (int type, Thread thread) { Message message = StorageManager.shared().createEntity(Message.class); message.setSender(ChatSDK.currentUser()); message.setMessageStatus(MessageSendStatus.Sending); message.setDate(new DateTime(System.currentTimeMillis())); message.setEntityID(UUID.randomUUID().toString()); message.setType(type); thread.addMessage(message); return message; }
@Override protected void onResume() { super.onResume(); // Only if the current user is the admin of this thread. if (StringUtils.isNotBlank(thread.getCreatorEntityId()) && thread.getCreatorEntityId().equals(ChatSDK.currentUser().getEntityID())) { //threadImageView.setOnClickListener(ChatSDKIntentClickListener.getPickImageClickListener(this, THREAD_PIC)); threadImageView.setOnClickListener(new ProfilePictureChooserOnClickListener(this)); } }
public void showSettings() { ChatSDK.ui().startEditProfileActivity(getContext(), ChatSDK.currentUser().getEntityID()); }
public boolean isRead() { ReadStatus status = readStatusForUser(ChatSDK.currentUser()); if (status != null && status.is(ReadStatus.read())) { return true; } else if (sender != null && sender.isMe()) { return true; } else if (read == null) { return false; } else { return read; } }
public Completable setUserOnline() { User current = ChatSDK.currentUser(); if (current != null && StringUtils.isNotEmpty(current.getEntityID())) { return UserWrapper.initWithModel(currentUserModel()).goOnline(); } if (ChatSDK.hook() != null) { ChatSDK.hook().executeHook(BaseHookHandler.SetUserOnline, null); } return Completable.complete(); }
public Completable updateLastOnline() { return Completable.create(e -> { User currentUser = ChatSDK.currentUser(); currentUser.setLastOnline(new Date()); currentUser.update(); e.onComplete(); }).concatWith(pushUser()).subscribeOn(Schedulers.single()); }
@Override public Completable addContact(User user, ConnectionType type) { return Completable.create(emitter -> { DatabaseReference ref = FirebasePaths.userContactsRef(ChatSDK.currentUser().getEntityID()).child(user.getEntityID()); HashMap<String, Integer> data = new HashMap<>(); data.put(Keys.Type, type.ordinal()); ref.setValue(data, (databaseError, databaseReference) -> { if (databaseError == null) { emitter.onComplete(); } else { emitter.onError(databaseError.toException()); } }); }); }
public Completable setUserOffline() { User current = ChatSDK.currentUser(); if (current != null && StringUtils.isNotEmpty(current.getEntityID())) { // Update the last online figure then go offline return updateLastOnline() .concatWith(UserWrapper.initWithModel(currentUserModel()).goOffline()); } if (ChatSDK.hook() != null) { ChatSDK.hook().executeHook(BaseHookHandler.SetUserOffline, null); } return Completable.complete(); }
/** * Sending a broadcast that the chat was closed, Only if there were new messages on this chat. * This is used for example to update the thread list that messages has been read. */ @Override protected void onStop() { super.onStop(); disposableList.dispose(); stopTyping(true); markRead(); if (thread != null && thread.typeIs(ThreadType.Public) && removeUserFromChatOnExit) { ChatSDK.thread().removeUsersFromThread(thread, ChatSDK.currentUser()).observeOn(AndroidSchedulers.mainThread()).subscribe(new CrashReportingCompletableObserver()); } }
protected void initList() { boolean enableMultiSelect = ChatSDK.config().groupsEnabled; adapter = new UsersListAdapter(enableMultiSelect); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter); loadData(); adapter.getItemClicks().subscribe(item -> { if(item instanceof User) { if (ChatSDK.config().groupsEnabled) { adapter.toggleSelection(item); } else { UserListItem user = (UserListItem) item; createAndOpenThread("", (User) user, ChatSDK.currentUser()); } } }); }
@Override public Completable deleteContact(User user, ConnectionType type) { return Completable.create(emitter -> { DatabaseReference ref = FirebasePaths.userContactsRef(ChatSDK.currentUser().getEntityID()).child(user.getEntityID()); ref.removeValue((databaseError, databaseReference) -> { if (databaseError == null) { emitter.onComplete(); } else { emitter.onError(databaseError.toException()); } }); }); }