feat: add trusted customer service friendships
Deploy im-server production / deploy (push) Successful in 11m38s
Deploy im-server production / deploy (push) Successful in 11m38s
This commit is contained in:
@@ -116,6 +116,8 @@ func serveInternalAdminQuery(wrt http.ResponseWriter, req *http.Request, prefix
|
||||
serveInternalUserCreate(wrt, req, tenant.ID)
|
||||
case req.Method == http.MethodPost && len(parts) == 5 && parts[2] == "users" && parts[4] == "action":
|
||||
serveInternalUserAction(wrt, req, tenant.ID, parts[3])
|
||||
case req.Method == http.MethodPost && len(parts) == 4 && parts[2] == "friends" && parts[3] == "direct":
|
||||
serveInternalFriendDirectAdd(wrt, req, tenant.ID)
|
||||
case req.Method == http.MethodPost && len(parts) == 4 && parts[2] == "login-lockouts" && parts[3] == "release":
|
||||
serveInternalLoginLockoutRelease(wrt, req, tenant.ID)
|
||||
case req.Method == http.MethodGet && len(parts) == 3 && parts[2] == "users":
|
||||
@@ -166,9 +168,37 @@ func serveInternalAdminQuery(wrt http.ResponseWriter, req *http.Request, prefix
|
||||
func isInternalAdminPostRoute(parts []string) bool {
|
||||
return (len(parts) == 3 && parts[2] == "users") ||
|
||||
(len(parts) == 5 && parts[2] == "users" && parts[4] == "action") ||
|
||||
(len(parts) == 4 && parts[2] == "friends" && parts[3] == "direct") ||
|
||||
(len(parts) == 4 && parts[2] == "login-lockouts" && parts[3] == "release")
|
||||
}
|
||||
|
||||
type internalDirectFriendRequest struct {
|
||||
UserID string `json:"user_id"`
|
||||
PeerID string `json:"peer_user_id"`
|
||||
}
|
||||
|
||||
func serveInternalFriendDirectAdd(wrt http.ResponseWriter, req *http.Request, tenantID types.TenantID) {
|
||||
var body internalDirectFriendRequest
|
||||
if err := json.NewDecoder(io.LimitReader(req.Body, 1<<20)).Decode(&body); err != nil {
|
||||
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed request", nil)
|
||||
return
|
||||
}
|
||||
userID := types.ParseUserId(strings.TrimSpace(body.UserID))
|
||||
peerID := types.ParseUserId(strings.TrimSpace(body.PeerID))
|
||||
if userID.IsZero() || peerID.IsZero() || userID == peerID {
|
||||
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed user IDs", nil)
|
||||
return
|
||||
}
|
||||
if err := store.Relations.AddFriendDirect(tenantID, userID, peerID, time.Now().UTC().Round(time.Millisecond)); err != nil {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
}
|
||||
writeIMSuccess(wrt, req, map[string]any{
|
||||
"relationship": "friend",
|
||||
"topic": userID.P2PName(peerID),
|
||||
})
|
||||
}
|
||||
|
||||
type internalUserCreateRequest struct {
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
|
||||
Reference in New Issue
Block a user