From 26d9d7630c4e5db785efc80584750227b6e1cfd7 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 31 Aug 2022 11:55:55 +0800 Subject: [PATCH 1/4] fcm --- internal/push/fcm/push.go | 12 ++++++++++-- internal/push/logic/push_to_client.go | 3 ++- internal/push/push_interface.go | 4 +++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/push/fcm/push.go b/internal/push/fcm/push.go index 99338e558..48f6a9947 100644 --- a/internal/push/fcm/push.go +++ b/internal/push/fcm/push.go @@ -7,11 +7,12 @@ import ( "Open_IM/pkg/common/log" "Open_IM/pkg/tools/splitter" "context" + "path/filepath" + "strconv" + firebase "firebase.google.com/go" "firebase.google.com/go/messaging" "google.golang.org/api/option" - "path/filepath" - "strconv" ) const SinglePushCountLimit = 400 @@ -67,6 +68,13 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, Msg.Notification = &messaging.Notification{} Msg.Notification.Body = detailContent Msg.Notification.Title = alert + if opts.IOSBadgeCount { + i := 1 + Msg.APNS.Payload.Aps.Badge = &i + } + if opts.IOSPushSound != "" { + Msg.APNS.Payload.Aps.Sound = opts.IOSPushSound + } ctx := context.Background() for _, v := range result { Msg.Tokens = v.Item diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 766704e1b..0e34ca5d9 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -318,7 +318,8 @@ func GetOfflinePushOpts(pushMsg *pbPush.PushMsgReq) (opts push.PushOpts, err err opts.Signal.ClientMsgID = pushMsg.MsgData.ClientMsgID log.NewDebug(pushMsg.OperationID, opts) } - + opts.IOSBadgeCount = pushMsg.MsgData.OfflinePushInfo.IOSBadgeCount + opts.IOSPushSound = pushMsg.MsgData.OfflinePushInfo.IOSPushSound } return opts, nil } diff --git a/internal/push/push_interface.go b/internal/push/push_interface.go index a1d45d7b7..1e177e74e 100644 --- a/internal/push/push_interface.go +++ b/internal/push/push_interface.go @@ -5,7 +5,9 @@ type OfflinePusher interface { } type PushOpts struct { - Signal Signal + Signal Signal + IOSPushSound string + IOSBadgeCount bool } type Signal struct { From caea072f7d7fb81678ebc92367bdbf77dc1055fa Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 31 Aug 2022 14:53:16 +0800 Subject: [PATCH 2/4] fcm --- internal/push/logic/push_to_client.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index b178d49ea..13ea1bb68 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -21,8 +21,9 @@ import ( "Open_IM/pkg/utils" "context" "encoding/json" - "github.com/golang/protobuf/proto" "strings" + + "github.com/golang/protobuf/proto" ) type OpenIMContent struct { @@ -323,9 +324,9 @@ func GetOfflinePushOpts(pushMsg *pbPush.PushMsgReq) (opts push.PushOpts, err err opts.Signal.ClientMsgID = pushMsg.MsgData.ClientMsgID log.NewDebug(pushMsg.OperationID, opts) } - opts.IOSBadgeCount = pushMsg.MsgData.OfflinePushInfo.IOSBadgeCount - opts.IOSPushSound = pushMsg.MsgData.OfflinePushInfo.IOSPushSound } + opts.IOSBadgeCount = pushMsg.MsgData.OfflinePushInfo.IOSBadgeCount + opts.IOSPushSound = pushMsg.MsgData.OfflinePushInfo.IOSPushSound return opts, nil } From d622f1df3dd62a5f563e3ce8beb7b284ef5272ce Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 31 Aug 2022 15:11:09 +0800 Subject: [PATCH 3/4] fcm --- internal/push/fcm/push.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/push/fcm/push.go b/internal/push/fcm/push.go index 48f6a9947..cedccbebe 100644 --- a/internal/push/fcm/push.go +++ b/internal/push/fcm/push.go @@ -68,6 +68,7 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, Msg.Notification = &messaging.Notification{} Msg.Notification.Body = detailContent Msg.Notification.Title = alert + Msg.APNS = &messaging.APNSConfig{Payload: &messaging.APNSPayload{Aps: &messaging.Aps{}}} if opts.IOSBadgeCount { i := 1 Msg.APNS.Payload.Aps.Badge = &i From 15ef064fc390362033d4739100779a79d1df2879 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Wed, 31 Aug 2022 17:32:40 +0800 Subject: [PATCH 4/4] user conn map copy --- internal/msg_gateway/gate/ws_server.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index f631a6c33..9b61318b3 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -368,7 +368,11 @@ func (ws *WServer) getUserAllCons(uid string) map[int]*UserConn { rwLock.RLock() defer rwLock.RUnlock() if connMap, ok := ws.wsUserToConn[uid]; ok { - return connMap + newConnMap := make(map[int]*UserConn) + for k, v := range connMap { + newConnMap[k] = v + } + return newConnMap } return nil }