TeamTalk db_proxy_server SessionModel详解

1. 简介

管理mysql IMRecentSession表用户会话信息

2. mysql IMRecentSession表
CREATE TABLE `IMRecentSession` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userId` int(11) unsigned NOT NULL COMMENT '用户id',
  `peerId` int(11) unsigned NOT NULL COMMENT '对方id',
  `type` tinyint(1) unsigned DEFAULT '0' COMMENT '类型,1-用户,2-群组',
  `status` tinyint(1) unsigned DEFAULT '0' COMMENT '用户:0-正常, 1-用户A删除,群组:0-正常, 1-被删除',
  `created` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_userId_peerId_status_updated` (`userId`,`peerId`,`status`,`updated`),
  KEY `idx_userId_peerId_type` (`userId`,`peerId`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3. IM::BaseDefine::ContactSessionInfo
message ContactSessionInfo{
	required uint32 session_id = 1;
	required SessionType session_type = 2;
    required SessionStatusType session_status = 3;
	required uint32 updated_time = 4;
	required uint32 latest_msg_id = 5;
	required bytes latest_msg_data = 6;
    required MsgType latest_msg_type = 7;
    required uint32 latest_msg_from_user_id = 8;
}
4. 类与接口

① void CSessionModel::getRecentSession(uint32_t nUserId, uint32_t lastTime, listIM::BaseDefine::ContactSessionInfo& lsContact)
通过查询mysql IMRecentSession获取和nUserId时间大于lastTime的会话信息(类型,1-用户,2-群组 用户:0-正常, 1-用户A删除,群组:0-正常, 1-被删除),
查询的结果存入lsContact

② uint32_t CSessionModel::getSessionId(uint32_t nUserId, uint32_t nPeerId, uint32_t nType, bool isAll)
从mysql IMRecentSession查询nUserId和nPeerId指定nType的会话id,isAll为false仅查询正常用户否则查询全部,
返回查询到的会话id

③ bool CSessionModel::updateSession(uint32_t nSessionId, uint32_t nUpdateTime)
更新mysql IMRecentSession nSessionId的会话时间(updated)

④ bool CSessionModel::removeSession(uint32_t nSessionId)
删除会话信息,实际未删除,
将mysql IMRecentSession指定nSessionId会话状态设置为删除

⑤ uint32_t CSessionModel::addSession(uint32_t nUserId, uint32_t nPeerId, uint32_t nType)
增加会话信息,若有则更新,若无则添加

⑥ void CSessionModel::fillSessionMsg(uint32_t nUserId, listIM::BaseDefine::ContactSessionInfo& lsContact)
填充lsContact里所有会话信息的消息内容,
获取消息内容需使用到CMessageModel

5. Tests/test_sessionmodel.cpp

RecentSession提供了两个接口getRecentSession和deleteRecentSession处理获取和删除最近会话请求pdu

该用例模拟win client,获取userid为1的会话信息

6. 源码

链接:TeamTalk_BlueBling

测试demo: tests/test_sessionmodel.cpp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值