Search in sources :

Example 1 with GroupViewModel

use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.

the class ConversationViewHolder method onBind.

public void onBind(ConversationInfo conversationInfo) {
    secretChatIndicator.setVisibility(View.GONE);
    onBindConversationInfo(conversationInfo);
    timeTextView.setText(TimeUtils.getMsgFormatTime(conversationInfo.timestamp));
    silentImageView.setVisibility(conversationInfo.isSilent ? View.VISIBLE : View.GONE);
    statusImageView.setVisibility(View.GONE);
    itemView.setBackgroundResource(conversationInfo.isTop ? R.drawable.selector_stick_top_item : R.drawable.selector_common_item);
    redDotView.setVisibility(View.GONE);
    if (conversationInfo.isSilent) {
        if (conversationInfo.unreadCount.unread > 0) {
            // 显示红点
            unreadCountTextView.setText("");
            unreadCountTextView.setVisibility(View.GONE);
            redDotView.setVisibility(View.VISIBLE);
        } else {
            unreadCountTextView.setVisibility(View.GONE);
        }
    } else {
        if (conversationInfo.unreadCount.unread > 0) {
            unreadCountTextView.setVisibility(View.VISIBLE);
            unreadCountTextView.setText(conversationInfo.unreadCount.unread > 99 ? "99+" : conversationInfo.unreadCount.unread + "");
        } else {
            unreadCountTextView.setVisibility(View.GONE);
        }
    }
    Draft draft = Draft.fromDraftJson(conversationInfo.draft);
    if (draft != null) {
        String draftString = draft.getContent() != null ? draft.getContent() : "[草稿]";
        MoonUtils.identifyFaceExpression(fragment.getActivity(), contentTextView, draft.getContent(), ImageSpan.ALIGN_BOTTOM);
        setViewVisibility(R.id.promptTextView, View.VISIBLE);
        setViewVisibility(R.id.contentTextView, View.VISIBLE);
    } else {
        if (conversationInfo.unreadCount.unreadMentionAll > 0 || conversationInfo.unreadCount.unreadMention > 0) {
            promptTextView.setText("[有人@我]");
            promptTextView.setVisibility(View.VISIBLE);
        } else {
            promptTextView.setVisibility(View.GONE);
        }
        setViewVisibility(R.id.contentTextView, View.VISIBLE);
        if (conversationInfo.lastMessage != null && conversationInfo.lastMessage.content != null) {
            String content = "";
            Message lastMessage = conversationInfo.lastMessage;
            // the message maybe invalid
            try {
                if (conversationInfo.conversation.type == Conversation.ConversationType.Group && lastMessage.direction == MessageDirection.Receive && !(lastMessage.content instanceof NotificationMessageContent)) {
                    GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class);
                    String senderDisplayName = groupViewModel.getGroupMemberDisplayName(conversationInfo.conversation.target, conversationInfo.lastMessage.sender);
                    content = senderDisplayName + ":" + lastMessage.digest();
                } else {
                    content = lastMessage.digest();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            content = WfcTextUtils.htmlToText(content);
            MoonUtils.identifyFaceExpression(fragment.getActivity(), contentTextView, content, ImageSpan.ALIGN_BOTTOM);
            switch(lastMessage.status) {
                case Sending:
                    statusImageView.setVisibility(View.VISIBLE);
                    // TODO update sending image resource
                    statusImageView.setImageResource(R.mipmap.ic_sending);
                    break;
                case Send_Failure:
                    statusImageView.setVisibility(View.VISIBLE);
                    statusImageView.setImageResource(R.mipmap.img_error);
                    break;
                default:
                    statusImageView.setVisibility(View.GONE);
                    break;
            }
        } else {
            contentTextView.setText("");
        }
    }
}
Also used : Draft(cn.wildfire.chat.kit.conversation.Draft) Message(cn.wildfirechat.message.Message) GroupViewModel(cn.wildfire.chat.kit.group.GroupViewModel) NotificationMessageContent(cn.wildfirechat.message.notification.NotificationMessageContent)

Example 2 with GroupViewModel

use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.

the class NormalMessageContentViewHolder method contextMenuItemFilter.

@Override
public boolean contextMenuItemFilter(UiMessage uiMessage, String tag) {
    Message message = uiMessage.message;
    if (message.conversation.type == Conversation.ConversationType.SecretChat) {
        if (MessageContextMenuItemTags.TAG_FORWARD.equals(tag)) {
            return true;
        }
        if (MessageContextMenuItemTags.TAG_FAV.equals(tag)) {
            return true;
        }
        return false;
    }
    if (MessageContextMenuItemTags.TAG_RECALL.equals(tag)) {
        String userId = ChatManager.Instance().getUserId();
        if (message.conversation.type == Conversation.ConversationType.Group) {
            GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class);
            GroupInfo groupInfo = groupViewModel.getGroupInfo(message.conversation.target, false);
            if (groupInfo != null && userId.equals(groupInfo.owner)) {
                return false;
            }
            GroupMember groupMember = groupViewModel.getGroupMember(message.conversation.target, ChatManager.Instance().getUserId());
            if (groupMember != null && (groupMember.type == GroupMember.GroupMemberType.Manager || groupMember.type == GroupMember.GroupMemberType.Owner)) {
                return false;
            }
        }
        long delta = ChatManager.Instance().getServerDeltaTime();
        long now = System.currentTimeMillis();
        if (message.direction == MessageDirection.Send && TextUtils.equals(message.sender, ChatManager.Instance().getUserId()) && now - (message.serverTime - delta) < Config.RECALL_TIME_LIMIT * 1000) {
            return false;
        } else {
            return true;
        }
    }
    // 只有channel 主可以发起
    if (MessageContextMenuItemTags.TAG_CHANEL_PRIVATE_CHAT.equals(tag)) {
        if (uiMessage.message.conversation.type == Conversation.ConversationType.Channel && uiMessage.message.direction == MessageDirection.Receive) {
            return false;
        }
        return true;
    }
    // 只有部分消息支持引用
    if (MessageContextMenuItemTags.TAG_QUOTE.equals(tag)) {
        MessageContent messageContent = message.content;
        if (messageContent instanceof TextMessageContent || messageContent instanceof FileMessageContent || messageContent instanceof VideoMessageContent || messageContent instanceof StickerMessageContent || messageContent instanceof ImageMessageContent) {
            return false;
        }
        return true;
    }
    // 只有部分消息支持收藏
    if (MessageContextMenuItemTags.TAG_FAV.equals(tag)) {
        MessageContent messageContent = message.content;
        if (messageContent instanceof TextMessageContent || messageContent instanceof FileMessageContent || messageContent instanceof CompositeMessageContent || messageContent instanceof VideoMessageContent || messageContent instanceof SoundMessageContent || messageContent instanceof ImageMessageContent) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : GroupMember(cn.wildfirechat.model.GroupMember) ImageMessageContent(cn.wildfirechat.message.ImageMessageContent) StickerMessageContent(cn.wildfirechat.message.StickerMessageContent) FileMessageContent(cn.wildfirechat.message.FileMessageContent) SoundMessageContent(cn.wildfirechat.message.SoundMessageContent) VideoMessageContent(cn.wildfirechat.message.VideoMessageContent) MessageContent(cn.wildfirechat.message.MessageContent) CallStartMessageContent(cn.wildfirechat.message.CallStartMessageContent) CompositeMessageContent(cn.wildfirechat.message.CompositeMessageContent) TextMessageContent(cn.wildfirechat.message.TextMessageContent) StickerMessageContent(cn.wildfirechat.message.StickerMessageContent) Message(cn.wildfirechat.message.Message) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) GroupInfo(cn.wildfirechat.model.GroupInfo) ImageMessageContent(cn.wildfirechat.message.ImageMessageContent) CompositeMessageContent(cn.wildfirechat.message.CompositeMessageContent) FileMessageContent(cn.wildfirechat.message.FileMessageContent) SoundMessageContent(cn.wildfirechat.message.SoundMessageContent) GroupViewModel(cn.wildfire.chat.kit.group.GroupViewModel) TextMessageContent(cn.wildfirechat.message.TextMessageContent) VideoMessageContent(cn.wildfirechat.message.VideoMessageContent)

Example 3 with GroupViewModel

use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.

the class ForwardActivity method afterViews.

@Override
protected void afterViews() {
    super.afterViews();
    messages = getIntent().getParcelableArrayListExtra("messages");
    if (messages == null || messages.isEmpty()) {
        Message message = getIntent().getParcelableExtra("message");
        if (message != null) {
            messages = new ArrayList<>();
            messages.add(message);
        }
    }
    if (messages == null || messages.isEmpty()) {
        finish();
    }
    forwardViewModel = ViewModelProviders.of(this).get(ForwardViewModel.class);
    userViewModel = ViewModelProviders.of(this).get(UserViewModel.class);
    groupViewModel = ViewModelProviders.of(this).get(GroupViewModel.class);
}
Also used : Message(cn.wildfirechat.message.Message) UserViewModel(cn.wildfire.chat.kit.user.UserViewModel) GroupViewModel(cn.wildfire.chat.kit.group.GroupViewModel)

Example 4 with GroupViewModel

use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.

the class ConversationInputPanel method mentionGroupMember.

private void mentionGroupMember() {
    Intent intent = new Intent(activity, MentionGroupMemberActivity.class);
    GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class);
    GroupInfo groupInfo = groupViewModel.getGroupInfo(conversation.target, false);
    intent.putExtra("groupInfo", groupInfo);
    fragment.startActivityForResult(intent, REQUEST_PICK_MENTION_CONTACT);
}
Also used : GroupInfo(cn.wildfirechat.model.GroupInfo) Intent(android.content.Intent) GroupViewModel(cn.wildfire.chat.kit.group.GroupViewModel)

