5
5
from ..core import SUBSCRIBE
6
6
from .util import encrypt_notify_payload , derive_notifier_key , warn_on_except , NotifyStats
7
7
8
- import firebase_admin
9
- from firebase_admin import messaging
8
+ from pyfcm import FCMNotification
10
9
11
10
import oxenc
12
11
from oxenmq import OxenMQ , Message , Address , AuthLevel
@@ -72,11 +71,13 @@ def push_notification(msg: Message):
72
71
73
72
device_token = data [b"&" ].decode () # unique service id, as we returned from validate
74
73
75
- msg = messaging .Message (
76
- data = {"enc_payload" : oxenc .to_base64 (enc_payload ), "spns" : f"{ SPNS_FIREBASE_VERSION } " },
77
- token = device_token ,
78
- android = messaging .AndroidConfig (priority = "high" ),
79
- )
74
+ msg = {
75
+ 'fcm_token' : device_token ,
76
+ 'data_payload' : {
77
+ "enc_payload" : oxenc .to_base64 (enc_payload ),
78
+ "spns" : f"{ SPNS_FIREBASE_VERSION } "
79
+ }
80
+ }
80
81
81
82
global notify_queue , queue_lock
82
83
with queue_lock :
@@ -91,7 +92,7 @@ def send_pending():
91
92
92
93
i = 0
93
94
while i < len (queue ):
94
- results = messaging . send_each ( messages = queue [i : i + MAX_NOTIFIES ], app = firebase_app )
95
+ results = firebase_app . async_notify_multiple_devices ( params_list = queue [i : i + MAX_NOTIFIES ])
95
96
with stats .lock :
96
97
stats .notifies += min (len (queue ) - i , MAX_NOTIFIES )
97
98
@@ -120,7 +121,7 @@ def start():
120
121
# restart/reconnect and receive messages sent while we where restarting.
121
122
key = derive_notifier_key ("firebase" )
122
123
123
- global omq , hivemind , firebase , queue_timer
124
+ global omq , hivemind , firebase_app , queue_timer
124
125
125
126
omq = OxenMQ (pubkey = key .public_key .encode (), privkey = key .encode ())
126
127
@@ -143,8 +144,8 @@ def start():
143
144
Address (config .config .hivemind_sock ), auth_level = AuthLevel .basic , ephemeral_routing_id = False
144
145
)
145
146
146
- firebase_app = firebase_admin . initialize_app (
147
- firebase_admin . credentials . Certificate ( conf ["token_file" ])
147
+ firebase_app = FCMNotification (
148
+ service_account_file = conf ["token_file" ], project_id = "loki-5a81e"
148
149
)
149
150
150
151
omq .send (hivemind , "admin.register_service" , "firebase" )
0 commit comments