mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
Merge branch 'tuoyun' into superGroup
# Conflicts: # internal/msg_gateway/gate/callback.go # internal/msg_transfer/logic/online_history_msg_handler.go # internal/push/logic/callback.go # internal/push/logic/push_to_client.go # pkg/common/db/model.go # pkg/common/db/newRedisModel.go # pkg/proto/group/group.pb.go # pkg/proto/group/group.proto
This commit is contained in:
@@ -419,6 +419,11 @@ type config struct {
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"joinDepartmentNotification"`
|
||||
Signal struct {
|
||||
OfflinePush struct {
|
||||
Title string `yaml:"title"`
|
||||
} `yaml:"offlinePush"`
|
||||
} `yaml:"signal"`
|
||||
}
|
||||
Demo struct {
|
||||
Port []int `yaml:"openImDemoPort"`
|
||||
@@ -442,8 +447,7 @@ type config struct {
|
||||
ImAPIURL string `yaml:"imAPIURL"`
|
||||
}
|
||||
Rtc struct {
|
||||
Port int `yaml:"port"`
|
||||
Address string `yaml:"address"`
|
||||
SignalTimeout string `yaml:"signalTimeout"`
|
||||
} `yaml:"rtc"`
|
||||
}
|
||||
type PConversation struct {
|
||||
|
||||
@@ -44,6 +44,7 @@ const (
|
||||
Quote = 114
|
||||
Common = 200
|
||||
GroupMsg = 201
|
||||
SignalMsg = 202
|
||||
|
||||
//SysRelated
|
||||
NotificationBegin = 1000
|
||||
@@ -218,14 +219,15 @@ const (
|
||||
)
|
||||
|
||||
var ContentType2PushContent = map[int64]string{
|
||||
Picture: "[图片]",
|
||||
Voice: "[语音]",
|
||||
Video: "[视频]",
|
||||
File: "[文件]",
|
||||
Text: "你收到了一条文本消息",
|
||||
AtText: "[有人@你]",
|
||||
GroupMsg: "你收到一条群聊消息",
|
||||
Common: "你收到一条新消息",
|
||||
Picture: "[图片]",
|
||||
Voice: "[语音]",
|
||||
Video: "[视频]",
|
||||
File: "[文件]",
|
||||
Text: "你收到了一条文本消息",
|
||||
AtText: "[有人@你]",
|
||||
GroupMsg: "你收到一条群聊消息",
|
||||
Common: "你收到一条新消息",
|
||||
SignalMsg: "音視頻通話邀請",
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -142,6 +142,18 @@ func UpdateGroupMemberInfo(groupMemberInfo db.GroupMember) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateGroupMemberInfoByMap(groupMemberInfo db.GroupMember, m map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetOwnerManagerByGroupID(groupID string) ([]db.GroupMember, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
|
||||
@@ -249,26 +249,27 @@ func GetDepartmentRelatedGroupIDList(departmentIDList []string) ([]string, error
|
||||
|
||||
func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*db.Department, error) {
|
||||
var department db.Department
|
||||
var parentID string
|
||||
//var parentID string
|
||||
dbConn.LogMode(true)
|
||||
// select * from departments where department_id = (select parent_id from departments where department_id= zx234fd);
|
||||
err := dbConn.Table("departments").Where("department_id=?", dbConn.Table("departments").Where("department_id=?", departmentID).Pluck("parent_id", parentID)).Find(&department).Error
|
||||
//dbConn.Table("departments").Where("department_id=?", departmentID).Pluck("parent_id", parentID).Error
|
||||
err := dbConn.Table("departments").Where("department_id=?").Find(&department).Error
|
||||
return &department, err
|
||||
}
|
||||
|
||||
func GetDepartmentParent(departmentID string, dbConn *gorm.DB, parentIDList []string) (*db.Department, error) {
|
||||
func GetDepartmentParent(departmentID string, dbConn *gorm.DB, parentIDList *[]string) error {
|
||||
department, err := getDepartmentParent(departmentID, dbConn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if department.ParentID != "" {
|
||||
parentIDList = append(parentIDList, department.ParentID)
|
||||
_, err = GetDepartmentParent(departmentID, dbConn, parentIDList)
|
||||
*parentIDList = append(*parentIDList, department.ParentID)
|
||||
err = GetDepartmentParent(departmentID, dbConn, parentIDList)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetDepartmentParentIDList(departmentID string) ([]string, error) {
|
||||
@@ -277,6 +278,6 @@ func GetDepartmentParentIDList(departmentID string) ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
var parentIDList []string
|
||||
_, err = GetDepartmentParent(departmentID, dbConn, parentIDList)
|
||||
err = GetDepartmentParent(departmentID, dbConn, &parentIDList)
|
||||
return parentIDList, err
|
||||
}
|
||||
|
||||
@@ -4,15 +4,21 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
log2 "Open_IM/pkg/common/log"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
//goRedis "github.com/go-redis/redis/v8"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
//func (d * DataBases)pubMessage(channel, msg string) {
|
||||
@@ -101,3 +107,91 @@ func (d *DataBases) CleanUpOneUserAllMsgFromRedis(userID string, operationID str
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) NewCacheSignalInfo(msg *pbCommon.MsgData) error {
|
||||
req := &pbRtc.SignalReq{}
|
||||
if err := proto.Unmarshal(msg.Content, req); err != nil {
|
||||
return err
|
||||
}
|
||||
//log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "SignalReq: ", req.String())
|
||||
var inviteeUserIDList []string
|
||||
switch invitationInfo := req.Payload.(type) {
|
||||
case *pbRtc.SignalReq_Invite:
|
||||
inviteeUserIDList = invitationInfo.Invite.Invitation.InviteeUserIDList
|
||||
case *pbRtc.SignalReq_InviteInGroup:
|
||||
inviteeUserIDList = invitationInfo.InviteInGroup.Invitation.InviteeUserIDList
|
||||
default:
|
||||
log2.NewDebug("", utils.GetSelfFuncName(), "req type not invite", string(msg.Content))
|
||||
return nil
|
||||
}
|
||||
for _, userID := range inviteeUserIDList {
|
||||
timeout, err := strconv.Atoi(config.Config.Rtc.SignalTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
keyList := SignalListCache + userID
|
||||
err = d.rdb.LPush(context.Background(), keyList, msg.ClientMsgID).Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = d.rdb.Expire(context.Background(), keyList, time.Duration(timeout)*time.Second).Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
key := SignalCache + msg.ClientMsgID
|
||||
err = d.rdb.Set(context.Background(), key, msg.Content, time.Duration(timeout)*time.Second).Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) GetSignalInfoFromCacheByClientMsgID(clientMsgID string) (invitationInfo *pbRtc.SignalInviteReq, err error) {
|
||||
key := SignalCache + clientMsgID
|
||||
invitationInfo = &pbRtc.SignalInviteReq{}
|
||||
bytes, err := d.rdb.Get(context.Background(), key).Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := &pbRtc.SignalReq{}
|
||||
if err = proto.Unmarshal(bytes, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch req2 := req.Payload.(type) {
|
||||
case *pbRtc.SignalReq_Invite:
|
||||
invitationInfo.Invitation = req2.Invite.Invitation
|
||||
case *pbRtc.SignalReq_InviteInGroup:
|
||||
invitationInfo.Invitation = req2.InviteInGroup.Invitation
|
||||
}
|
||||
return invitationInfo, err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetAvailableSignalInvitationInfo(userID string) (invitationInfo *pbRtc.SignalInviteReq, err error) {
|
||||
keyList := SignalListCache + userID
|
||||
result := d.rdb.RPop(context.Background(), keyList)
|
||||
if err = result.Err(); err != nil {
|
||||
return nil, utils.Wrap(err, "GetAvailableSignalInvitationInfo failed")
|
||||
}
|
||||
key, err := result.Result()
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetAvailableSignalInvitationInfo failed")
|
||||
}
|
||||
log2.NewDebug("", utils.GetSelfFuncName(), result, result.String())
|
||||
invitationInfo, err = d.GetSignalInfoFromCacheByClientMsgID(key)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetSignalInfoFromCacheByClientMsgID")
|
||||
}
|
||||
err = d.delUserSingalList(userID)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetSignalInfoFromCacheByClientMsgID")
|
||||
}
|
||||
return invitationInfo, nil
|
||||
}
|
||||
|
||||
func (d *DataBases) delUserSingalList(userID string) error {
|
||||
keyList := SignalListCache + userID
|
||||
err := d.rdb.Del(context.Background(), keyList).Err()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,13 +5,18 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
log2 "Open_IM/pkg/common/log"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
//osconfig "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -29,6 +34,8 @@ const (
|
||||
blackListCache = "BLACK_LIST_CACHE:"
|
||||
groupCache = "GROUP_CACHE:"
|
||||
messageCache = "MESSAGE_CACHE:"
|
||||
SignalCache = "SIGNAL_CACHE:"
|
||||
SignalListCache = "SIGNAL_LIST_CACHE:"
|
||||
)
|
||||
|
||||
func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (interface{}, error) {
|
||||
@@ -342,3 +349,25 @@ func (d *DataBases) DelMsgFromCache(uid string, seqList []uint32, operationID st
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DataBases) CacheSignalInfo(msg *pbCommon.MsgData) error {
|
||||
key := SignalCache + msg.ClientMsgID
|
||||
_, err := d.Exec("SET", key, msg.Content, "ex", config.Config.Rtc.SignalTimeout)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetSignalInfoFromCache(clientMsgID string) (invitationInfo *pbRtc.SignalInviteReq, err error) {
|
||||
key := SignalCache + clientMsgID
|
||||
result, err := redis.Bytes(d.Exec("GET", key))
|
||||
log2.NewDebug("", utils.GetSelfFuncName(), clientMsgID, result, string(result))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := &pbRtc.SignalReq{}
|
||||
if err = proto.Unmarshal(result, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req2 := req.Payload.(*pbRtc.SignalReq_Invite)
|
||||
invitationInfo = req2.Invite
|
||||
return invitationInfo, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user