I have a sub in my FirebaseMessaging service that sends a message (as a Map). When I pass a message to the sub for sending I also want to save it in a list so that if the send fails, I can retry later. If the send is successful, the message is removed from the list.
As you can see from the code below, the message map is actually 2 maps - a "to" map & a "data" map.
When I send the first message it saves to the list ok, however every subsequent message added to the list results in all the previous ones' "data" map being set to empty ("data={}") & only the most recent message has any value in the "data" map.
For example, here's the log output if I send 3 messages & then loop through the values in messageList:
I don't understand why this is happening! Is there some kind of limitation when it comes to saving maps of maps to lists?
Here's the code:
- Colin.
As you can see from the code below, the message map is actually 2 maps - a "to" map & a "data" map.
When I send the first message it saves to the list ok, however every subsequent message added to the list results in all the previous ones' "data" map being set to empty ("data={}") & only the most recent message has any value in the "data" map.
For example, here's the log output if I send 3 messages & then loop through the values in messageList:
'SEND FIRST MESSAGE
(MyMap) {to=/topics/92bb34ae-3d76-4096-ad83-9f7f7b187a1d-AllUpdates, data={type=pos, sendername=Nexus, message=First message, lat=-41.292606064478186, lon=174.02045622467995, timestamp=1502492750494, group=AllUpdates, senderuuid=92bb34ae-3d76-4096-ad83-9f7f7b187a1d}}
'SEND SECOND MESSAGE
(MyMap) {to=/topics/92bb34ae-3d76-4096-ad83-9f7f7b187a1d-AllUpdates, data={}} 'FIRST MESSAGE DATA IS NOW EMPTY
(MyMap) {to=/topics/92bb34ae-3d76-4096-ad83-9f7f7b187a1d-AllUpdates, data={type=pos, sendername=Nexus, message=Second message, lat=-41.29621733886542, lon=174.02380764484408, timestamp=1502492800319, group=AllUpdates, senderuuid=92bb34ae-3d76-4096-ad83-9f7f7b187a1d}}
'SEND THIRD MESSAGE
(MyMap) {to=/topics/92bb34ae-3d76-4096-ad83-9f7f7b187a1d-AllUpdates, data={}} 'FIRST MESSAGE DATA IS NOW EMPTY
(MyMap) {to=/topics/92bb34ae-3d76-4096-ad83-9f7f7b187a1d-AllUpdates, data={}} 'SECOND MESSAGE DATA IS NOW EMPTY
(MyMap) {to=/topics/92bb34ae-3d76-4096-ad83-9f7f7b187a1d-AllUpdates, data={type=pos, sendername=Nexus, message=Third message, lat=-41.2970213844652, lon=174.02977053076032, timestamp=1502492868097, group=AllUpdates, senderuuid=92bb34ae-3d76-4096-ad83-9f7f7b187a1d}}
I don't understand why this is happening! Is there some kind of limitation when it comes to saving maps of maps to lists?
Here's the code:
B4X:
Private Sub sendLocationMessage(msg As String, lat As Double, lon As Double, group As String)
Private m As Map = CreateMap("to": $"/topics/${Starter.myUUID}-${group.Trim.Replace(" ", "")}"$)
Private data As Map = CreateMap("type": "pos", "sendername": Starter.cOpts.MyName, "message": msg, "lat": lat, "lon": lon, "timestamp": DateTime.Now, "group": group.Trim.Replace(" ", ""), "senderuuid": Starter.myUUID)
m.Put("data": data)
CallSub2(FirebaseMessaging, "sendMessage", m)
End Sub
Public Sub sendMessage(message As Map)
Private Job As HttpJob
Private jg As JSONGenerator
'messageList is declared in Process_Globals
If messageList.IndexOf(message) = -1 Then messageList.Add(message)
Job.Initialize("fcm", Me)
jg.Initialize(message)
Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
Job.GetRequest.SetContentType("application/json")
Job.GetRequest.SetHeader("Authorization", "key=" & Starter.API_KEY)
End Sub
- Colin.
Last edited: