Search in sources :

Example 11 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class XmppService method parseBody.

private ChatMsg parseBody(Message msg) throws Exception {
    JSONObject obj = new JSONObject(msg.getBody());
    ChatMsg chatmsg = new ChatMsg().parse(obj);
    chatmsg.setChatId(msg.getFrom().split("@")[0]);
    if (msg.getMsgtype() == MsgType.system && chatmsg.getType() == 500) {
        chatmsg.setChatId(chatmsg.getUserId());
    }
    String server_name = msg.getFrom().split("@")[1];
    if (server_name.contains("/")) {
        int end = server_name.indexOf("/");
        server_name = server_name.substring(0, end);
    }
    // If your group chat live news userid domain not group system
    boolean isGroupNormalOrSystemMsg = false;
    if (server_name.startsWith("super_group.") || server_name.startsWith("group.")) {
        isGroupNormalOrSystemMsg = true;
    }
    if (server_name.startsWith("super_group.")) {
        // Group special processing, it is necessary to remove super_group.
        server_name = server_name.replace("super_group.", "");
    }
    if (!TextUtils.isEmpty(server_name) && !server_name.contains(XmppUtils.SERVER_NAME)) {
        chatmsg.setChatId(chatmsg.getChatId() + "@" + server_name);
        if (// The group messages or group system, the userid and the from same domain
        !isGroupNormalOrSystemMsg && !TextUtils.isEmpty(chatmsg.getUserId())) {
            chatmsg.setUserId(chatmsg.getUserId() + "@" + server_name);
        }
        chatmsg.setFriendLog(1);
    }
    if (// Groups, and discussion groups will use, labeled message domain users may source and groups
    !TextUtils.isEmpty(chatmsg.getUsersource()) && !chatmsg.getUsersource().equals(XmppUtils.SERVER_NAME)) {
        // Due to the above code, for cross domain group or group chat may userid has spliced into xxx@juejian.net but the message does not necessarily and group users of the domain name
        String[] uids = chatmsg.getUserId().split("@");
        if (uids.length > 0) {
            chatmsg.setUserId(uids[0] + "@" + chatmsg.getUsersource());
        } else {
            chatmsg.setUserId(chatmsg.getUserId() + "@" + chatmsg.getUsersource());
        }
    }
    chatmsg.setMsgTime(msg.getMsgTime() / 1000);
    chatmsg.setMessageId(msg.getPacketID());
    chatmsg.setUnread(1);
    return chatmsg;
}
Also used : JSONObject(org.json.JSONObject) SuppressLint(android.annotation.SuppressLint) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 12 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class XmppService method parseGroupChat.

/**
 * Group chat with
 */
