-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! TF-3157 Implement web socket push
- Loading branch information
1 parent
575edd9
commit dbf30b0
Showing
7 changed files
with
50 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 27 additions & 3 deletions
30
lib/features/push_notification/data/network/web_socket_api.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
|
||
import 'package:core/data/network/dio_client.dart'; | ||
import 'package:jmap_dart_client/jmap/account_id.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/web_socket_ticket_capability.dart'; | ||
import 'package:jmap_dart_client/jmap/core/session/session.dart'; | ||
import 'package:model/extensions/session_extension.dart'; | ||
import 'package:tmail_ui_user/features/push_notification/data/model/web_socket_ticket.dart'; | ||
import 'package:tmail_ui_user/features/push_notification/domain/exceptions/web_socket_exceptions.dart'; | ||
|
||
class WebSocketApi { | ||
final DioClient _dioClient; | ||
|
||
WebSocketApi(this._dioClient); | ||
|
||
Future<WebSocketTicket> getWebSocketTicket(String url) async { | ||
final response = await _dioClient.post(url); | ||
return WebSocketTicket.fromJson(response); | ||
Future<String> getWebSocketTicket( | ||
Session session, | ||
AccountId accountId | ||
) async { | ||
final webSocketTicketCapability = session.getCapabilityProperties<WebSocketTicketCapability>( | ||
accountId, | ||
CapabilityIdentifier.jmapWebSocketTicket); | ||
|
||
final webSocketTicketGenerationUrl = webSocketTicketCapability?.generationEndpoint; | ||
if (webSocketTicketGenerationUrl == null) { | ||
throw WebSocketTicketUnavailableException(); | ||
} | ||
final webSocketTicketGenerationResponse = await _dioClient.post( | ||
'$webSocketTicketGenerationUrl'); | ||
final webSocketTicket = WebSocketTicket.fromJson( | ||
webSocketTicketGenerationResponse); | ||
if (webSocketTicket.value == null) { | ||
throw WebSocketTicketUnavailableException(); | ||
} | ||
|
||
return webSocketTicket.value!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters