Invite friends check

This commit is contained in:
2024-04-06 14:36:36 +08:00
parent b2719ae302
commit a96910edd2
7 changed files with 60 additions and 3 deletions

View File

@ -10,6 +10,17 @@ import (
"github.com/spf13/viper"
)
func GetAccountFriend(userId, relatedId uint, status int) (*proto.FriendshipResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return grpc.Friendships.GetFriendship(ctx, &proto.FriendshipTwoSideLookupRequest{
AccountId: uint64(userId),
RelatedId: uint64(relatedId),
Status: uint32(status),
})
}
func NotifyAccount(user models.Account, subject, content string, realtime bool, links ...*proto.NotifyLink) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

View File

@ -132,6 +132,20 @@ func ListChannelMember(channelId uint) ([]models.ChannelMember, error) {
return members, nil
}
func InviteChannelMember(user models.Account, target models.Channel) error {
if _, err := GetAccountFriend(user.ID, target.AccountID, 1); err != nil {
return fmt.Errorf("you only can invite your friends to your channel")
}
member := models.ChannelMember{
ChannelID: target.ID,
AccountID: user.ID,
}
err := database.C.Save(&member).Error
return err
}
func AddChannelMember(user models.Account, target models.Channel) error {
member := models.ChannelMember{
ChannelID: target.ID,
@ -139,7 +153,6 @@ func AddChannelMember(user models.Account, target models.Channel) error {
}
err := database.C.Save(&member).Error
return err
}