ConnectyCube / connectycube-flutter-samples

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

Adding user to dialog which does not exist in user. #311

Open richanshah opened 9 months ago

richanshah commented 9 months ago

@TatankaConCube , I have feature when user gets invites of joining group. in here I tried to find dialog with custom paramter feild groupuuid but the problem is In this user dialog is not currently exist so i am not able to find same diaog and add user into this.

is there any code or functonality which can help me to complete this feature ?

Screenshot_1695971873

getDialogs: {currentPage: null, totalEntries: 16, perPage: null, skip: 0, limit: 100, items: [{_id: 651674bbecbe27002ff9411f, last_message: null, last_message_date_sent: null, last_message_user_id: null, photo: https://main-court-demo122136-dev.s3.amazonaws.com/public/Group/1695970483654298/1695970483654298.jpg, user_id: 10909924, xmpp_room_jid: 7266_651674bbecbe27002ff9411f@muc.chat.connectycube.com, unread_messages_count: 0, name: we3, type: 2, description: null, occupants_count: 2, occupants_ids: [10909837, 10909924], pinned_messages_ids: [], admins_ids: [], data: {groupUuid: 06e3c452-624e-4f13-818a-6ced5c536b16, class_name: CUSTOM_DIALOG_PARAMS}, last_message_status: null, last_message_id: null, is_e2ee: false, is_muted: false, id: null, created_at: 2023-09-29T06:54:51.000Z, updated_at: 2023-09-29T06:59:30.000Z}, {_id: 65166f41ecbe27002ff940a1, last_message: null, last_message_date_sent: null, last_message_user_id: null, photo: /, user_id: 10909837, xmpp_room_jid: 7266_65166f41ecbe27002ff940a1@ I CB-SDK: : _createDialog with user= null I CB-SDK: : ========================================================= I === REQUEST ==== f2da1dfb-20da-49cf-8870-234debe3eaa9 === I REQUEST I PUT https://api.connectycube.com/chat/Dialog/ I HEADERS I {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 2.8.0, CB-Token: 4BBDBF006350CC77F9C8E350DE81787922A2} I BODY I {"push_all":{"occupants_ids":[10909837]}} I
I CB-SDK: : *** I * RESPONSE 404 f2da1dfb-20da-49cf-8870-234debe3eaa9 *** I HEADERS I {connection: keep-alive, content-type: text/plain; charset=utf-8, date: Fri, 29 Sep 2023 07:15:15 GMT, strict-transport-security: max-age=15768000; includeSubDomains, server: nginx/1.25.0, content-length: 67} I BODY I HttpException: E_ROUTE_NOT_FOUND: Route not found PUT /chat/Dialog/ I
I CB-SDK: : updateDialogInfo error ResponseException: 404: HttpException:

I need to find dialog which doesnt exist in this user but in connectycube

richanshah commented 9 months ago

can u give me method like getAllDialogs ? from connectycube ?

TatankaConCube commented 9 months ago

I can see the next solution here:

  1. Use PUBLIC_GROUP dialogs in case you want to invite any user there;
  2. In the admin panel you need to create the 'invite_dialog' scheme which will contain the next fields required for displaying the invite on the user's screen:
    {
    'dialog_id':'',
    'dialog_name': '',
    'dialog_description': '',
    'inviting_user': 0,
    'invited_user': 1,
    'status': 'invited',
    // other field required by your app
    }
  3. The inviting user creates the custom object with the Invite data;
  4. The inviting user sends the system message to the invited user about the Inviting event;
  5. The invited user after receiving this message goes to the Invites screen and loads all custom objects with class name you created before for invites and with filter by field 'invited_user' (for loading invites for current user only).
  6. After accepting the invite the user performs join to the public dialog (after this it can load this dialog and its messages);
  7. Invited user updates the custom object by updating field 'status' to 'accepted';
  8. If the invited user rejects the invite it just updates the custom object's field 'status' to 'rejected'.

If you prefer to use the GROUP dialogs for it, you need to develop the logic for notifying the inviting user about the necessity to update the group dialog by adding the invited user to the dialog members.

richanshah commented 9 months ago

@TatankaConCube , well, invitation flow is already in my app, i tried with public group. and push all method for adding new occupants but look i am getting below error, why?

I/flutter ( 7130): REQUEST I/flutter ( 7130): PUT https://api.connectycube.com/chat/Dialog/65169f96ecbe27002ff949d0 I/flutter ( 7130): HEADERS I/flutter ( 7130): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 2.8.0, CB-Token: 517F3EAC3A60514C780CE4CEFAAEEF1AE7D5} I/flutter ( 7130): BODY I/flutter ( 7130): {"push_all":{"occupants_ids":[11136638]}} I/flutter ( 7130): I/flutter ( 7130): CB-SDK: : *** I/flutter ( 7130): * RESPONSE 403 05c0529d-5388-4f23-8b54-46691b8cb5d3 *** I/flutter ( 7130): HEADERS I/flutter ( 7130): {connection: keep-alive, content-type: application/json; charset=utf-8, date: Fri, 29 Sep 2023 09:59:43 GMT, strict-transport-security: max-age=15768000; includeSubDomains, server: nginx/1.25.0, content-length: 88} I/flutter ( 7130): BODY I/flutter ( 7130): {"errors":{"base":["You don't have appropriate permissions to perform this operation"]}}

below group is created my another user as public group , and as per above code i am trying to add user in that public group , which should work , right?

POST https://api.connectycube.com/chat/Dialog I/flutter (13440): HEADERS I/flutter (13440): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 2.8.0, CB-Token: 5FD6D4F23E43305721DB13558A81C7698034} I/flutter (13440): BODY I/flutter (13440): {"photo":"/","name":"yo yo","type":4,"occupants_ids":[10909924],"data":{"groupUuid":"458baefa-9d19-4745-b1ee-657392695615","class_name":"CUSTOM_DIALOG_PARAMS"}} I/flutter (13440): I/flutter (13440): CB-SDK: : *** I/flutter (13440): * RESPONSE 201 0a1474c4-c060-4495-bb7c-98080c8f7edf *** I/flutter (13440): HEADERS I/flutter (13440): {cb-token-expirationdate: 2023-09-29 11:57:42 UTC, connection: keep-alive, date: Fri, 29 Sep 2023 09:57:42 GMT, strict-transport-security: max-age=15768000; includeSubDomains, content-length: 601, access-control-expose-headers: CB-Token-ExpirationDate, Date, content-type: application/json; charset=utf-8, server: nginx/1.25.0} I/flutter (13440): BODY I/flutter (13440): {"_id":"65169f96ecbe27002ff949d0","user_id":10909924,"created_at":"2023-09-29T09:57:42Z","updated_at":"2023-09-29T09:57:42Z","name":"yo yo","type":4,"photo":"/","occupants_count":1,"xmpp_room_jid":"7266_65169f96ecbe27002ff949d0@muc.chat.connectycube.com","admins_ids":[],"is_muted":false,"last_message":null,"last_message_date_sent":null,"last_message_id":null,"last_message_user_id":null,"last_message_status":null,"unread_messages_count":0,"pinned_messages_ids":[],"data":{"groupUuid":"458baefa-9d19-4745-b1ee-657392695615","class_name":"CUSTOM_DIALOG_PARAMS"},"description":null,"occupants_ids":[]}

TatankaConCube commented 9 months ago

no, please read our doc first https://developers.connectycube.com/server/chat?id=roles-and-privileges you need to use the subscribeToDialog function if you want to become a member of the PUBLIC_GROUP dialog

richanshah commented 9 months ago

ok got it, trying to fetch old messages in public group but getting this error @TatankaConCube

I/flutter ( 7130): CB-SDK: : ========================================================= I/flutter ( 7130): === REQUEST ==== b9a85a84-678f-45a6-8ff3-012b51470b0e === I/flutter ( 7130): REQUEST I/flutter ( 7130): GET https://api.connectycube.com/chat/Message?chat_dialog_id=6516a87becbe27002ff94d22&limit=50&sort_desc=date_sent&date_sent%5Bgt%5D=0 I/flutter ( 7130): HEADERS I/flutter ( 7130): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 2.8.0, CB-Token: F6999974DC446E00AEDE9F4C0C8941D4135A} I/flutter ( 7130): BODY I/flutter ( 7130):
I/flutter ( 7130): I/flutter ( 7130): CB-SDK: : ========================================================= I/flutter ( 7130): === REQUEST ==== 79f460e5-ff9e-456e-aa89-35806e09fe1c === I/flutter ( 7130): REQUEST I/flutter ( 7130): GET https://api.connectycube.com/users/v2 I/flutter ( 7130): HEADERS I/flutter ( 7130): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 2.8.0, CB-Token: F6999974DC446E00AEDE9F4C0C8941D4135A} I/flutter ( 7130): BODY I/flutter ( 7130):
I/flutter ( 7130): I/flutter ( 7130): Another exception was thrown: Invalid argument(s): No host specified in URI / [GETX] Info: _GetImpl Instance of '_GetImpl' #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2751:9)

1 _HttpClient.openUrl (dart:_http/http_impl.dart:2622:7)

2 IOClient.send (package:http/src/io_client.dart:88:38)

3 HttpFileService.get (package:flutter_cache_manager/src/web/file_service.dart:37:44)

4 WebHelper._download (package:flutter_cache_manager/src/web/web_helper.dart:115:24)

5 WebHelper._updateFile (package:flutter_cache_manager/src/web/web_helper.dart:97:28)

#6 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:65:7) I/flutter ( 7130): CB-SDK: : ********************************************************* I/flutter ( 7130): *** RESPONSE *** 200 *** b9a85a84-678f-45a6-8ff3-012b51470b0e *** I/flutter ( 7130): HEADERS I/flutter ( 7130): {cb-token-expirationdate: 2023-09-29 12:58:51 UTC, connection: keep-alive, date: Fri, 29 Sep 2023 10:58:51 GMT, strict-transport-security: max-age=15768000; includeSubDomains, content-length: 1527, access-control-expose-headers: CB-Token-ExpirationDate, Date, content-type: application/json; charset=utf-8, server: nginx/1.25.0} I/flutter ( 7130): BODY I/flutter ( 7130): {"skip":0,"limit":50,"items":[{"_id":"6516ad55bc52d7d3c3dc3f3c","chat_dialog_id":"6516a87becbe27002ff94d22","message":"yoo","date_sent":1695984981,"sender_id":11136638,"recipient_id":null,"created_at":"2023-09-29T10:56:21Z","updated_at":"2023-09-29T10:58:37Z","read_ids":[11136638,10909924],"delivered_ids":[11136638,10909924],"views_count":2,"reactions":null,"attachments":[],"edited_at":null,"read":1},{"_id":"6516ad50bc52d7d3c3dc3f3b","chat_dialog_id":"6516a87becbe27002ff94d22","message":"hiiii","date_sent":1695984976,"sender_id":11136638,"recipient_id":null,"created_at":"2023-09-29T10:56:16Z","updated_at":"2023-09-29T10:58:37Z","read_ids":[11136638,10909924],"delivered_ids":[11136638,10909924],"views_count":2,"reactions":null,"attachments":[],"edited_at":null,"read":1},{"_id":"6516a9437503fb8c1fd580c7","chat_dialog_id":"6516a87becbe27002ff94d22","message":"yo","date_sent":1695983939,"sender_id":11136638,"recipient_id":null,"created_at":"2023-09-29T10:39:00Z","updated_at":"2023-09-29T10:58:37Z","read_ids":[ I/flutter ( 7130): I/flutter ( 7130): CB-SDK: : ********************************************************* I/flutter ( 7130): *** RESPONSE *** 422 *** 79f460e5-ff9e-456e-aa89-35806e09fe1c *** I/flutter ( 7130): HEADERS I/flutter ( 7130): {connection: keep-alive, content-type: application/json; charset=utf-8, date: Fri, 29 Sep 2023 10:58:51 GMT, strict-transport-security: max-age=15768000; includeSubDomains, server: nginx/1.25.0, content-length: 88} I/flutter ( 7130): BODY I/flutter ( 7130): {"errors":{"base":["At least one stand-alone field with primary operator is required"]}} I/flutter ( 7130): [GETX] Info: _GetImpl Instance of '_GetImpl' runZonedGuarded: ResponseException: 422: {"errors":{"base":["At least one stand-alone field with primary operator is required"]}}
richanshah commented 9 months ago

this is the code

/// Get All Messages of user Future<List> getMessagesList() async { showLoader(value: true); if (listMessage.isNotEmpty) return Future.value(listMessage);

Completer<List<CubeMessage>> completer = Completer();
List<CubeMessage>? messages;
try {
  await Future.wait<void>([
    getMessagesByDate(0, false).then((loadedMessages) {
      showLoader(value: false);
      messages = loadedMessages;
    }),
    getAllUsersByIds(cubeDialog.occupantsIds!.toSet()).then((result) => occupants.addAll({for (var item in result!.items) item.id: item}))
  ]);
  if (messages != null) {
    dataFetched.value = true;
    listMessage.addAll(messages as Iterable<CubeMessage>);
  }
  showLoader(value: false);
  completer.complete(messages);
} catch (error) {
  showLoader(value: false);
  completer.completeError(error);
}
return completer.future;

}

/// Get Messages by date Future<List> getMessagesByDate(int date, bool isLoadNew) async { var params = GetMessagesParameters(); params.sorter = RequestSorter(AppConstant.sortDesc, '', 'date_sent'); params.limit = messagesPerPage; params.filters = [RequestFilter('', 'date_sent', isLoadNew || date == 0 ? 'gt' : 'lt', date)];

return getMessages(cubeDialog.dialogId!, params.getRequestParameters())
    .then((result) {
      lastPartSize = result!.items.length;

      return result.items;
    })
    .whenComplete(() {})
    .catchError((onError) {
      return List<CubeMessage>.empty(growable: true);
    });

}

TatankaConCube commented 9 months ago

could you please print to the console output of cubeDialog.occupantsIds!.toSet()? can it by an empty array?

richanshah commented 9 months ago

@TatankaConCube yes getting occupantsIds= [] as empty, can u provide me the proper way for this?, Even in ur demo project public group concept i not found.

TatankaConCube commented 9 months ago

@richanshah please read our documentation https://developers.connectycube.com/flutter/messaging?id=retrieve-public-dialog-occupants

richanshah commented 9 months ago

@TatankaConCube , why in ur sample public group is not included? can u please add in sample

TatankaConCube commented 9 months ago

we provided samples to demonstrate how to work with the most popular APIs of our SDKs, we can't add all possible functionality to the app. we try to cover all our APIs with documentation to simplify the using of it by developers

richanshah commented 9 months ago

@TatankaConCube , With public group tried

@richanshah please read our documentation https://developers.connectycube.com/flutter/messaging?id=retrieve-public-dialog-occupants

i have tried this but getting error @TatankaConCube

https://api.connectycube.com/chat/Dialog/651bd626ecbe27002ffa55a7/occupants I/flutter (25935): HEADERS I/flutter (25935): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 2.8.0, CB-Token: F8E156B2FF39656B72CBD89B899D8F70E001} I/flutter (25935): BODY I/flutter (25935):
I/flutter (25935): I/flutter (25935): Another exception was thrown: Invalid argument(s): No host specified in URI / [GETX] Info: _GetImpl Instance of '_GetImpl' #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2751:9)

1 _HttpClient.openUrl (dart:_http/http_impl.dart:2622:7)

2 IOClient.send (package:http/src/io_client.dart:88:38)

3 HttpFileService.get (package:flutter_cache_manager/src/web/file_service.dart:37:44)

4 WebHelper._download (package:flutter_cache_manager/src/web/web_helper.dart:115:24)

5 WebHelper._updateFile (package:flutter_cache_manager/src/web/web_helper.dart:97:28)

#6 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:65:7) I/flutter (25935): CB-SDK: CubeChatConnection: Chat connection SocketOpened I/flutter (25935): CB-SDK: CubeChatConnection: Chat connection SocketOpened [log] D/[Connection]: State: XmppConnectionState.SocketOpened [log] ---Xmpp Sending:--- [log] [log] ---Xmpp Receiving:--- [log] [log] D/[Connection]: processInitialStream [log] ---Xmpp Receiving:--- [log] PLAINANONYMOUSPLAIN_FASTzlib [log] D/[ConnectionNegotiatorManager]: Negotiating features [log] D/[ConnectionNegotiatorManager]: Found matching negotiator true [log] ---Xmpp Sending:--- [log] ADExMTM2NjM4LTcyNjYARjhFMTU2QjJGRjM5NjU2QjcyQ0JEODlCODk5RDhGNzBFMDAx [log] D/[ConnectionNegotiatorManager]: ACTIVE FEATURE: {name: SaslAuthenticationFeature, name_space: null, priority: 1000, state: NegotiatorState.NEGOTIATING}, isReady: true [log] ---Xmpp Receiving:--- [log] I/flutter (25935): CB-SDK: CubeChatConnection: Chat connection Authenticated I/flutter (25935): CB-SDK: CubeChatConnection: Chat connection Authenticated [log] ---Xmpp Sending:--- I/flutter (25935): CB-SDK: : [_initCubeChat] state CubeChatConnectionState.Authenticated [log] [log] D/[Connection]: State: XmppConnectionState.Authenticated [log] D/[ConnectionNegotiatorManager]: Found matching negotiator true [log] ---Xmpp Sending:--- [log] [log] D/[ConnectionNegotiatorManager]: ACTIVE FEATURE: {name: StreamManagementModule, name_space: null, priority: 1000, state: NegotiatorState.NEGOTIATING}, isReady: true [log] D/[ConnectionNegotiatorManager]: Feature Started Parsing [log] ---Xmpp Receiving:--- [log] [log] D/[Connection]: processInitialStream I/flutter (25935): CB-SDK: : ********************************************************* I/flutter (25935): *** RESPONSE *** 404 *** 99c1261d-052f-4607-8bce-c0a2695f6d0f *** I/flutter (25935): HEADERS I/flutter (25935): {connection: keep-alive, content-type: application/json; charset=utf-8, date: Tue, 03 Oct 2023 09:10:47 GMT, strict-transport-security: max-age=15768000; includeSubDomains, server: nginx/1.25.0, content-length: 24} I/flutter (25935): BODY I/flutter (25935): {"errors":["Not found"]}
richanshah commented 9 months ago

@TatankaConCube , how can i delete public dialogs ? who has ownership ?

DELETE https://api.connectycube.com/chat/Dialog/6516a87becbe27002ff94d22 I HEADERS I {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 2.8.0, CB-Token: AF1ECA47AD1AD666796A7C658B3A64E2D98C} I BODY I

i tried this api, it gives success but it doesn't delete dialog from api

TatankaConCube commented 9 months ago

I/flutter (25935): {"errors":["Not found"]}

is your user a member of this dialog? was it joined to dialog before?

how can i delete public dialogs ? who has ownership ?

in your example you delete dialog for current user only, you need to use the parameter force = true in case you want to delete dialog completely for all users, we say about it in our documentation https://developers.connectycube.com/flutter/messaging?id=remove-dialog

the users' permissions I provided before in this thread above https://github.com/ConnectyCube/connectycube-flutter-samples/issues/311#issuecomment-1740649525

richanshah commented 9 months ago

is your user a member of this dialog? was it joined to dialog before?

yes already joined and also did chat

TatankaConCube commented 9 months ago

could you please provide the full log which contains the joining flow and the requests of the participants (without any cutting and filtering)

TatankaConCube commented 9 months ago

is this public dialog?

richanshah commented 9 months ago

is this public dialog?

YES

richanshah commented 9 months ago

could you please provide the full log which contains the joining flow and the requests of the participants (without any cutting and filtering)

that is difficult

TatankaConCube commented 9 months ago

that is difficult

then try to do it with parts, I just need to see the same dialog id in all requests (join, get occupants, etc.)

richanshah commented 9 months ago

@TatankaConCube Can u help me to find out why this happens

                 I  
                                 I  news list = [Instance of 'QueryGetNewsListgetNewsListdata']
                                 I  CB-SDK: : *********************************************************
                                 I  *** RESPONSE *** 201 *** ba192362-4a56-40ea-8468-fee5a07a7704 ***
                                 I  HEADERS
                                 I    {cb-token-expirationdate: 2023-10-05 14:34:22 UTC, connection: keep-alive, date: Thu, 05 Oct 2023 12:34:22 GMT, strict-transport-security: max-age=15768000; includeSubDomains, content-length: 876, 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-05T12:34:22.580Z","updated_at":"2023-10-05T12:34:22.580Z","application_id":7266,"token":"A528A013164174F42FE054DEB0CAA304FEC8","nonce":236412525,"ts":1696509260,"user_id":11169340,"id":11169340,"user":{"_id":"651ea85728fcf9002f87338b","id":11169340,"created_at":"2023-10-05T12:13:11Z","updated_at":"2023-10-05T12:22:22Z","last_request_at":"2023-10-05T12:22:22Z","login":"53b4141e-fb58-44d5-a450-578fca1a933a","email":"richa.shah@brainvire.com","full_name":"rich shah","phone":"6033333333","custom_data":"{uuid: 53b4141e-fb58-44d5-a450-578fca1a933a}","avatar":"https://main-court-demo122136-dev.s3.amazonaws.com/public/User/1696507981210490/1696507981210490.jpg","external_id":"53b4141e-fb58-44d5-a450-578fca1a933a","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: rich shah, address_book_name: null, email: richa.shah@brainvire.com, login: 53b4141e-fb58-44d5-a450-578fca1a933a, phone: 6033333333, website: null, last_request_at: null, external_user_id: null, external_id: null, facebook_id: null, twitter_id: null, password: CA95400837D5D402168FFB440A2BA46C7272, oldPassword: null, custom_data: null, avatar: https://main-court-demo122136-dev.s3.amazonaws.com/public/User/1696507981210490/1696507981210490.jpg, guest: null, timezone: null, tag_list: null, id: 11169340, created_at: null, updated_at: null}
                                 I  CB-SDK: CubeChatConnection: [login] userId: 11169340, resourceId: null
                                 I  CB-SDK: CubeChatConnection: Chat connection SocketOpening
                                 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