✨ Invite friends check
This commit is contained in:
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user