feat: 新增关系类型及按话题查询通话记录接口
- 新增 RelationshipSelf 关系类型 - 新增 serveIMCallsByTopic 接口处理按话题查询通话记录 - 实现群成员资料接口返回本人时的 self 关系处理 - 更新接口文档说明本人查询时返回 relationship: self
This commit is contained in:
+38
-4
@@ -3133,6 +3133,25 @@ func serveIMTopicCalls(wrt http.ResponseWriter, req *http.Request) {
|
||||
writeIMSuccess(wrt, req, map[string]any{"topic": topic, "items": callRecordPayloads(items, principal.Uid), "next_cursor": nextCursor})
|
||||
}
|
||||
|
||||
// serveIMCallsByTopic serves GET /v1/im/calls/{topic} — 对接文档契约路径,按会话查通话记录。
|
||||
func serveIMCallsByTopic(wrt http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodGet {
|
||||
writeIMError(wrt, req, http.StatusMethodNotAllowed, 30002, imReasonMethodNotAllowed, "method not allowed", nil)
|
||||
return
|
||||
}
|
||||
principal, topic, ok := authenticateTopicReader(wrt, req, topicFromCallsByTopicPath(req.URL.Path))
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
limit := parseIMLimit(req.URL.Query().Get("limit"), 50, 100)
|
||||
items, nextCursor, err := store.Calls.List(principal.TenantID, principal.Uid, topic, strings.TrimSpace(req.URL.Query().Get("cursor")), limit)
|
||||
if err != nil {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
}
|
||||
writeIMSuccess(wrt, req, map[string]any{"topic": topic, "items": callRecordPayloads(items, principal.Uid), "next_cursor": nextCursor})
|
||||
}
|
||||
|
||||
func serveIMMessageSearch(wrt http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodGet {
|
||||
writeIMError(wrt, req, http.StatusMethodNotAllowed, 30002, imReasonMethodNotAllowed, "method not allowed", nil)
|
||||
@@ -5794,10 +5813,16 @@ func serveIMGroupMemberProfile(wrt http.ResponseWriter, req *http.Request, topic
|
||||
writeIMError(wrt, req, http.StatusInternalServerError, 90000, imReasonInternal, "internal error", nil)
|
||||
return
|
||||
}
|
||||
ctx, err := store.Relations.GetRelationshipContext(principal.TenantID, principal.Uid, memberID, principal.Uid.P2PName(memberID))
|
||||
if err != nil {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
// 查询本人时 GetRelationshipContext 不接受 userID==peerID(会报 ErrMalformed),
|
||||
// 直接构造 self 上下文,群内本人资料返回 200。
|
||||
ctx := &types.RelationshipContext{Relationship: types.RelationshipSelf, CanSend: true}
|
||||
if memberID != principal.Uid {
|
||||
var err error
|
||||
ctx, err = store.Relations.GetRelationshipContext(principal.TenantID, principal.Uid, memberID, principal.Uid.P2PName(memberID))
|
||||
if err != nil {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
writeIMSuccess(wrt, req, groupMemberProfilePayload(topic, memberSub, user, ctx))
|
||||
}
|
||||
@@ -11006,6 +11031,15 @@ func topicFromCallsPath(path string) string {
|
||||
return topicFromPathWithSuffix(path, prefix, suffix)
|
||||
}
|
||||
|
||||
func topicFromCallsByTopicPath(path string) string {
|
||||
const prefix = "/v1/im/calls/"
|
||||
idx := strings.Index(path, prefix)
|
||||
if idx < 0 {
|
||||
return ""
|
||||
}
|
||||
return strings.Trim(strings.TrimSpace(path[idx+len(prefix):]), "/")
|
||||
}
|
||||
|
||||
func topicFromDraftPath(path string) string {
|
||||
const prefix = "/v1/im/topics/"
|
||||
const suffix = "/draft"
|
||||
|
||||
@@ -934,6 +934,7 @@ func main() {
|
||||
mux.HandleFunc(config.ApiPath+"v1/im/favorites", serveIMFavorites)
|
||||
mux.HandleFunc(config.ApiPath+"v1/im/favorites/", serveIMFavoriteResource)
|
||||
mux.HandleFunc(config.ApiPath+"v1/im/calls/rtc-join", serveIMCallRTCJoin)
|
||||
mux.HandleFunc(config.ApiPath+"v1/im/calls/", serveIMCallsByTopic)
|
||||
mux.HandleFunc(config.ApiPath+"v1/im/calls", serveIMCalls)
|
||||
mux.HandleFunc(config.ApiPath+"v1/im/topics/", serveIMTopicMessageAction)
|
||||
mux.HandleFunc(config.ApiPath+"v1/im/conversations/", serveIMConversationContext)
|
||||
|
||||
@@ -9,6 +9,7 @@ const (
|
||||
FriendRequestExpired = "expired"
|
||||
|
||||
RelationshipNone = "none"
|
||||
RelationshipSelf = "self"
|
||||
RelationshipFriend = "friend"
|
||||
RelationshipPendingInbound = "pending_inbound"
|
||||
RelationshipPendingOutbound = "pending_outbound"
|
||||
|
||||
Reference in New Issue
Block a user