初始化项目

This commit is contained in:
2022-09-27 11:31:23 +08:00
parent b4dc3c7305
commit 533ede4f66
54 changed files with 12011 additions and 25 deletions

148
recentcontact/api.go Normal file
View File

@@ -0,0 +1,148 @@
/**
* @Author: wanglin
* @Author: wanglin@vspn.com
* @Date: 2021/10/28 16:05
* @Desc: TODO
*/
package recentcontact
import (
"git.echol.cn/loser/tencent-im/internal/core"
"git.echol.cn/loser/tencent-im/internal/types"
)
const (
service = "recentcontact"
commandFetchSessions = "get_list"
commandDeleteSession = "delete"
)
type API interface {
// FetchSessions 拉取会话列表
// 支持分页拉取会话列表
// 点击查看详细文档:
// https://cloud.tencent.com/document/product/269/62118
FetchSessions(arg *FetchSessionsArg) (ret *FetchSessionsRet, err error)
// PullSessions 续拉取会话列表
// 本API是借助"拉取会话列表"API进行扩展实现
// 支持分页拉取会话列表
// 点击查看详细文档:
// https://cloud.tencent.com/document/product/269/62118
PullSessions(arg *PullSessionsArg, fn func(ret *FetchSessionsRet)) (err error)
// DeleteSession 删除单个会话
// 删除指定会话,支持同步清理漫游消息。
// 点击查看详细文档:
// https://cloud.tencent.com/document/product/269/62119
DeleteSession(fromUserId, toUserId string, SessionType SessionType, isClearRamble ...bool) (err error)
}
type api struct {
client core.Client
}
func NewAPI(client core.Client) API {
return &api{client: client}
}
// FetchSessions 拉取会话列表
// 支持分页拉取会话列表
// 点击查看详细文档:
// https://cloud.tencent.com/document/product/269/62118
func (a *api) FetchSessions(arg *FetchSessionsArg) (ret *FetchSessionsRet, err error) {
req := &fetchSessionsReq{
UserId: arg.UserId,
TimeStamp: arg.TimeStamp,
StartIndex: arg.StartIndex,
TopTimeStamp: arg.TopTimeStamp,
TopStartIndex: arg.TopStartIndex,
}
if arg.IsAllowTopSession {
req.AssistFlags += 1 << 0
}
if arg.IsReturnEmptySession {
req.AssistFlags += 1 << 1
}
if arg.IsAllowTopSessionPaging {
req.AssistFlags += 1 << 2
}
resp := &fetchSessionsResp{}
if err = a.client.Post(service, commandFetchSessions, req, resp); err != nil {
return
}
ret = &FetchSessionsRet{
TimeStamp: resp.TimeStamp,
StartIndex: resp.StartIndex,
TopTimeStamp: resp.TopTimeStamp,
TopStartIndex: resp.TopStartIndex,
List: resp.Sessions,
HasMore: resp.CompleteFlag == 0,
}
return
}
// PullSessions 续拉取会话列表
// 本API是借助"拉取会话列表"API进行扩展实现
// 支持分页拉取会话列表
// 点击查看详细文档:
// https://cloud.tencent.com/document/product/269/62118
func (a *api) PullSessions(arg *PullSessionsArg, fn func(ret *FetchSessionsRet)) (err error) {
var (
ret *FetchSessionsRet
req = &FetchSessionsArg{
UserId: arg.UserId,
IsAllowTopSession: arg.IsAllowTopSession,
IsReturnEmptySession: arg.IsReturnEmptySession,
IsAllowTopSessionPaging: arg.IsAllowTopSessionPaging,
}
)
for ret == nil || ret.HasMore {
ret, err = a.FetchSessions(req)
if err != nil {
return
}
fn(ret)
if ret.HasMore {
req.TimeStamp = ret.TimeStamp
req.StartIndex = ret.StartIndex
req.TopTimeStamp = ret.TopTimeStamp
req.TopStartIndex = ret.TopStartIndex
}
}
return
}
// DeleteSession 删除单个会话
// 删除指定会话,支持同步清理漫游消息。
// 点击查看详细文档:
// https://cloud.tencent.com/document/product/269/62119
func (a *api) DeleteSession(fromUserId, toUserId string, SessionType SessionType, isClearRamble ...bool) (err error) {
req := &deleteSessionReq{
FromUserId: fromUserId,
ToUserId: toUserId,
Type: SessionType,
}
if len(isClearRamble) > 0 && isClearRamble[0] {
req.ClearRamble = 1
}
if err = a.client.Post(service, commandDeleteSession, req, &types.ActionBaseResp{}); err != nil {
return
}
return
}

16
recentcontact/enum.go Normal file
View File

@@ -0,0 +1,16 @@
/**
* @Author: wanglin
* @Author: wanglin@vspn.com
* @Date: 2021/10/28 17:22
* @Desc: TODO
*/
package recentcontact
// SessionType 会话类型
type SessionType int
const (
SessionTypeC2C SessionType = 1 // C2C 会话
SessionTypeG2C SessionType = 2 // G2C 会话
)

78
recentcontact/types.go Normal file
View File

@@ -0,0 +1,78 @@
/**
* @Author: wanglin
* @Author: wanglin@vspn.com
* @Date: 2021/10/28 16:11
* @Desc: TODO
*/
package recentcontact
import "git.echol.cn/loser/tencent-im/internal/types"
// FetchSessionsArg 拉取会话列表(参数)
type FetchSessionsArg struct {
UserId string // (必填)请求拉取该用户的会话列表
TimeStamp int // (必填)普通会话的起始时间,第一页填 0
StartIndex int // (必填)普通会话的起始位置,第一页填 0
TopTimeStamp int // (必填)置顶会话的起始时间,第一页填 0
TopStartIndex int // (必填)置顶会话的起始位置,第一页填 0
IsAllowTopSession bool // (选填)是否支持置顶会话
IsReturnEmptySession bool // (选填)是否返回空会话
IsAllowTopSessionPaging bool // (选填)是否支持置顶会话分页
}
// PullSessionsArg 续拉取会话列表(参数)
type PullSessionsArg struct {
UserId string // (必填)请求拉取该用户的会话列表
IsAllowTopSession bool // (选填)是否支持置顶会话
IsReturnEmptySession bool // (选填)是否返回空会话
IsAllowTopSessionPaging bool // (选填)是否支持置顶会话分页
}
// FetchSessionsRet 拉取会话列表(返回)
type FetchSessionsRet struct {
TimeStamp int // 普通会话下一页拉取的起始时间,分页拉取时通过请求包的 TimeStamp 字段带给移动通信后台
StartIndex int // 普通会话下一页拉取的起始位置,分页拉取时通过请求包的 StartIndex 字段带给移动通信后台
TopTimeStamp int // 置顶会话下一页拉取的起始时间,分页拉取时通过请求包的 TopTimeStamp 字段带给移动通信后台
TopStartIndex int // 置顶会话下一页拉取的起始位置,分页拉取时通过请求包的 TopStartIndex 字段带给移动通信后台
HasMore bool // 是否拉完了数据
List []*SessionItem // 会话对象数组
}
// fetchSessionsReq 拉取会话列表(请求)
type fetchSessionsReq struct {
UserId string `json:"From_Account"` // (必填)请求拉取该用户的会话列表
TimeStamp int `json:"TimeStamp"` // (必填)普通会话的起始时间,第一页填 0
StartIndex int `json:"StartIndex"` // (必填)普通会话的起始位置,第一页填 0
TopTimeStamp int `json:"TopTimeStamp"` // (必填)置顶会话的起始时间,第一页填 0
TopStartIndex int `json:"TopStartIndex"` // (必填)置顶会话的起始位置,第一页填 0
AssistFlags int `json:"AssistFlags"` // 必填会话辅助标志位bit 0 - 是否支持置顶会话bit 1 - 是否返回空会话bit 2 - 是否支持置顶会话分页)
}
// fetchSessionsResp 拉取会话列表(响应)
type fetchSessionsResp struct {
types.ActionBaseResp
CompleteFlag int `json:"CompleteFlag"` // 结束标识1 表示已返回全量会话0 表示还有会话没拉完
TimeStamp int `json:"TimeStamp"` // 普通会话下一页拉取的起始时间,分页拉取时通过请求包的 TimeStamp 字段带给移动通信后台
StartIndex int `json:"StartIndex"` // 普通会话下一页拉取的起始位置,分页拉取时通过请求包的 StartIndex 字段带给移动通信后台
TopTimeStamp int `json:"TopTimeStamp"` // 置顶会话下一页拉取的起始时间,分页拉取时通过请求包的 TopTimeStamp 字段带给移动通信后台
TopStartIndex int `json:"TopStartIndex"` // 置顶会话下一页拉取的起始位置,分页拉取时通过请求包的 TopStartIndex 字段带给移动通信后台
Sessions []*SessionItem `json:"SessionItem"` // 会话对象数组
}
// SessionItem 会话对象
type SessionItem struct {
Type SessionType `json:"Type"` // 会话类型1 表示 C2C 会话2 表示 G2C 会话
UserId string `json:"To_Account,omitempty"` // C2C 会话才会返回,返回会话方的 UserID
GroupId string `json:"GroupId,omitempty"` // G2C 会话才会返回,返回群 ID
MsgTime int `json:"MsgTime"` // 会话时间
TopFlag int `json:"TopFlag"` // 置顶标记0 标识普通会话1 标识置顶会话
}
// deleteSessionReq 删除单个会话(请求)
type deleteSessionReq struct {
FromUserId string `json:"From_Account"` // (必填)请求删除该 UserID 的会话
Type SessionType `json:"type"` // 必填会话类型1 表示 C2C 会话2 表示 G2C 会话
ToUserId string `json:"To_Account"` // (必填)待删除的会话的 UserID
ClearRamble int `json:"ClearRamble,omitempty"` // 选填是否清理漫游消息1 表示清理漫游消息0 表示不清理漫游消息
}