private ChatMsg parseGroupChat(Message msg, boolean isGroupSystem) {
    if (!TextUtils.isEmpty(msg.getBody())) {
        try {
            String content = null;
            ChatMsg chatmsg = parseBody(msg);
            chatmsg.setMsgType(msg.getMsgtype());
            String[] uids = chatmsg.getChatId().split("@");
            chatmsg.setChatId("group-" + chatmsg.getGroupId());
            if (uids.length > 1) {
                chatmsg.setChatId(chatmsg.getChatId() + "@" + uids[1]);
            }
            chatmsg.setGroup(true);
            if (chatmsg.getType() == 10000) {
                // Offline message
                new Thread(new HandleOfflineMsgList(chatmsg, MsgType.groupchat)).start();
                return chatmsg;
            } else if (!isGroupSystem) {
                // Is not a group of notice
                if (!checkChatType(chatmsg.getType())) {
                    chatmsg.setType(50000);
                }
                switch(chatmsg.getType()) {
                    case // Share the news
                    13:
                        chatmsg.setType(103);
                        content = chatmsg.getContent();
                        break;
                    case // file
                    19:
                        chatmsg.setInviteType(4);
                        chatmsg.setType(1009);
                        break;
                    case // Not compatible with high version of the news
                    50000:
                        chatmsg.setContent(chatmsg.getMsgName());
                        break;
                }
            } else {
                // Is a group of notification
                if (chatmsg.getType() == 12 || chatmsg.getType() == 13) {
                    // Invited to join the group chat message by default
                    if (!TextUtils.isEmpty(chatmsg.getInviteName())) {
                        chatmsg.setContent(getString(R.string.discuss_group_invite, chatmsg.getInviteName()));
                    } else {
                        chatmsg.setContent(getString(R.string.discuss_group_invite_default));
                    }
                } else if (chatmsg.getType() == 14) {
                    chatmsg.setContent(getString(R.string.discuss_group_kick));
                } else if (chatmsg.getType() == 15) {
                    chatmsg.setContent(getString(R.string.discuss_group_dismiss));
                } else if (chatmsg.getType() == 17) {
                    // Modify the multiplayer session name
                    chatmsg.setContent(getString(R.string.discuss_group_rename, chatmsg.getGroupName()));
                } else if (chatmsg.getType() == 18) {
                    // Someone quit the multiplayer session
                    chatmsg.setContent(getString(R.string.discuss_group_outside, chatmsg.getUsername()));
                }
                try {
                    MySharedPrefs.writeBoolean(NextApplication.mContext, MySharedPrefs.FILE_USER, MySharedPrefs.IS_MASK_MSG + NextApplication.myInfo.getLocalId() + "_" + chatmsg.getChatId(), chatmsg.getGroupMask());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                chatmsg.setDismissGroup(chatmsg.getType() == 15);
                chatmsg.setKickGroup(chatmsg.getType() == 14);
                Bundle bundle = new Bundle();
                bundle.putString("uid", chatmsg.getChatId());
                bundle.putBoolean("dismissgroup", chatmsg.isDismissGroup());
                bundle.putBoolean("kickgroup", chatmsg.isKickGroup());
                Utils.intentAction(getApplicationContext(), XmppAction.ACTION_MESSAGE_GROUP_KICK_LISTENER, bundle);
            }
            StringBuilder url = new StringBuilder();
            if (chatmsg.getMemberAvatarList() != null) {
                for (GroupMemberAvatarVo vo : chatmsg.getMemberAvatarList()) {
                    url.append(vo.getImage()).append("___").append(vo.getGender()).append("#");
                }
                url.deleteCharAt(url.lastIndexOf("#"));
            }
            final String avatarUrl = chatmsg.getUserImage();
            String uName = chatmsg.getUsername();
            if (isGroupSystem) {
                // Is the information system is not to judge whether time display
                FinalUserDataBase.getInstance().saveChatMsg(chatmsg, chatmsg.getChatId(), chatmsg.getGroupName(), url.toString(), false);
            } else {
                // Is not the system information is normal
                FinalUserDataBase.getInstance().saveChatMsg(chatmsg, chatmsg.getChatId(), chatmsg.getGroupName(), url.toString());
            }
            chatmsg.setUsername(uName);
            chatmsg.setUserImage(avatarUrl);
            if (chatmsg.getType() == 103 && !TextUtils.isEmpty(content)) {
                chatmsg.setContent(content);
            }
            Bundle bundle = new Bundle();
            bundle.putSerializable(XmppAction.ACTION_MESSAGE_LISTENER, chatmsg);
            Utils.intentAction(getApplicationContext(), XmppAction.ACTION_MESSAGE_LISTENER, bundle);
            if (chatmsg.getType() == 2) {
                // Download the audio files
                Bundle downloadBundle = new Bundle();
                downloadBundle.putString("uid", chatmsg.getChatId());
                downloadBundle.putString("username", chatmsg.getUsername());
                downloadBundle.putString("avatarurl", chatmsg.getUserImage());
                downloadBundle.putSerializable("chatmsg", chatmsg);
                Utils.intentService(getApplicationContext(), LoadDataService.class, LoadDataService.ACTION_FILE_DOWNLOAD, LoadDataService.ACTION_FILE_DOWNLOAD, downloadBundle);
            }
            chatmsg.setUserImage(url.toString());
            if (chatmsg.getType() == 103 && !TextUtils.isEmpty(content)) {
                chatmsg.setContent(chatmsg.getShareTitle());
            }
            return chatmsg;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : Bundle(android.os.Bundle) ChatMsg(com.lingtuan.firefly.vo.ChatMsg) LoginThread(com.lingtuan.firefly.xmpp.LoginThread) GroupMemberAvatarVo(com.lingtuan.firefly.contact.vo.GroupMemberAvatarVo)

Example 13 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ChatFileInfoUI method onClick.

@Override
public void onClick(View v) {
    super.onClick(v);
    switch(v.getId()) {
        case R.id.bottom_left_btn:
            if (isOffLine) {
                File file = new File(fileUrl);
                openFile(file);
            } else {
                if (state == 1 || state == 3) {
                    // Failed to upload or cancel the upload
                    /**
                     ********Send a broadcast to the chat interface, update the transfer status and upload a file again**************
                     */
                    sendBroadcast(msgid, 0, Constants.ACTION_START_UPLOAD_FILE);
                    state = 0;
                    resetView();
                } else if (state == 2) {
                    // Uploaded successfully
                    if (!TextUtils.isEmpty(localUrl)) {
                        File file = new File(localUrl);
                        openFile(file);
                    } else {
                        showToast(getString(R.string.chat_file_deleted));
                    }
                } else if (state == 4 || state == 6 || state == 8) {
                    // Did not download or failed to download or cancel the download
                    /**
                     ********step1: To download the logic**************
                     */
                    final Bundle bundle = new Bundle();
                    bundle.putString("url", fileUrl);
                    bundle.putString("msgid", msgid);
                    bundle.putString("fileid", fileId);
                    bundle.putBoolean("isGroupOrFavFile", isGroupOrFavFile);
                    Utils.intentServiceAction(this, LoadDataService.ACTION_DOWNLOAD_CHAT_FILE, bundle);
                    /**
                     ********step2: Send a broadcast to the chat interface, update the transfer status**************
                     */
                    sendBroadcast(msgid, 5, Constants.ACTION_START_DOWNLOAD_FILE);
                    state = 5;
                    resetView();
                } else if (state == 7) {
                    // Download successful
                    if (!TextUtils.isEmpty(localUrl)) {
                        File file = new File(localUrl);
                        openFile(file);
                    }
                }
            }
            break;
        case R.id.bottom_right_btn:
            if (isOffLine) {
                // Offline files
                if (state == -1 || state == 0) {
                    // Is waiting for receiving the sender
                    state = 3;
                    sendBroadcast(msgid, 2, Constants.MSG_REPORT_CANCEL_SEND_FILE);
                } else if (state == 4) {
                    // Did not download the receiver
                    state = 5;
                    sendBroadcast(msgid, 0, Constants.MSG_REPORT_START_RECV_FILE);
                } else if (state == 5) {
                    // Receive in the receiver
                    state = 8;
                    sendBroadcast(msgid, 1, Constants.MSG_REPORT_CANCEL_RECV_FILE);
                }
                resetOffLineView();
            } else {
                if (state == 0 || state == 1 || state == 3) {
                    showToast(getString(R.string.fav_file_warning));
                    return;
                }
                if (collectState == 0) {
                    // Not to collect
                    requestToCollectFile();
                } else {
                    // Already collected
                    CancelCollectFile();
                }
            }
            break;
        case // Cancel the upload or download
        R.id.img_cancel:
            if (state == 0) {
                // On the cross
                /**
                 ********step1: Cancel the upload logic**************
                 */
                final Bundle bundle = new Bundle();
                bundle.putString("chatid", chatid);
                bundle.putString("msgid", msgid);
                Utils.intentServiceAction(this, LoadDataService.ACTION_CANCEL_UPLOAD_CHAT_FILE, bundle);
                sendBroadcast(msgid, 3, Constants.ACTION_CANCEL_UPLOAD_FILE);
                state = 3;
                resetView();
            /**
             ********step2: Send a broadcast to the chat interface, update the transfer status**************
             */
            } else if (state == 5) {
                // 下载中
                final Bundle bundle = new Bundle();
                bundle.putString("url", fileUrl);
                Utils.intentServiceAction(this, LoadDataService.ACTION_CANCEL_DOWNLOAD_CHAT_FILE, bundle);
                sendBroadcast(msgid, 8, Constants.ACTION_CANCEL_DOWNLOAD_FILE);
                state = 8;
                resetView();
            }
            break;
        case // forwarding
        R.id.bottom_middle_btn:
            ArrayList<ChatMsg> list = new ArrayList<>();
            /**
             **************************************
             */
            ChatMsg chatMsg = new ChatMsg();
            chatMsg.setType(1009);
            chatMsg.setShareTitle(name);
            chatMsg.setNumber(number + "");
            chatMsg.setLocalUrl(localUrl);
            chatMsg.setContent(TextUtils.isEmpty(fileUrl) ? localUrl : fileUrl);
            chatMsg.setInviteType(state);
            chatMsg.setMsgName(getString(R.string.chatting_file));
            chatMsg.setCreateTime(msgTime);
            chatMsg.setThirdId(fileId);
            chatMsg.parseUserBaseVo(NextApplication.myInfo.getUserBaseVo());
            /**
             **************************************
             */
            list.add(chatMsg);
            Intent intent = new Intent(this, ContactSelectedUI.class);
            intent.putExtra("msglist", list);
            intent.putExtra("needClose", true);
            startActivity(intent);
            Utils.openNewActivityAnim(this, false);
            break;
    }
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) File(java.io.File) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 14 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ChatReportReasonUI method sendReportChatMsg.

private void sendReportChatMsg() {
    if (TextUtils.isEmpty(buid)) {
        return;
    }
    if (TextUtils.equals("-1", seven) && TextUtils.equals("-1", eight) && TextUtils.equals("-1", nine) && TextUtils.equals("-1", ten) && TextUtils.equals("-1", eleven)) {
        showToast(getResources().getString(R.string.report_reason_choice));
        return;
    }
    StringBuilder sb = new StringBuilder();
    sb.append(seven);
    sb.append(",");
    sb.append(eight);
    sb.append(",");
    sb.append(nine);
    sb.append(",");
    sb.append(ten);
    sb.append(",");
    sb.append(eleven);
    sb.append(",");
    String replace0String = sb.toString().replace("-1,", "");
    type = replace0String.substring(0, replace0String.length() - 1);
    if (msgList == null) {
        showToast(getResources().getString(R.string.chat_please_choice_msg));
        return;
    }
    /**
     * Chat logs together
     */
    ChatMsg cmBuild = new ChatMsg();
    String contentString = cmBuild.parseChatMsgListToJsonString(msgList);
    if (TextUtils.isEmpty(contentString)) {
        showToast(getResources().getString(R.string.chat_please_choice_msg));
        return;
    }
    NetRequestImpl.getInstance().sendReportChatMsg(type, buid, contentString, new RequestListener() {

        @Override
        public void start() {
            if (mProgressDialog == null) {
                mProgressDialog = LoadingDialog.showDialog(ChatReportReasonUI.this, null, getString(R.string.chatting_sending_two));
            }
        }

        @Override
        public void success(JSONObject response) {
            if (mProgressDialog != null) {
                mProgressDialog.dismiss();
            }
            showToast(response.optString("msg"));
            setResult(RESULT_OK);
            Utils.exitActivityAndBackAnim(ChatReportReasonUI.this, true);
        }

        @Override
        public void error(int errorCode, String errorMsg) {
            if (mProgressDialog != null) {
                mProgressDialog.dismiss();
            }
            showToast(errorMsg);
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 15 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ChatHistoryUI method initData.

@Override
protected void initData() {
    swipeLayout.setColorSchemeResources(R.color.black);
    setTitle(getResources().getString(R.string.report_chat_title));
    mRightBtn.setText(getResources().getString(R.string.submit));
    mRightBtn.setVisibility(View.VISIBLE);
    ChattingManager.getInstance(this).destory();
    chattingManager = ChattingManager.getInstance(this);
    List<ChatMsg> mList = FinalUserDataBase.getInstance().getChatMsgListByChatId(buid, 0, 20);
    mAdapter = new ChatAdapter(mList, this, null, listView);
    chattingManager.setUserInfo(userName, avatarUrl, buid, mAdapter, listView);
    mAdapter.addSelectedList(selectedList, true);
    listView.setAdapter(mAdapter);
    listView.setSelection(mList.size());
}
Also used : ChatAdapter(com.lingtuan.firefly.chat.adapter.ChatAdapter) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Aggregations

ChatMsg (com.lingtuan.firefly.vo.ChatMsg)61 Bundle (android.os.Bundle)17 Intent (android.content.Intent)12 ArrayList (java.util.ArrayList)11 UserBaseVo (com.lingtuan.firefly.vo.UserBaseVo)9 Cursor (android.database.Cursor)8 SuppressLint (android.annotation.SuppressLint)6 WifiPeopleVO (com.lingtuan.firefly.offline.vo.WifiPeopleVO)5 View (android.view.View)4 ImageView (android.widget.ImageView)4 GroupMemberAvatarVo (com.lingtuan.firefly.contact.vo.GroupMemberAvatarVo)4 PendingIntent (android.app.PendingIntent)3 TextView (android.widget.TextView)3 MyDialogFragment (com.lingtuan.firefly.util.MyDialogFragment)3 LoginThread (com.lingtuan.firefly.xmpp.LoginThread)3 File (java.io.File)3 JSONObject (org.json.JSONObject)3 Bitmap (android.graphics.Bitmap)2 Message (android.os.Message)2 Editable (android.text.Editable)2