-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add login exception on authentication failed
* Add example
- Loading branch information
Sebastien Dugene
committed
Dec 29, 2020
1 parent
5026b8b
commit cca1d20
Showing
5 changed files
with
58 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:rocket_chat_connector_flutter/models/channel.dart'; | ||
import 'package:rocket_chat_connector_flutter/models/channel_counters.dart'; | ||
import 'package:rocket_chat_connector_flutter/models/channel_messages.dart'; | ||
import 'package:rocket_chat_connector_flutter/models/filters/channel_counters_filter.dart'; | ||
import 'package:rocket_chat_connector_flutter/models/filters/channel_history_filter.dart'; | ||
import 'package:rocket_chat_connector_flutter/models/new/message_new.dart'; | ||
import 'package:rocket_chat_connector_flutter/models/response/message_new_response.dart'; | ||
import 'package:rocket_chat_connector_flutter/services/authentication_service.dart'; | ||
import 'package:rocket_chat_connector_flutter/services/channel_service.dart'; | ||
import 'package:rocket_chat_connector_flutter/services/http_service.dart' as rocket_http_service; | ||
import 'package:rocket_chat_connector_flutter/services/message_service.dart'; | ||
|
||
final String serverUrl = "myServerUrl"; | ||
final String username = "myUserName"; | ||
final String password = "myPassword"; | ||
final Channel channel = Channel(id: "myChannelId"); | ||
|
||
final rocket_http_service.HttpService rocketHttpService = rocket_http_service.HttpService(serverUrl); | ||
final AuthenticationService authenticationService = AuthenticationService(rocketHttpService); | ||
final ChannelService channelService = ChannelService(rocketHttpService); | ||
final MessageService messageService = MessageService(rocketHttpService); | ||
|
||
Future main(List<String> args) async { | ||
rocket_http_service.HttpService.authentication = await authenticationService.login(username, password); | ||
|
||
// get channel message counter | ||
ChannelCountersFilter filter = ChannelCountersFilter(channel); | ||
ChannelCounters counters = await channelService.counters(filter); | ||
print("Channel have ${counters.unreads} unread messages"); | ||
|
||
// get channel message list | ||
ChannelHistoryFilter channelHistoryFilter = ChannelHistoryFilter(channel, count: 50); | ||
ChannelMessages channelMessages = await channelService.history(channelHistoryFilter); | ||
print("Last message : ${channelMessages.messages.first.ts} : ${channelMessages.messages.first.msg}"); | ||
|
||
// send message | ||
MessageNew messageNew = MessageNew(roomId: channel.id, text: "my message"); | ||
MessageNewResponse response = await messageService.postMessage(messageNew); | ||
print("Message send success : ${response.success}"); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class LoginException implements Exception { | ||
String message; | ||
LoginException(this.message); | ||
|
||
String toString() { | ||
if (message == null) return "LoginException"; | ||
return "LoginException: $message"; | ||
} | ||
} |
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