ConnectyCube / connectycube-flutter-samples

Code samples for Flutter, based on ConnectyCube platform
https://developers.connectycube.com/flutter/
Apache License 2.0
85 stars 91 forks source link

forground notification #304

Closed richanshah closed 8 months ago

richanshah commented 11 months ago

@TatankaConCube , Is there any way I can get foreground notification , when in my app chat screen is not open ?

TatankaConCube commented 11 months ago

it is the app-side feature. you can listen for messages in the ChatMessagesManager and if received the message is not from an opened chat, show some popup

richanshah commented 11 months ago

it is the app-side feature. you can listen for messages in the ChatMessagesManager and if received the message is not from an opened chat, show some popup

@TatankaConCube can u help me where to put and what conditions are needed?

TatankaConCube commented 11 months ago

in your main listener (somewhere in the main app controller), you can check if the received message's dialog screen is opened, and if not, show the in-app notification

richanshah commented 11 months ago

@TatankaConCube do i have to listen to final ChatMessagesManager? chatMessagesManager = CubeChatConnection.instance.chatMessagesManager;

this in main controller of the app?

TatankaConCube commented 11 months ago

I don't know what is the main controller of YOUR app. It could be a main app widget, another widget, or some manager/helper for working with chat. but you are right, you should listen the ChatMessagesManager there for catching new messages.

richanshah commented 11 months ago

@TatankaConCube yes its main app widget, i tried this code

StreamSubscription? msgSubscription; msgSubscription = chatMessagesManager?.chatMessagesStream.listen(onReceiveMessage);

/// Called when message received from connectycube void onReceiveMessage(CubeMessage message) { log("onReceiveMessage global message= $message"); log('[showNotification] RR message: ${message}');

// Check if the message is not read
showNotification(message);
log('[showNotification] SS message: ${message}');

}

but not getting anything in here. can u please let me know what is missing here?

richanshah commented 11 months ago

getting this in log but i dont know where this log is coming from as i have not added any logs like this

CB-SDK: : Receive GROUP chat message 651cfdb7d39f117547c8dcf1

richanshah commented 11 months ago

@TatankaConCube , Sometimes i get this

                                 I  CB-SDK: : *********************************************************
                                 I  *** RESPONSE *** 201 *** f0e53e21-4043-4a99-8819-5bfcf6b65647 ***
                                 I  HEADERS
                                 I    {cb-token-expirationdate: 2023-10-04 07:58:35 UTC, connection: keep-alive, date: Wed, 04 Oct 2023 05:58:35 GMT, strict-transport-security: max-age=15768000; includeSubDomains, content-length: 870, access-control-expose-headers: CB-Token-ExpirationDate, Date, content-type: application/json; charset=utf-8, server: nginx/1.25.0}
                                 I  BODY
                                 I    {"session":{"created_at":"2023-10-04T05:58:35.621Z","updated_at":"2023-10-04T05:58:35.621Z","application_id":7266,"token":"CB81EC205AACCF33013DD4ADF03593478035","nonce":1637986659,"ts":1696399113,"user_id":11136638,"id":11136638,"user":{"_id":"65167df928fcf9002f85a274","id":11136638,"created_at":"2023-09-29T07:34:17Z","updated_at":"2023-10-04T05:52:10Z","last_request_at":"2023-10-04T05:52:10Z","login":"a1f9d2bd-3303-4819-b360-43b9b30970f4","email":"ronak@gmail.com","full_name":"Ronak Mehta","phone":"9409112712","custom_data":"{uuid: a1f9d2bd-3303-4819-b360-43b9b30970f4}","avatar":"https://main-court-demo122136-dev.s3.amazonaws.com/public/User/1695966673915018/1695966673915018.jpg","external_id":"a1f9d2bd-3303-4819-b360-43b9b30970f4","timezone":null,"website":null,"twitter_id":null,"external_user_id":null,"facebook_id":null,"user_tags":null,"is_guest":null}}}
                                 I  
                                 I  CB-SDK: : login with = {full_name: Ronak Mehta, address_book_name: null, email: ronak@gmail.com, login: a1f9d2bd-3303-4819-b360-43b9b30970f4, phone: 9409112712, website: null, last_request_at: null, external_user_id: null, external_id: null, facebook_id: null, twitter_id: null, password: F41C7C258773A4B5E90A2DBBFEE2F9897EB4, oldPassword: null, custom_data: null, avatar: https://main-court-demo122136-dev.s3.amazonaws.com/public/User/1695966673915018/1695966673915018.jpg, guest: null, timezone: null, tag_list: null, id: 11136638, created_at: null, updated_at: null}
                                 I  CB-SDK: CubeChatConnection: [login] userId: 11136638, resourceId: null
                                 I  CB-SDK: CubeChatConnection: Chat connection SocketOpening
                                 I  Response:
                                 I  URL: null
                                 I  Response: {getNewsList: {meta: {status: true, message: Data fetched successfully, message_code: LIST_SUCCESS, status_code: 200, __typename: Meta}, data: [{uuid: c51e3d68-bb36-4090-9874-341b5d439ffc, title: maincourt news, description: <p>hellooooooo</p>, image: images.jpeg, file_path: https://main-court-demo.s3.amazonaws.com/images/News/1209757538014, file_type: image, type: News, created_at: Sep 28, 2023 - 01:50 pm, is_like: false, comment_count: 0, like_count: 1, __typename: NewsListFront}], pagination: {offset: 1, limit: 5, total_count: 1, __typename: Pagination}, __typename: NewsListFrontInfo}, __typename: Query}
                                 I  
                                 I  
                                 I  news list = [Instance of 'QueryGetNewsListgetNewsListdata']
                                 I  CB-SDK: CubeChatConnection: Chat connection SocketOpened
                                 I  CB-SDK: CubeChatConnection: Chat connection AuthenticationFailure
                                 I  CB-SDK: CubeChatConnection: Chat connection Closing
                                 I  CB-SDK: CubeChatConnection: Chat connection Closed 

dont know why this happens

richanshah commented 11 months ago

@TatankaConCube how about i mark chat session as in active in the places where chat module is not needed. and only make it active when chat is needed. that way i can also get forground notifications right?

richanshah commented 11 months ago

@TatankaConCube i have maintained it with like this . i did CubeChatConnection.instance.markInactive() when my chat ui is closed in the app, that way i am getting forground notifications. can u tell me if there is any other purpose of this line CubeChatConnection.instance.markInactive()

richanshah commented 11 months ago

@TatankaConCube sometimes i am getting notifications from connectycube even if my session is active , why is that ?

TatankaConCube commented 10 months ago

our back will send the push notifications in the next cases:

richanshah commented 10 months ago

great thanks for the update @TatankaConCube