bool MsgBubbleSnapChat::OnClicked(ui::EventArgs* arg)
{
	//如果是阅后即焚,则需要先下载好图片
	Json::Value json;
	if (StringToJson(msg_.attach_, json))
	{
		std::string url = json["data"]["url"].asString();
		if (nbase::FilePathIsExist(src_image_path_, false)) {
			ImageViewManager::GetInstance()->StartViewPic(src_image_path_, L"", true, true);
			nim::MsgLog::DeleteAsync(sid_, type_, msg_.client_msg_id_, nim::MsgLog::DeleteCallback());
			SessionBox* session = dynamic_cast<SessionBox*>(SessionManager::GetInstance()->FindSessionBox(sid_));
			if (session)
				session->OnSnapchatReadCallback(msg_.client_msg_id_);
		}
		else {
			nim::NOS::DownloadResource(url, ToWeakCallback([this](int res_code, const std::string& file_path, const std::string& call_id, const std::string& res_id) {
				if (res_code == nim::kNIMResSuccess)
				{
					std::wstring ws_file_path = nbase::UTF8ToUTF16(file_path);
					if (nbase::FilePathIsExist(ws_file_path, false))
					{
						ImageViewManager::GetInstance()->StartViewPic(ws_file_path, L"", true, true);
						nim::MsgLog::DeleteAsync(sid_, type_, msg_.client_msg_id_, nim::MsgLog::DeleteCallback());
						SessionBox* session_form = dynamic_cast<SessionBox*>(SessionManager::GetInstance()->FindSessionBox(sid_));
						if (session_form)
							session_form->OnSnapchatReadCallback(msg_.client_msg_id_);
					}
				}
			}));
		}
	}

	return true;
}
void SessionForm::OnGetTeamInfoCb(const std::string& tid, const nim::TeamInfo& result)
{
	team_info_ = result;

	std::wstring wname = nbase::UTF8ToUTF16(team_info_.GetName());
	if (!wname.empty())
	{
		SetTaskbarTitle(wname);
		label_title_->SetText(wname);
	}

	bool valid = team_info_.IsValid();
	if (!valid)
	{
		LeaveTeamHandle();
		return;
	}
	else
	{
		EnterTeamHandle();
	}

	if (team_info_.GetType() == nim::kNIMTeamTypeAdvanced)
	{
		AdjustSizeForAdvancedTeam();
		Json::Value json;
		if (StringToJson(team_info_.GetAnnouncement(), json))
		{
			UpdateBroad(json);
		}
		else
		{
			re_broad_->SetUTF8Text(team_info_.GetAnnouncement());
		}
		CheckTeamType(nim::kNIMTeamTypeAdvanced);
		//member
		InvokeGetTeamMember();
	}

	btn_header_->SetEnabled(true);
}
/**
 * @brief RequestHandler::handlePost
 * @param uri
 * @param p_data
 * @return
 */
void RequestHandler::handleRequest(ConnectionInfo &conInfo)
{
    vector<string> parsedURI = parseURI(conInfo.url);

    string p_image[] = {"index", "images", "IDENTIFIER", ""};
    string p_searchImage[] = {"index", "searcher", ""};
    string p_ioIndex[] = {"index", "io", ""};

    Json::Value ret;
    conInfo.answerCode = MHD_HTTP_OK;

    if (testURIWithPattern(parsedURI, p_image)
        && conInfo.connectionType == PUT)
    {
        u_int32_t i_imageId = atoi(parsedURI[2].c_str());

        u_int32_t i_ret = featureExtractor->processNewImage(
            i_imageId, conInfo.uploadedData.size(), conInfo.uploadedData.data());

        ret["type"] = Converter::codeToString(i_ret);
        ret["image_id"] = Json::Value(i_imageId);
    }
    else if (testURIWithPattern(parsedURI, p_image)
             && conInfo.connectionType == DELETE)
    {
        u_int32_t i_imageId = atoi(parsedURI[2].c_str());

        u_int32_t i_ret = index->removeImage(i_imageId);
        ret["type"] = Converter::codeToString(i_ret);
        ret["image_id"] = Json::Value(i_imageId);
    }
    else if (testURIWithPattern(parsedURI, p_searchImage)
             && conInfo.connectionType == POST)
    {
        SearchRequest req;

        req.imageData = conInfo.uploadedData;
        req.client = NULL;
        u_int32_t i_ret = imageSearcher->searchImage(req);

        ret["type"] = Converter::codeToString(i_ret);
        if (i_ret == OK)
        {
            Json::Value imageIds(Json::arrayValue);
            for (unsigned i = 0; i < req.results.size(); ++i)
                imageIds.append(req.results[i]);
            ret["image_ids"] = imageIds;
        }
    }
    else if (testURIWithPattern(parsedURI, p_ioIndex)
             && conInfo.connectionType == POST)
    {
        string dataStr(conInfo.uploadedData.begin(),
                       conInfo.uploadedData.end());

        Json::Value data = StringToJson(dataStr);
        u_int32_t i_ret;
        if (data["type"] == "LOAD")
            i_ret = index->load(data["index_path"].asString());
        else if (data["type"] == "WRITE")
            i_ret = index->write(data["index_path"].asString());
        else if (data["type"] == "CLEAR")
            i_ret = index->clear();
        else
            i_ret = ERROR_GENERIC;

        ret["type"] = Converter::codeToString(i_ret);
    }
    else
    {
        conInfo.answerCode = MHD_HTTP_INTERNAL_SERVER_ERROR;
        ret["type"] = Converter::codeToString(ERROR_GENERIC);
    }

    conInfo.answerString = JsonToString(ret);
}
Example #4
0
void MsgRecordForm::ShowMsg(const nim::IMMessage &msg, bool first, bool show_time)
{
	const std::string &bubble_id = msg.client_msg_id_;
	if(bubble_id.empty())
	{
		QLOG_WAR(L"msg id empty");
		return;
	}

	IdBubblePair::iterator it = id_bubble_pair_.find(bubble_id);
	if(it != id_bubble_pair_.end())
	{
		QLOG_WAR(L"repeat msg: {0}") <<bubble_id;
		return;
	}

	MsgBubbleItem* item = NULL;

	if (msg.type_ == nim::kNIMMessageTypeText)
		item = new MsgBubbleText;
	else if (msg.type_ == nim::kNIMMessageTypeImage)
		item = new MsgBubbleImage;
	else if (msg.type_ == nim::kNIMMessageTypeAudio)
		item = new MsgBubbleAudio;
	else if (msg.type_ == nim::kNIMMessageTypeFile)
		item = new MsgBubbleFile;
	else if (msg.type_ == nim::kNIMMessageTypeLocation)
		item = new MsgBubbleLocation;
	else if (msg.type_ == nim::kNIMMessageTypeNotification)
	{
		id_bubble_pair_[bubble_id] = NULL;

		MsgBubbleNotice* cell = new MsgBubbleNotice;
		GlobalManager::FillBoxWithCache(cell, L"session/cell_notice.xml");
		if(first)
			msg_list_->AddAt(cell, 0);
		else
			msg_list_->Add(cell);
		cell->InitControl();
		cell->InitInfo(msg, session_id_);
		return;
	}
	else if (msg.type_ == nim::kNIMMessageTypeCustom)
	{
		Json::Value json;
		if (StringToJson(msg.attach_, json))
		{
			int sub_type = json["type"].asInt();
			if (sub_type == CustomMsgType_Jsb) //finger
			{
				item = new MsgBubbleFinger;
			}
			else if (sub_type == CustomMsgType_SnapChat)
			{
				item = new MsgBubbleSnapChat;
			}
			else if (sub_type == CustomMsgType_Sticker)
			{
				item = new MsgBubbleSticker;
			}
			else if (sub_type == CustomMsgType_Rts)
			{
				if (json["data"].isObject())
				{
					int flag = json["data"]["flag"].asInt();
					if (flag == 0)
					{
						item = new MsgBubbleText;
					}
					else if (flag == 1)
					{
						id_bubble_pair_[bubble_id] = NULL;

						MsgBubbleNotice* cell = new MsgBubbleNotice;
						GlobalManager::FillBoxWithCache(cell, L"session/cell_notice.xml");
						if (first)
							msg_list_->AddAt(cell, 0);
						else
							msg_list_->Add(cell);
						cell->InitControl();
						cell->InitInfo(msg, session_id_);
						return;
					}
				}
			}
		}
	}

	if (item == nullptr)
	{
		QLOG_WAR(L"unknown msg: cid={0} msg_type={1}") << bubble_id << msg.type_;
		item = new MsgBubbleUnknown;
	}

	bool bubble_right = IsBubbleRight(msg);
	if(bubble_right)
		GlobalManager::FillBoxWithCache( item, L"session/bubble_right.xml" );
	else
		GlobalManager::FillBoxWithCache( item, L"session/bubble_left.xml" );

	if(first)
		msg_list_->AddAt(item, 0);
	else
		msg_list_->Add(item);

	id_bubble_pair_[bubble_id] = item;

	std::string sid = nbase::UTF16ToUTF8(GetWindowClassName());

	item->InitControl(bubble_right);
	item->InitInfo(msg);
	item->SetSessionId(sid);
	item->SetSessionType(session_type_);
	item->SetActionMenu(false);
	item->SetShowTime(show_time);
	if (bubble_right || msg.session_type_ == nim::kNIMSessionTypeP2P)
		item->SetShowName(false, "");
	else
	{
		auto iter = team_member_info_list_.find(msg.sender_accid_);
		if (iter != team_member_info_list_.cend() && !iter->second.GetNick().empty())
			item->SetShowName(true, iter->second.GetNick()); //显示群名片
		else
		{
			std::string show_name = nbase::UTF16ToUTF8(UserService::GetInstance()->GetUserName(msg.sender_accid_));
			item->SetShowName(true, show_name); //显示备注名或昵称
		}
	}

	if (msg.type_ == nim::kNIMMessageTypeAudio)
		item->SetPlayed(true);

	if( item->NeedDownloadResource() )
	{
		nim::NOS::FetchMedia(msg, nbase::Bind(&MsgRecordForm::OnDownloadCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), nim::NOS::ProgressCallback());
	}
}
Example #5
0
void CustomMsgBubble::InitInfo(const nim::IMMessage &msg)
{
	sender_id_ = msg.sender_accid_;
	session_type_ = msg.session_type_;
	receiver_id_ = msg.receiver_accid_;

	std::wstring sender = UserService::GetInstance()->GetUserName(sender_id_);
	if (session_type_ == nim::kNIMSessionTypeP2P)
	{
		head_->SetBkImage(PhotoService::GetInstance()->GetUserPhoto(sender_id_));
		name_->SetText(sender);
	}
	else
	{
		head_->SetBkImage(PhotoService::GetInstance()->GetTeamPhoto(receiver_id_, true));
		std::wstring team_sender = TeamService::GetInstance()->GetTeamName(receiver_id_) + L"->" + sender;
		name_->SetText(team_sender);
	}

	std::wstring tm = GetMessageTime(msg.timetag_, false);
	time_->SetText(tm);

	std::wstring msg_body;
	if (msg.msg_setting_.server_history_saved_)
	{
		//msg_body = L"【可离线通知】";
	}
	else
	{
		msg_body = L"【在线通知】";
	}
// 	if (!msg.custom_apns_text.empty())
// 	{
// 		if (!msg_body.empty())
// 		{
// 			msg_body += L"\r\n";
// 		}
// 		msg_body += L"【推送】" + nbase::UTF8ToUTF16(msg.custom_apns_text);
// 	}
	if (!msg.content_.empty())
	{
		if (!msg_body.empty())
		{
			msg_body += L"\r\n";
		}
		msg_body += L"【附言】" + nbase::UTF8ToUTF16(msg.content_);
	}
	bool fetch_data = false;
	Json::Value json;
	if (StringToJson(msg.attach_, json) && json.isObject())
	{
		if (json.isMember("id") && json.isMember("content"))
		{
			std::string id = json["id"].asString();
			std::string content = json["content"].asString();
			if (id == "2" && !content.empty())
			{
				if (!msg_body.empty())
				{
					msg_body += L"\r\n【内容】";
				}
				msg_body = nbase::UTF8ToUTF16(content);
				fetch_data = true;
			}
		}
	}
	if (!fetch_data)
		msg_body = nbase::UTF8ToUTF16(msg.attach_);

	SetMsgText(msg_body);
}