Example 5 with GroupViewModel

use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.

the class PickOrCreateConversationTargetActivity method onContactPicked.

@Override
protected void onContactPicked(List<UIUserInfo> newlyCheckedUserInfos) {
    if (singleMode && newlyCheckedUserInfos.size() > 1) {
        // 先创建群组
        MaterialDialog dialog = new MaterialDialog.Builder(this).content("创建中...").progress(true, 100).build();
        dialog.show();
        List<UserInfo> userInfos = new ArrayList<>();
        for (UIUserInfo info : newlyCheckedUserInfos) {
            userInfos.add(info.getUserInfo());
        }
        GroupViewModel groupViewModel = ViewModelProviders.of(this).get(GroupViewModel.class);
        groupViewModel.createGroup(this, userInfos, null, Arrays.asList(0)).observe(this, new Observer<OperateResult<String>>() {

            @Override
            public void onChanged(@Nullable OperateResult<String> result) {
                dialog.dismiss();
                if (result.isSuccess()) {
                    GroupInfo groupInfo = groupViewModel.getGroupInfo(result.getResult(), false);
                    Intent intent = new Intent();
                    intent.putExtra("groupInfo", groupInfo);
                    setResult(RESULT_OK, intent);
                    finish();
                } else {
                    Toast.makeText(PickOrCreateConversationTargetActivity.this, "create group error", Toast.LENGTH_SHORT).show();
                }
            }
        });
    } else {
        Intent intent = new Intent();
        intent.putExtra("userInfo", newlyCheckedUserInfos.get(0).getUserInfo());
        setResult(RESULT_OK, intent);
        finish();
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) GroupInfo(cn.wildfirechat.model.GroupInfo) ArrayList(java.util.ArrayList) UIUserInfo(cn.wildfire.chat.kit.contact.model.UIUserInfo) UserInfo(cn.wildfirechat.model.UserInfo) Intent(android.content.Intent) UIUserInfo(cn.wildfire.chat.kit.contact.model.UIUserInfo) OperateResult(cn.wildfire.chat.kit.common.OperateResult) GroupViewModel(cn.wildfire.chat.kit.group.GroupViewModel)

Aggregations

GroupViewModel (cn.wildfire.chat.kit.group.GroupViewModel)12 GroupInfo (cn.wildfirechat.model.GroupInfo)5 Intent (android.content.Intent)3 UIUserInfo (cn.wildfire.chat.kit.contact.model.UIUserInfo)3 UserViewModel (cn.wildfire.chat.kit.user.UserViewModel)3 Message (cn.wildfirechat.message.Message)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 ArrayList (java.util.ArrayList)3 OperateResult (cn.wildfire.chat.kit.common.OperateResult)2 UserInfo (cn.wildfirechat.model.UserInfo)2 List (java.util.List)2 SharedPreferences (android.content.SharedPreferences)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 Toast (android.widget.Toast)1 Observer (androidx.lifecycle.Observer)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 ViewModelProviders (androidx.lifecycle.ViewModelProviders)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 SimpleItemAnimator (androidx.recyclerview.widget.SimpleItemAnimator)1