QuickBlox / q-municate-services-ios

Easy-to-use services for Quickblox SDK, for speeding up development of iOS chat applications
BSD 3-Clause "New" or "Revised" License
31 stars 42 forks source link

Sending message to Sender in group chat!! #101

Closed kaderkayten closed 8 years ago

kaderkayten commented 8 years ago

In group chat when a user send a message the unread message count increases.So the message sent is also sent to the sender.More over the badge are not updated in the cache,the local data storage.

Raikerian commented 8 years ago

Hi,

What version of QMServices are you using?

kaderkayten commented 8 years ago

Hi,I am using the latest version of QMServices(0.34)

  De : Vitaliy Gorbachov <notifications@github.com>

À : QuickBlox/q-municate-services-ios q-municate-services-ios@noreply.github.com Cc : kader kdrzas@yahoo.fr Envoyé le : Mardi 19 janvier 2016 14h33 Objet : Re: [q-municate-services-ios] Sending message to Sender in group chat!! (#101)

Hi,What version of QMServices are you using?— Reply to this email directly or view it on GitHub.

Raikerian commented 8 years ago

We have a check for current user where we incrementing unread message counter for local group dialog only if message senderID is not equal to our user ID. Can you verify if the problem really occurs on sender's messages?

Raikerian commented 8 years ago

Are you still facing this issue?

kaderkayten commented 8 years ago

Yes, i am still facing it.I am even trying to update  the dialog unreadcount  by setting to be zero in the chatviewcontroller.It seems to work but once you restart the count still shows a past count.I think it does not update in the backend it just updates in the local and when you retrieve from the backend again it  shows the old. Also from the last release when i try to join someone to the group chat it shows forbidden i was not able to figure it out.Previous version  was working fine for me.

  De : Vitaliy Gorbachov <notifications@github.com>

À : QuickBlox/q-municate-services-ios q-municate-services-ios@noreply.github.com Cc : kader kdrzas@yahoo.fr Envoyé le : Lundi 25 janvier 2016 14h20 Objet : Re: [q-municate-services-ios] Sending message to Sender in group chat!! (#101)

Are you still facing this issue?— Reply to this email directly or view it on GitHub.

Raikerian commented 8 years ago

Lets try to figure it out:

  1. Unread message counter working incorrect only for messages that were sent by sender? Or when you are receiving them too?
  2. Please provide us code snippet which is showing how you are creating QBChatMessage instance and sending it using QMServices method.
  3. About forbidden join please also provide code snippet on how you join someone and error log.
kaderkayten commented 8 years ago

1- In a group chat when a user send 3 messages and leaves the view controller to the the dialogs controller where i show the badge with unread count it shows 3 instead of 0.And the problem is how to make it be read.Because it does not go to 0.

2-code for sending

      let message = QBChatMessage()
        message.text = txtMessageField.text
        message.senderID = (QBSession.currentSession().currentUser?.ID)!
        message.senderNick = currentuserDetail["screenName"] as! String
        message.dateSent = NSDate()

        ServicesManager.instance().chatService.sendMessage(message, toDialog: self.chatDialog, saveToHistory: true, saveToStorage: true, completion: { (error) -> Void in
            self.txtMessageField.text = ""
            self.txtMessageField.resignFirstResponder()

            if error == nil {
                QBChat.instance().readMessage(message, completion: { (eroor) -> Void in

                })
              //
                //self.mainTableView.reloadData()
            }

        })

////code for showing the badge

    /////////  basically it is in the cell
             ourCell.lblText.text = last_user+chatDialog.lastMessageText!
            if chatDialog.unreadMessagesCount > 0{
                ourCell.lblNumberCountIndicator.text = "\(chatDialog.unreadMessagesCount)"

            }else {

                ourCell.lblNumberCountIndicator.hidden = true
                ourCell.redContainerIndicatorView.hidden = true
                }

3- code for joining
var selecteduser = [QBUUser]() //is an array of qbuusers /// let dialog_toupdate = QBChatDialog(dialogID: dialog_global!.ID, type: QBChatDialogType.Group)

        dialog_toupdate.setPushOccupantsIDs(["\(self.selecteduser)"])

        ServicesManager.instance().chatService.joinOccupantsWithIDs([self.selecteduser], toChatDialog: dialog_toupdate, completion: { (respnse, dial) -> Void in

            dialog_global = dialog

            let viewController = UIStoryboard(name:"NGroupStoryboard", bundle: nil).instantiateViewControllerWithIdentifier("viewChatVC") as! ChatViewController

            Addflag = -1
            self.navigationController!.pushViewController(viewController, animated: true)

        })
Raikerian commented 8 years ago
  1. Are you reloading data of tableview when there is dialog update in memory storage? Please check if unreadMessageCount is not desync with badge.
  2. Try adding this before message sending:
message.deliveredIDs = [((QBSession.currentSession().currentUser?.ID)!)];
message.readIDs = [((QBSession.currentSession().currentUser?.ID)!)];
message.markable = true

3 . Is 'self.selecteduser' a number or QBUUser instance? Log of the error would be helpful.

kaderkayten commented 8 years ago

There comes the log

2016-01-26 11:46:37.428 Buyzar[3965:54072] [QBCore] Request URL:https://api.quickblox.com/chat/Dialog/569f8e47a0eb473a4f00008c.json?push_all%5Boccupants_ids%5D%5B%5D%5B%5D=5135638&push_all%5Boccupants_ids%5D%5B%5D%5B%5D=5109061
2016-01-26 11:46:37.437 Buyzar[3965:54072] [QBCore] Request method: PUT
2016-01-26 11:46:37.438 Buyzar[3965:54072] [QBCore] Request parameters:{
    "push_all" =     {
        "occupants_ids" =         (
                        (
                5135638,
                5109061
            )
        );
    };
}
2016-01-26 11:46:37.439 Buyzar[3965:54072] [QBCore] Request headers: {
    "Content-Type" = "application/json";
    "QB-OS" = "iOS 9.2";
    "QB-SDK" = "iOS 2.6.2";
    "QB-Token" = 28900704dfbeb3fb8d9d78d50cec732ac9ab2048;
    "QuickBlox-REST-API-Version" = "0.1.1";
}
2016-01-26 11:46:38.067 Buyzar[3965:54076] [QBCore] Response error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7ff231c83ac0> { URL: https://api.quickblox.com/chat/Dialog/569f8e47a0eb473a4f00008c.json?push_all%5Boccupants_ids%5D%5B%5D%5B%5D=5135638&push_all%5Boccupants_ids%5D%5B%5D%5B%5D=5109061 } { status code: 403, headers {
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Length" = 79;
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Tue, 26 Jan 2016 09:46:37 GMT";
    "QB-Token-ExpirationDate" = "2016-01-26 11:42:48 UTC";
    "QuickBlox-REST-API-Version" = "0.1.1";
    Server = "nginx/1.6.2";
    Status = "403 Forbidden";
    "X-Rack-Cache" = "invalidate, pass";
    "X-Request-Id" = 4e2dfa51c572811429616fb4ec1780b2;
    "X-Runtime" = "0.021816";
    "X-UA-Compatible" = "IE=Edge,chrome=1";
} }, NSErrorFailingURLKey=https://api.quickblox.com/chat/Dialog/569f8e47a0eb473a4f00008c.json?push_all[occupants_ids][][]=5135638&push_all[occupants_ids][][]=5109061, com.alamofire.serialization.response.error.data=<7b226572 726f7273 223a5b22 596f7520 646f6e27 74206861 76652061 7070726f 70726961 74652070 65726d69 7373696f 6e732074 6f207065 72666f72 6d207468 6973206f 70657261 74696f6e 225d7d>, NSLocalizedDescription=Request failed: forbidden (403)}
kaderkayten commented 8 years ago

1 - MY reloadata method is commented out .I am reloading it in func chatService(chatService: QMChatService!, didAddMessageToMemoryStorage message: QBChatMessage!, forDialogID dialogID: String!)

or when there is a new message that came.

Raikerian commented 8 years ago

It seems like you are trying to push not an array of user ids, but array with array of users ids.

kaderkayten commented 8 years ago

Sorry but i did not get the meaning of : "Not an array of user ids, but array with array of users ids."

Raikerian commented 8 years ago

Can you print self.selecteduser from you code snippet in a console?

I mean:

"push_all" =     {
        "occupants_ids" =         (// start of array
                        (// start of the second array
                5135638,
                5109061
            )
        );
    };
kaderkayten commented 8 years ago

Yeah.You are right!The previous the ids was passed as string so i was casting them in an array .But this last one takes a Uint so i do not need to cast the ids to string. About this it will be nice you could follow a simple pattern either using string or int will be nice, For example :dialgogID string occupant ids : nsnumber where as Qbuser ids are Uint and for private recipient IDS = int etc.... You have to type cast it everytime.

Raikerian commented 8 years ago

Yes. You need to send array of numbers, e.g. objects (not UInt's) in order to make it work. It is always array and should be never single object or string.

So, were you able to fix it?

kaderkayten commented 8 years ago

No still

016-01-26 17:53:04.062 Buyzar[6859:187416] [QBCore] Request parameters:{ "push_all" = { "occupants_ids" = ( 5135638, 5109061 ); }; } 2016-01-26 17:53:04.062 Buyzar[6859:187416] [QBCore] Request headers: { "Content-Type" = "application/json"; "QB-OS" = "iOS 9.2"; "QB-SDK" = "iOS 2.6.2"; "QB-Token" = ce16ace14f089defdda710573f6176ea1fa7966a; "QuickBlox-REST-API-Version" = "0.1.1"; } 2016-01-26 17:53:04.246 Buyzar[6859:187655] [QBCore] Response error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f8b4c5f0170> { URL: https://api.quickblox.com/chat/Dialog/569f8e47a0eb473a4f00008c.json?push_all%5Boccupants_ids%5D%5B%5D=5135638&push_all%5Boccupants_ids%5D%5B%5D=5109061 } { status code: 403, headers { "Access-Control-Allow-Origin" = "*"; "Cache-Control" = "no-cache"; Connection = "keep-alive"; "Content-Length" = 79; "Content-Type" = "application/json; charset=utf-8"; Date = "Tue, 26 Jan 2016 15:53:04 GMT"; "QB-Token-ExpirationDate" = "2016-01-26 17:50:22 UTC"; "QuickBlox-REST-API-Version" = "0.1.1"; Server = "nginx/1.6.2"; Status = "403 Forbidden"; "X-Rack-Cache" = "invalidate, pass"; "X-Request-Id" = 1d60bf3358b73d74e184efdb3ad6fbe3; "X-Runtime" = "0.023339"; "X-UA-Compatible" = "IE=Edge,chrome=1"; } }, NSErrorFailingURLKey=https://api.quickblox.com/chat/Dialog/569f8e47a0eb473a4f00008c.json?push_all[occupants_ids][]=5135638&push_all[occupants_ids][]=5109061, com.alamofire.serialization.response.error.data=<7b226572 726f7273 223a5b22 596f7520 646f6e27 74206861 76652061 7070726f 70726961 74652070 65726d69 7373696f 6e732074 6f207065 72666f72 6d207468 6973206f 70657261 74696f6e 225d7d>, NSLocalizedDescription=Request failed: forbidden (403)} 2016-01-26 17:53:04.634 Buyzar[6859:187654] [QBCore] Response error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f8b4a551b00> { URL: https://api.quickblox.com/chat/Dialog/569f8e47a0eb473a4f00008c.json?push_all%5Boccupants_ids%5D%5B%5D=5135638&push_all%5Boccupants_ids%5D%5B%5D=5109061 } { status code: 403,

Raikerian commented 8 years ago

Please update iOS SDK to 2.6.3 (there are fixed error logs) and print '[response.error reasons]' in console. Attach result here.

kaderkayten commented 8 years ago

I have updated the sdks yet because i changed things in the sdk and qmchatservice to allow me to send audio and video and also other properties that is not directly provided

but here is the log for response.error reasons

(lldb) po respnse.error?.reasons nil

(lldb)

Raikerian commented 8 years ago

Yes, error logs are not working in 2.6.2. You can easily update it to 2.6.3, it will not affect your own QMServices changes.

Raikerian commented 8 years ago

Any updates on this? Were you able to catch error?