-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
149 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
>>> | ||
class C { | ||
late final Command<MessageUpdateRequest, void> addNewMessageCommand = | ||
Command.createAsyncNoResult<MessageUpdateRequest>((newMessage) async { | ||
final chatApi = ChatsApi(di<ApiClient>()); | ||
if (_target == null) { | ||
assert(_chatPartner != null); | ||
_target = await chatApi.sendMessageToUserAndCreateChatIfNeeded( | ||
_chatPartner!.id.toString(), | ||
messageUpdateRequest: newMessage); | ||
} else { | ||
await chatApi.addMessageToChat(chatId, messageUpdateRequest: newMessage); | ||
} | ||
notifyListeners(); | ||
}, | ||
errorFilter: ApiErrorFilter( | ||
(error) => error.code == 412 || error.code == 403, | ||
ErrorReaction.localHandler, | ||
),debugName: cmdAddMessage) | ||
..errors.listen((ex,_) { | ||
final apiError = ex!.error as ApiException; | ||
|
||
/// TODO adjust to chatmessagesource | ||
items.removeLast(); | ||
lastMessage = null; | ||
refreshItemCOunt(); | ||
if (apiError.message?.contains('limited to 15 people') ?? false) { | ||
di<InteractionManager>().pushToastWithBuilder( | ||
(context) => ToastConfig( | ||
context.l10n.messagingLimitPerDay, | ||
), | ||
); | ||
} else if (apiError.message?.contains('Permission denied') ?? false) { | ||
di<InteractionManager>().pushToastWithBuilder( | ||
(context) => ToastConfig( | ||
context.l10n.defaultMessagingRestriction, | ||
), | ||
); | ||
} | ||
}); | ||
} | ||
<<< | ||
class C { | ||
late final Command<MessageUpdateRequest, void> addNewMessageCommand = | ||
Command.createAsyncNoResult<MessageUpdateRequest>( | ||
(newMessage) async { | ||
final chatApi = ChatsApi(di<ApiClient>()); | ||
if (_target == null) { | ||
assert(_chatPartner != null); | ||
_target = | ||
await chatApi.sendMessageToUserAndCreateChatIfNeeded( | ||
_chatPartner!.id.toString(), | ||
messageUpdateRequest: newMessage, | ||
); | ||
} else { | ||
await chatApi.addMessageToChat( | ||
chatId, | ||
messageUpdateRequest: newMessage, | ||
); | ||
} | ||
notifyListeners(); | ||
}, | ||
errorFilter: ApiErrorFilter( | ||
(error) => error.code == 412 || error.code == 403, | ||
ErrorReaction.localHandler, | ||
), | ||
debugName: cmdAddMessage, | ||
) | ||
..errors.listen((ex, _) { | ||
final apiError = ex!.error as ApiException; | ||
|
||
/// TODO adjust to chatmessagesource | ||
items.removeLast(); | ||
lastMessage = null; | ||
refreshItemCOunt(); | ||
if (apiError.message?.contains('limited to 15 people') ?? false) { | ||
di<InteractionManager>().pushToastWithBuilder( | ||
(context) => ToastConfig(context.l10n.messagingLimitPerDay), | ||
); | ||
} else if (apiError.message?.contains('Permission denied') ?? false) { | ||
di<InteractionManager>().pushToastWithBuilder( | ||
(context) => ToastConfig( | ||
context.l10n.defaultMessagingRestriction, | ||
), | ||
); | ||
} | ||
}); | ||
} | ||
>>> | ||
class C { | ||
late final Command<MessageUpdateRequest, void> addNewMessageCommand = | ||
Command.createAsyncNoResult<MessageUpdateRequest>(_addNewMessage, | ||
errorFilter: ApiErrorFilter( | ||
(error) => error.code == 412 || error.code == 403, | ||
ErrorReaction.localHandler, | ||
),debugName: cmdAddMessage) | ||
..errors.listen((ex,_) { | ||
final apiError = ex!.error as ApiException; | ||
|
||
/// TODO adjust to chatmessagesource | ||
items.removeLast(); | ||
lastMessage = null; | ||
refreshItemCOunt(); | ||
if (apiError.message?.contains('limited to 15 people') ?? false) { | ||
di<InteractionManager>().pushToastWithBuilder( | ||
(context) => ToastConfig( | ||
context.l10n.messagingLimitPerDay, | ||
), | ||
); | ||
} else if (apiError.message?.contains('Permission denied') ?? false) { | ||
di<InteractionManager>().pushToastWithBuilder( | ||
(context) => ToastConfig( | ||
context.l10n.defaultMessagingRestriction, | ||
), | ||
); | ||
} | ||
}); | ||
} | ||
<<< | ||
class C { | ||
late final Command<MessageUpdateRequest, void> addNewMessageCommand = | ||
Command.createAsyncNoResult<MessageUpdateRequest>( | ||
_addNewMessage, | ||
errorFilter: ApiErrorFilter( | ||
(error) => error.code == 412 || error.code == 403, | ||
ErrorReaction.localHandler, | ||
), | ||
debugName: cmdAddMessage, | ||
) | ||
..errors.listen((ex, _) { | ||
final apiError = ex!.error as ApiException; | ||
|
||
/// TODO adjust to chatmessagesource | ||
items.removeLast(); | ||
lastMessage = null; | ||
refreshItemCOunt(); | ||
if (apiError.message?.contains('limited to 15 people') ?? false) { | ||
di<InteractionManager>().pushToastWithBuilder( | ||
(context) => ToastConfig(context.l10n.messagingLimitPerDay), | ||
); | ||
} else if (apiError.message?.contains('Permission denied') ?? false) { | ||
di<InteractionManager>().pushToastWithBuilder( | ||
(context) => ToastConfig( | ||
context.l10n.defaultMessagingRestriction, | ||
), | ||
); | ||
} | ||
}); | ||
} |