IM/MDB/imm_mongodb/template/MsgTemplate.h
dongl a764f9fcab 暂时添加了 邮箱不可重复申请帐号
后续改成 邮箱可以申请多个账号, 用邮箱登陆时选择帐号登陆
修改了 MessageSystem 结构
2023-07-04 10:31:14 +08:00

50 lines
1.7 KiB
C++

//
// Created by dongl on 23-5-27.
//
#ifndef IM2_MSGTEMPLATE_H
#define IM2_MSGTEMPLATE_H
#include <mongocxx/client.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include "proto/mp.mp.pb.h"
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_array;
using bsoncxx::builder::basic::make_document;
class MsgTemplate {
public:
/**
* 对于 mongo 的 通用消息 插入模板
* @param msg_type 消息类型
* @param session_type 会话类型
* @param message_id 消息id
* @param time 消息时间
* @param account 消息来源
* @param msg_data 消息数据
* @return make_document -》 mongocxx
*/
static bsoncxx::document::value session_msg(mp::MP_SUB_TYPE msg_type, mp::MP_SUB_TYPE session_type,
int64_t message_id, time_t time, int64_t account,
const std::string& msg_data) {
// 要插入的视图
auto doc_value = make_document(
kvp("msg_type", msg_type), // 200 text消息
kvp("session_type", session_type), // 300 单体会话
kvp("msg_id", message_id), // 0 会话级id
kvp("time", time), // 时间
kvp("account", account), // 目标/来源
kvp("msg_data", msg_data.c_str()) // 消息内容
);
return doc_value;
}
};
#endif //IM2_MSGTEMPLATE_H