feat: add chat

This commit is contained in:
Krispire Admin
2026-08-29 03:49:30 +05:30
parent 3b10e726b7
commit d50031cdb3
21 changed files with 6960 additions and 11 deletions
+37 -5
View File
@@ -71,10 +71,13 @@ type SocialGraphService struct {
reports *repository.ReportRepo
posts *repository.PostRepo
users *repository.UserRepo
notif *NotificationService
mail mailer.Mailer
admins []string
logger *zap.Logger
// chat answers "may the viewer open a DM with this profile?" — the same
// rule OpenDM enforces, so the button and the action can't disagree.
chat *repository.ChatRepo
notif *NotificationService
mail mailer.Mailer
admins []string
logger *zap.Logger
}
func NewSocialGraphService(
@@ -83,6 +86,7 @@ func NewSocialGraphService(
reports *repository.ReportRepo,
posts *repository.PostRepo,
users *repository.UserRepo,
chat *repository.ChatRepo,
notif *NotificationService,
mail mailer.Mailer,
admins []string,
@@ -90,7 +94,8 @@ func NewSocialGraphService(
) *SocialGraphService {
return &SocialGraphService{
follows: follows, blocks: blocks, reports: reports, posts: posts,
users: users, notif: notif, mail: mail, admins: admins, logger: logger,
users: users, chat: chat, notif: notif, mail: mail, admins: admins,
logger: logger,
}
}
@@ -294,6 +299,33 @@ func (s *SocialGraphService) Relationship(ctx context.Context, viewerID, targetI
}
out.Blocked = viewerBlocked
out.BlockedBy = blockedByTarget
// A block closes messaging in either direction; otherwise the target's own
// "who can message you" rule decides. Asking the chat repository — rather
// than reimplementing the rule here — is what keeps the offered button and
// the eventual OpenDM in agreement.
switch {
case viewerID == "" || viewerID == targetID:
out.CanMessage = false
case viewerBlocked || blockedByTarget:
out.CanMessage = false
out.MessageRestriction = "blocked"
case s.chat == nil:
out.CanMessage = true
default:
allowed, err := s.chat.CanStartConversation(ctx, viewerID, targetID)
if err != nil {
return nil, err
}
out.CanMessage = allowed
if !allowed {
settings, err := s.chat.Settings(ctx, targetID)
if err != nil {
return nil, err
}
out.MessageRestriction = settings.WhoCanMessage
}
}
return out, nil
}