wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:recycle: rename envelope data_type format

Kacaii 55a02df9 25b7d289

+15 -15
+15 -15
src/app/web/socket.gleam
··· 25 25 26 26 /// Connecting to a websocket can fail 27 27 pub opaque type WebSocketError { 28 - /// Session cookie was not found 28 + /// 󱛪 Session cookie was not found 29 29 MissingCookie 30 - /// `crypto.verify_signed_message` failed 30 + /// 󰣮 Failed to verify signed message 31 31 InvalidSignature 32 - /// The signed message could not be properly decrypted 32 + /// 󱦃 The signed message could not be properly decrypted 33 33 InvalidUtf8 34 - /// Decrypted string was not a valid Uuid 34 + /// 󰘨 Session token has invalid Uuid fomat 35 35 InvalidUuid(String) 36 36 } 37 37 ··· 126 126 send_envelope( 127 127 state:, 128 128 conn:, 129 - data_type: "assigned_to_brigade", 129 + data_type: "brigade:assigned", 130 130 data: json.object([ 131 131 #("user_id", uuid.to_string(user_id) |> json.string), 132 132 #("brigade_id", uuid.to_string(brigade_id) |> json.string), ··· 137 137 send_envelope( 138 138 state:, 139 139 conn:, 140 - data_type: "assigned_to_occurrence", 140 + data_type: "occurrence:assigned", 141 141 data: json.object([ 142 142 #("user_id", uuid.to_string(user_id) |> json.string), 143 143 #("occurrence_id", uuid.to_string(occurrence_id) |> json.string), ··· 153 153 send_envelope( 154 154 state:, 155 155 conn:, 156 - data_type: "new_occurrence", 156 + data_type: "occurrence:new", 157 157 data: json.object([ 158 158 #("id", json.string(uuid.to_string(occ_id))), 159 159 #("occ_type", json.string(category.to_string_pt_br(occ_type))), ··· 162 162 } 163 163 164 164 msg.OccurrenceResolved(id:, when:) -> { 165 + let timestamp_json = 166 + json.nullable(when, fn(time) { 167 + timestamp.to_unix_seconds(time) |> json.float 168 + }) 169 + 165 170 send_envelope( 166 171 state:, 167 172 conn:, 168 - data_type: "occurrence_resolved", 173 + data_type: "occurrence:resolved", 169 174 data: json.object([ 170 175 #("id", json.string(uuid.to_string(id))), 171 - #( 172 - "timestamp", 173 - json.nullable(when, fn(time) { 174 - timestamp.to_unix_seconds(time) |> json.float 175 - }), 176 - ), 176 + #("timestamp", timestamp_json), 177 177 ]), 178 178 ) 179 179 } ··· 200 200 // 󱅡 Send data 201 201 let msg_result = mist.send_text_frame(conn, json.to_string(envelope_json)) 202 202 case msg_result { 203 - Error(_) -> mist.stop_abnormal("Failed to send envelope to User") 203 + Error(_) -> mist.stop_abnormal("Failed to send message to User") 204 204 Ok(_) -> mist.continue(state) 205 205 } 206 206 }