use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class GroupAvatarChangeActor method uploadCompleted.
public void uploadCompleted(final long rid, FileReference fileReference) {
if (!tasksMap.containsKey(rid)) {
return;
}
final int gid = tasksMap.get(rid);
long accessHash = getGroup(gid).getAccessHash();
if (currentTasks.get(gid) != rid) {
return;
}
api(new RequestEditGroupAvatar(new ApiGroupOutPeer(gid, accessHash), rid, new ApiFileLocation(fileReference.getFileId(), fileReference.getAccessHash()), ApiSupportConfiguration.OPTIMIZATIONS)).flatMap(responseEditGroupAvatar -> updates().applyUpdate(responseEditGroupAvatar.getSeq(), responseEditGroupAvatar.getState(), new UpdateGroupAvatarChanged(gid, responseEditGroupAvatar.getAvatar()))).then(v -> avatarChanged(gid, rid)).failure(e -> {
if (!tasksMap.containsKey(rid)) {
return;
}
final int gid2 = tasksMap.get(rid);
if (currentTasks.get(gid2) != rid) {
return;
}
currentTasks.remove(gid2);
tasksMap.remove(rid);
context().getGroupsModule().getAvatarVM(gid2).getUploadState().change(new AvatarUploadState(null, false));
});
}
use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class GroupInfoFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
chatId = getArguments().getInt(EXTRA_CHAT_ID);
groupVM = groups().get(chatId);
View res = inflater.inflate(R.layout.fragment_group, container, false);
listView = (RecyclerListView) res.findViewById(R.id.groupList);
notMemberView = res.findViewById(R.id.notMember);
res.setBackgroundColor(style.getMainBackgroundColor());
// listView.setBackgroundColor(style.getMainBackgroundColor());
notMemberView.setBackgroundColor(style.getMainBackgroundColor());
((TextView) notMemberView.findViewById(R.id.not_member_text)).setTextColor(style.getTextPrimaryColor());
//
// Header
//
// Views
View header = inflater.inflate(R.layout.fragment_group_header, listView, false);
TextView title = (TextView) header.findViewById(R.id.title);
TextView subtitle = (TextView) header.findViewById(R.id.subtitle);
avatarView = (AvatarView) header.findViewById(R.id.avatar);
avatarView.init(Screen.dp(48), 22);
TextView aboutTV = (TextView) header.findViewById(R.id.about);
View shortNameCont = header.findViewById(R.id.shortNameContainer);
TextView shortNameView = (TextView) header.findViewById(R.id.shortName);
TextView shortLinkView = (TextView) header.findViewById(R.id.shortNameLink);
TextView addMember = (TextView) header.findViewById(R.id.addMemberAction);
addMember.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
TextView members = (TextView) header.findViewById(R.id.viewMembersAction);
TextView leaveAction = (TextView) header.findViewById(R.id.leaveAction);
TextView administrationAction = (TextView) header.findViewById(R.id.administrationAction);
View descriptionContainer = header.findViewById(R.id.descriptionContainer);
SwitchCompat isNotificationsEnabled = (SwitchCompat) header.findViewById(R.id.enableNotifications);
// Styling
// ((TextView) header.findViewById(R.id.about_hint)).setTextColor(style.getTextSecondaryColor());
header.setBackgroundColor(style.getMainBackgroundColor());
header.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
title.setTextColor(style.getProfileTitleColor());
subtitle.setTextColor(style.getProfileSubtitleColor());
aboutTV.setTextColor(style.getTextPrimaryColor());
shortNameView.setTextColor(style.getTextPrimaryColor());
shortLinkView.setTextColor(style.getTextSecondaryColor());
// settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
((TintImageView) header.findViewById(R.id.settings_notification_icon)).setTint(style.getSettingsIconColor());
((TintImageView) header.findViewById(R.id.settings_about_icon)).setTint(style.getSettingsIconColor());
((TextView) header.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
((TextView) header.findViewById(R.id.addMemberAction)).setTextColor(style.getTextPrimaryColor());
members.setTextColor(style.getTextPrimaryColor());
administrationAction.setTextColor(style.getTextPrimaryColor());
leaveAction.setTextColor(style.getTextDangerColor());
if (groupVM.getGroupType() == GroupType.CHANNEL) {
leaveAction.setText(R.string.group_leave_channel);
} else {
leaveAction.setText(R.string.group_leave);
}
header.findViewById(R.id.after_settings_divider).setBackgroundColor(style.getBackyardBackgroundColor());
//
// Header
//
avatarView.bind(groupVM.getAvatar().get(), groupVM.getName().get(), groupVM.getId());
avatarView.setOnClickListener(view -> {
if (groupVM.getAvatar().get() != null) {
startActivity(ViewAvatarActivity.viewGroupAvatar(chatId, getActivity()));
}
});
bind(groupVM.getName(), name -> {
title.setText(name);
});
bind(groupVM.getMembersCount(), val -> {
subtitle.setText(messenger().getFormatter().formatGroupMembers(val));
});
// About
bind(groupVM.getAbout(), (about) -> {
aboutTV.setText(about);
aboutTV.setVisibility(about != null ? View.VISIBLE : View.GONE);
});
bind(groupVM.getShortName(), shortName -> {
if (shortName != null) {
shortNameView.setText("@" + shortName);
String prefix = ActorSDK.sharedActor().getGroupInvitePrefix();
if (prefix != null) {
shortLinkView.setText(prefix + shortName);
shortLinkView.setVisibility(View.VISIBLE);
} else {
shortLinkView.setVisibility(View.GONE);
}
}
shortNameCont.setVisibility(shortName != null ? View.VISIBLE : View.GONE);
});
final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
shortNameCont.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String link = shortLinkView.getText().toString();
clipboard.setPrimaryClip(ClipData.newPlainText(null, (link.contains("://") ? "" : "https://") + link));
Toast.makeText(getActivity(), getString(R.string.invite_link_copied), Toast.LENGTH_SHORT).show();
}
});
bind(groupVM.getAbout(), groupVM.getShortName(), (about, shortName) -> {
descriptionContainer.setVisibility(about != null || shortName != null ? View.VISIBLE : View.GONE);
});
// Notifications
isNotificationsEnabled.setChecked(messenger().isNotificationsEnabled(Peer.group(chatId)));
isNotificationsEnabled.setOnCheckedChangeListener((buttonView, isChecked) -> {
messenger().changeNotificationsEnabled(Peer.group(chatId), isChecked);
});
header.findViewById(R.id.notificationsCont).setOnClickListener(v -> {
isNotificationsEnabled.setChecked(!isNotificationsEnabled.isChecked());
});
// Add Member
bind(groupVM.getIsCanInviteMembers(), (canInvite) -> {
if (canInvite) {
addMember.setVisibility(View.VISIBLE);
} else {
addMember.setVisibility(View.GONE);
}
});
addMember.setOnClickListener(view -> {
startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
});
// Administration
if (groupVM.getIsCanEditAdministration().get() || groupVM.getIsCanDelete().get()) {
administrationAction.setOnClickListener(view -> {
startActivity(new Intent(getActivity(), GroupAdminActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
});
} else {
administrationAction.setVisibility(View.GONE);
}
// Async Members
// Showing member only when members available and async members is enabled
bind(groupVM.getIsCanViewMembers(), groupVM.getIsAsyncMembers(), (canViewMembers, vm1, isAsync, vm2) -> {
if (canViewMembers) {
if (isAsync) {
members.setVisibility(View.VISIBLE);
header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
} else {
members.setVisibility(View.GONE);
header.findViewById(R.id.after_settings_divider).setVisibility(View.VISIBLE);
}
} else {
members.setVisibility(View.GONE);
header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
}
});
members.setOnClickListener(view -> {
startActivity(new Intent(getContext(), MembersActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupVM.getId()));
});
// Leave
bind(groupVM.getIsCanLeave(), canLeave -> {
if (canLeave) {
leaveAction.setVisibility(View.VISIBLE);
leaveAction.setOnClickListener(view1 -> {
new AlertDialog.Builder(getActivity()).setMessage(getString(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.alert_leave_channel_message : R.string.alert_leave_group_message).replace("%1$s", groupVM.getName().get())).setPositiveButton(R.string.alert_leave_group_yes, (dialog2, which) -> {
execute(messenger().leaveAndDeleteGroup(chatId).then(aVoid -> ActorSDK.returnToRoot(getActivity())));
}).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
});
} else {
leaveAction.setVisibility(View.GONE);
}
});
listView.addHeaderView(header, null, false);
//
// Members
//
groupUserAdapter = new MembersAdapter(getActivity(), getArguments().getInt("groupId"));
listView.setAdapter(groupUserAdapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
Object item = parent.getItemAtPosition(position);
if (item != null && item instanceof GroupMember) {
GroupMember groupMember = (GroupMember) item;
if (groupMember.getUid() != myUid()) {
UserVM userVM = users().get(groupMember.getUid());
if (userVM != null) {
startActivity(Intents.openPrivateDialog(userVM.getId(), true, getActivity()));
}
}
}
});
listView.setOnItemLongClickListener((adapterView, view, i, l) -> {
Object item = adapterView.getItemAtPosition(i);
if (item != null && item instanceof GroupMember) {
GroupMember groupMember = (GroupMember) item;
if (groupMember.getUid() != myUid()) {
UserVM userVM = users().get(groupMember.getUid());
if (userVM != null) {
groupUserAdapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
return true;
}
}
}
return false;
});
//
// Scroll handling
//
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (firstVisibleItem >= 1) {
updateBar(Integer.MAX_VALUE);
} else {
View top = listView.getChildAt(0);
if (top != null) {
updateBar(-top.getTop());
} else {
updateBar(Integer.MAX_VALUE);
}
}
}
});
//
// Placeholder
//
bind(groupVM.isMember(), (isMember) -> {
notMemberView.setVisibility(isMember ? View.GONE : View.VISIBLE);
getActivity().invalidateOptionsMenu();
});
// Menu
bind(groupVM.getIsCanEditInfo(), canEditInfo -> {
getActivity().invalidateOptionsMenu();
});
return res;
}
use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class RouterActor method onMessageRead.
//
// Read States
//
private Promise<Void> onMessageRead(Peer peer, long date) {
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
boolean isChanged = false;
Promise<Void> res;
if (date > state.getOutReadDate()) {
state = state.changeOutReadDate(date);
res = getDialogsRouter().onPeerReadChanged(peer, date);
isChanged = true;
} else {
res = Promise.success(null);
}
if (date > state.getOutReceiveDate()) {
state = state.changeOutReceiveDate(date);
isChanged = true;
}
if (isChanged) {
conversationStates.addOrUpdateItem(state);
}
return res;
}
use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class RouterActor method preStart.
@Override
public void preStart() {
super.preStart();
conversationStates = context().getMessagesModule().getConversationStates().getEngine();
//
// Loading Active Dialogs
//
activeDialogStorage = new ActiveDialogStorage();
byte[] data = context().getStorageModule().getBlobStorage().loadItem(AbsModule.BLOB_DIALOGS_ACTIVE);
if (data != null) {
try {
activeDialogStorage = new ActiveDialogStorage(data);
} catch (IOException e) {
e.printStackTrace();
}
}
if (!activeDialogStorage.isLoaded()) {
api(new RequestLoadGroupedDialogs(ApiSupportConfiguration.OPTIMIZATIONS)).chain(r -> updates().applyRelatedData(r.getUsers(), r.getGroups())).chain(r -> updates().loadRequiredPeers(r.getUserPeers(), r.getGroupPeers())).then(r -> {
boolean showArchived = false;
boolean showInvite = false;
if (r.showArchived() != null) {
showArchived = r.showArchived();
}
if (r.showInvite() != null) {
showInvite = r.showInvite();
}
onActiveDialogsChanged(r.getDialogs(), showArchived, showInvite);
context().getConductor().getConductor().onDialogsLoaded();
});
} else {
notifyActiveDialogsVM();
context().getConductor().getConductor().onDialogsLoaded();
}
}
use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class RouterActor method onNewMessages.
//
// Incoming Messages
//
private Promise<Void> onNewMessages(Peer peer, List<Message> messages) {
assertTrue(messages.size() != 0);
boolean isConversationVisible = isConversationVisible(peer);
//
// Collecting Information
//
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
Message topMessage = null;
int unreadCount = 0;
long maxInReadDate = 0;
long maxInDate = 0;
for (Message m : messages) {
if (topMessage == null || topMessage.getSortDate() < m.getSortDate()) {
topMessage = m;
}
if (m.getSenderId() != myUid()) {
if (m.getSortDate() > state.getInReadDate()) {
unreadCount++;
maxInReadDate = Math.max(maxInReadDate, m.getSortDate());
}
if (m.getSortDate() > state.getInMaxMessageDate()) {
maxInDate = Math.max(maxInDate, m.getSortDate());
}
}
}
//
// Writing to Conversation
//
conversation(peer).addOrUpdateItems(messages);
//
// Update Chat State
//
updateChatState(peer);
//
// Updating Counter
//
boolean isRead = false;
if (unreadCount != 0) {
if (isConversationVisible) {
// Auto Reading message
boolean needUpdateState = false;
if (maxInReadDate > 0) {
if (state.getInReadDate() < maxInReadDate) {
state = state.changeInReadDate(maxInReadDate);
}
state = state.changeCounter(0);
context().getMessagesModule().getPlainReadActor().send(new CursorReaderActor.MarkRead(peer, maxInReadDate));
context().getNotificationsModule().onOwnRead(peer, maxInReadDate);
isRead = true;
needUpdateState = true;
}
if (state.getInMaxMessageDate() < maxInDate) {
state.changeInMaxDate(maxInDate);
needUpdateState = true;
}
if (needUpdateState) {
conversationStates.addOrUpdateItem(state);
}
} else {
// Updating counter
state = state.changeCounter(state.getUnreadCount() + unreadCount);
if (state.getInMaxMessageDate() < maxInDate) {
state = state.changeInMaxDate(maxInDate);
}
conversationStates.addOrUpdateItem(state);
notifyActiveDialogsVM();
}
}
//
if (maxInReadDate > 0 && !isRead) {
context().getMessagesModule().getPlainReceiverActor().send(new CursorReceiverActor.MarkReceived(peer, maxInReadDate));
}
//
// Updating Dialog List
//
Promise<Void> res = getDialogsRouter().onMessage(peer, topMessage, state.getUnreadCount());
//
if (!isConversationVisible) {
for (Message m : messages) {
if (m.getSenderId() != myUid()) {
boolean hasCurrentMention = false;
if (m.getContent() instanceof TextContent) {
if (((TextContent) m.getContent()).getMentions().contains(myUid())) {
hasCurrentMention = true;
}
}
int messagesCount = 0;
int dialogsCount = 0;
for (Peer activePeer : activeDialogStorage.getAllPeers()) {
int activeDialogueUnreadCount = conversationStates.getValue(activePeer.getUnuqueId()).getUnreadCount();
if (activeDialogueUnreadCount > 0) {
dialogsCount++;
messagesCount += activeDialogueUnreadCount;
}
}
context().getNotificationsModule().onInMessage(peer, m.getSenderId(), m.getSortDate(), ContentDescription.fromContent(m.getContent()), hasCurrentMention, messagesCount, dialogsCount);
}
}
}
return res;
}
Aggregations