GetStream / swift-activity-feed

Stream Swift iOS Activity Feed Components
https://getstream.io/
BSD 3-Clause "New" or "Revised" License
30 stars 17 forks source link

Add activity not working in the demo #1

Closed deepak-vishwakarma-spok closed 4 years ago

deepak-vishwakarma-spok commented 5 years ago

Can you please check if add activity working . I added my stream key , app id and tokien. When trying to add activity getting decoding error . but activity are getting saved successfully. Below is the error on console coming

unexpectedError(Optional(GetStream.ClientError.jsonDecode("The data couldn’t be read because it isn’t in the correct format.", Optional(Swift.DecodingError.typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "actor", intValue: nil)], debugDescription: "Expected to decode Dictionary<String, Any> but found a string/data instead.", underlyingError: nil))), 224 bytes)))

levmar commented 4 years ago

I ran into this error as well, and was able to work around it by ensuring that the API endpoint returned an enriched actor attribute, not just a String with an actor ID. In order to do that, I had to make sure that the actor was a string following the format SA:user-id, where user-id is some user that actually exists within the Stream application.

Not sure if this is an intentional limitation of the client API. But as it currently stands, the Swift Activity Feed Demo code does not work without enriched actor information in the feed.

b-onc commented 4 years ago

Hey @deepak-vishwakarma-spok Demo project, adding activity works for me now. @levmar : The client should use an actor as the current user.

dconroy commented 4 years ago

ensuring that the API endpoint returned an enriched actor attribute

@levmar @b-onc Thanks for the tip. How does one insure that the API returns the enriched data?

marctatham commented 4 years ago

The funny thing is that I've just Hooked the GetStreamActivityFeed and GetStream dependencies into my project, I've literally taken the code form the example app and run it and I'm observing the same behaviour.

The funny thing is that I'm not in control of deserialising the response, at least I understand this as the responsibility of your SDK.

The example response:

{
  "results": [
    {
      "id": "adb5cc6f-3aee-11ea-a1e5-0a0d7a10423a",
      "reaction_counts": {
      },
      "verb": "post",
      "time": "2020-01-19T19:05:37.922162",
      "latest_reactions": {
      },
      "object": "Test - ",
      "actor": {
        "id": "138",
        "data": null,
        "updated_at": "2020-01-12T19:02:04.535043Z",
        "created_at": "2020-01-12T19:02:04.535043Z"
      },
      "origin": null,
      "latest_reactions_extra": {
      },
      "own_reactions": {
      },
      "target": "",
      "foreign_id": ""
    },
    {
      "id": "7323b5e8-3aee-11ea-88d4-12f8ef9c949e",
      "reaction_counts": {
      },
      "verb": "post",
      "time": "2020-01-19T19:03:59.656906",
      "latest_reactions": {
      },
      "object": "Test ",
      "actor": {
        "id": "138",
        "data": null,
        "updated_at": "2020-01-12T19:02:04.535043Z",
        "created_at": "2020-01-12T19:02:04.535043Z"
      },
      "origin": null,
      "latest_reactions_extra": {
      },
      "own_reactions": {
      },
      "target": "",
      "foreign_id": ""
    },
    {
      "id": "8f8179ef-3aed-11ea-a149-0a0d7a10423a",
      "reaction_counts": {
      },
      "verb": "post",
      "time": "2020-01-19T18:57:37.750885",
      "latest_reactions": {
      },
      "object": "The test ",
      "actor": {
        "id": "138",
        "data": null,
        "updated_at": "2020-01-12T19:02:04.535043Z",
        "created_at": "2020-01-12T19:02:04.535043Z"
      },
      "origin": null,
      "latest_reactions_extra": {
      },
      "own_reactions": {
      },
      "target": "",
      "foreign_id": ""
    },
    {
      "id": "db787833-3aeb-11ea-8746-12f8ef9c949e",
      "reaction_counts": {
      },
      "verb": "post",
      "time": "2020-01-19T18:45:26.205240",
      "latest_reactions": {
      },
      "object": "LePost",
      "actor": {
        "id": "138",
        "data": null,
        "updated_at": "2020-01-12T19:02:04.535043Z",
        "created_at": "2020-01-12T19:02:04.535043Z"
      },
      "origin": null,
      "latest_reactions_extra": {
      },
      "own_reactions": {
      },
      "target": "",
      "foreign_id": ""
    }
  ],
  "next": "",
  "duration": "10.28ms"
}
marcoti commented 4 years ago

🤔 any news on this?

b-onc commented 4 years ago

@marcoti We were blocked by some other issues but we'll get to this as soon as possible.

b-onc commented 4 years ago

Hey @marcoti , @marcfrost and @levmar I've tried to reporduce the error using https://github.com/GetStream/swift-activity-feed-demo but I could not. I've setup a new add and used new credentials, demo app was not working, so I've updated the demo app to work with latest GetStream pod. So far, everything works for me. Can you guys provide more info on this JSON decoding error?

Good to follow the tutorial, too: https://getstream.io/ios-activity-feed/tutorial/

marctatham commented 4 years ago

Sure - so I've gone through the tutorial, I think I'm doing what I'm supposed to be. Let me try paint the picture as accurately as possible...

On my getStream developer dashboard:

On my backend:

So let's shift this focus on over to my iOS client implementation:

So here's what I'm seeing with this very basic setup when navigating to my ViewController that is doing literally nothing but interacting with getStream:

So to recap:

I've tried to be as detailed as possible but if I've left out some crucial information I'm more than happy to provide more info to help debug this. But it really doesn't seem like I'm doing anything particularly special with any of the above 🤷‍♂ any help would be appreciated, maybe I'm doing something silly my side - but I'm really surprised to see that JSON decoding error in the logs. It's OK for there to be a problem processing a response, but it seems less OK that the response can't be deserialised (especially in this case where the repsonse is actually a 200 and contains what looks at a glance to be a perfectly formed payload describing the posts in the timeline.

Side note: I'm aware the logs contain my API key - that's OK it's just a development app I threw together to test out your API + SDK. I'll regenerate it if I pursue this solution further.

marctatham commented 4 years ago

Actually I've just pulled the latest codebase on the demo app and I'm seeing the exact same behaviour that side:

The below is 100% reproducible on the current head:

commit dc079d76b516403e111aed7149e37ce891035cbb (HEAD -> master, origin/master, origin/HEAD)

Take my development stream application to help you on your journey:

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Setup Stream Client.
        Client.config = .init(apiKey: "knwc9xsncjfj", appId: "67189", logsEnabled: true)

        Client.shared.setupUser(GetStreamActivityFeed.User(name: "Test",
                                                           id: "138"),
                                token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTM4In0.IbGoZUE7jzdjmJsZk4USNQak_v9z0VYfS4BOd7lqlSQ") { (result) in
                                    guard result.error == nil else {
                                        preconditionFailure("Cannot setup user: \(result.error!)")
                                    }
                                    if let viewController = self.window?.rootViewController as? ViewController {
                                        viewController.reloadData()
                                    }
        }

        return true
    }
}

Log output:

Stream Feed v.2.2.1
🔑  knwc9xsncjfj
🔗  https://api.stream-io-api.com/api/v1.0/
🐴 [28/01 22:03:12.695] 🧹 Disconnect. Reset Client User, Token, URLSession and WebSocket. Old user id: <Empty>.
👤  User id: 138
🀄️  Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTM4In0.IbGoZUE7jzdjmJsZk4USNQak_v9z0VYfS4BOd7lqlSQ
🐴 [28/01 22:03:12.699] ➡️ create(GetStreamActivityFeed.User, true)
🐴 [28/01 22:03:12.700] 🧾 Request Data:
{
  "id" : "138",
  "data" : {
    "name" : "Test",
    "profileImage" : null
  }
}
🐴 [28/01 22:03:12.700] 🧾 URL parameters: ["get_or_create": true]
🐴 [28/01 22:03:12.741] ➡️ get(timeline:138, true, GetStream.Pagination.none, "", GetStream.FeedMarkOption.none, GetStream.FeedReactionsOptions(rawValue: 13))
🐴 [28/01 22:03:12.741] 🧾 Parameters: ["withReactionCounts": true, "withOwnReactions": true, "withRecentReactions": true]
🐴 [28/01 22:03:13.257] ⬅️ Response 201: https://api.stream-io-api.com/api/v1.0/user/?api_key=knwc9xsncjfj&get_or_create=1
🐴 [28/01 22:03:13.257] ⒿⓈⓄⓃ 129 bytes
 {
  "duration" : "0.75ms",
  "id" : "138",
  "data" : {

  },
  "updated_at" : "2020-01-12T19:02:04.535043Z",
  "created_at" : "2020-01-12T19:02:04.535043Z"
}
🐴 [28/01 22:03:13.260] 👤 The current user was setupped with id: 138
🐴 [28/01 22:03:13.260] ➡️ get(timeline:138, true, GetStream.Pagination.none, "", GetStream.FeedMarkOption.none, GetStream.FeedReactionsOptions(rawValue: 13))
🐴 [28/01 22:03:13.260] 🧾 Parameters: ["withRecentReactions": true, "withOwnReactions": true, "withReactionCounts": true]
🐴 [28/01 22:03:13.270] ⬅️ Response 200: https://api.stream-io-api.com/api/v1.0/enrich/feed/timeline/138/?api_key=knwc9xsncjfj&withOwnReactions=1&withReactionCounts=1&withRecentReactions=1
🐴 [28/01 22:03:13.270] ⒿⓈⓄⓃ 1872 bytes
 {
  "results" : [
    {
      "id" : "7ad53f41-4219-11ea-8e45-0a0d7a10423a",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-28T21:59:39.063277",
      "latest_reactions" : {

      },
      "object" : "Hmmm.",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    },
    {
      "id" : "adb5cc6f-3aee-11ea-a1e5-0a0d7a10423a",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-19T19:05:37.922162",
      "latest_reactions" : {

      },
      "object" : "Test - ",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    },
    {
      "id" : "7323b5e8-3aee-11ea-88d4-12f8ef9c949e",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-19T19:03:59.656906",
      "latest_reactions" : {

      },
      "object" : "Test ",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    },
    {
      "id" : "8f8179ef-3aed-11ea-a149-0a0d7a10423a",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-19T18:57:37.750885",
      "latest_reactions" : {

      },
      "object" : "The test ",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    },
    {
      "id" : "db787833-3aeb-11ea-8746-12f8ef9c949e",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-19T18:45:26.205240",
      "latest_reactions" : {

      },
      "object" : "LePost",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    }
  ],
  "next" : "",
  "duration" : "10.40ms"
}
❌ JSON decoding error: The data couldn’t be read because it isn’t in the correct format.. Data: 1872 bytes
🐴 [28/01 22:03:13.396] ⬅️ Response 200: https://api.stream-io-api.com/api/v1.0/enrich/feed/timeline/138/?api_key=knwc9xsncjfj&withOwnReactions=1&withReactionCounts=1&withRecentReactions=1
🐴 [28/01 22:03:13.396] ⒿⓈⓄⓃ 1872 bytes
 {
  "results" : [
    {
      "id" : "7ad53f41-4219-11ea-8e45-0a0d7a10423a",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-28T21:59:39.063277",
      "latest_reactions" : {

      },
      "object" : "Hmmm.",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    },
    {
      "id" : "adb5cc6f-3aee-11ea-a1e5-0a0d7a10423a",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-19T19:05:37.922162",
      "latest_reactions" : {

      },
      "object" : "Test - ",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    },
    {
      "id" : "7323b5e8-3aee-11ea-88d4-12f8ef9c949e",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-19T19:03:59.656906",
      "latest_reactions" : {

      },
      "object" : "Test ",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    },
    {
      "id" : "8f8179ef-3aed-11ea-a149-0a0d7a10423a",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-19T18:57:37.750885",
      "latest_reactions" : {

      },
      "object" : "The test ",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    },
    {
      "id" : "db787833-3aeb-11ea-8746-12f8ef9c949e",
      "reaction_counts" : {

      },
      "verb" : "post",
      "time" : "2020-01-19T18:45:26.205240",
      "latest_reactions" : {

      },
      "object" : "LePost",
      "actor" : {
        "id" : "138",
        "data" : null,
        "updated_at" : "2020-01-12T19:02:04.535043Z",
        "created_at" : "2020-01-12T19:02:04.535043Z"
      },
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "target" : "",
      "foreign_id" : ""
    }
  ],
  "next" : "",
  "duration" : "10.62ms"
}
❌ JSON decoding error: The data couldn’t be read because it isn’t in the correct format.. Data: 1872 bytes
b-onc commented 4 years ago

Hello @marcfrost Thanks for sharing lots of info! I can reproduce your issue easily. The issue is not reproducible on a clear feed, the problem comes from the JSON you're getting. When you setup the user with:

Client.shared.setupUser(token: userAccount.socialUserToken) { result in
            self.reloadData()
        }

you'll use the default user type (GetStream.User). But TextToolBar expects GetStreamActivityFeed.User to operate. That's why if you setup a new user with setupUser(token:), you won't be able to post anything on the demo app, you'll get the warning:

❌ The current user not found

When I create a new (demo) app (without any code changes), and post some stuff, in the results' actor I see:

"actor" : {
  "id" : "138",
  "data" : {
    "name" : "Test",
    "profileImage" : null
  },
  "updated_at" : "2020-01-29T09:55:18.112781Z",
  "created_at" : "2020-01-29T09:55:18.112781Z"
}

but in your logs, I see that data is null. If you've used a custom user type, can you share it? If you haven't, I suspect the problem comes from using setupUser(token:) and posting some stuff (without using GetStreamActivityFeed), then using demo app (which uses setupUser(user:token:) and gets enriched activities) to try fetching the posts. It'd be good to know how were the activities in the JSON were created in the first place, so we can get to the bottom of this issue.

The issues people are facing in this thread surfaced a logging problem: this should've been made clearer in the docs and the log outputs. We'll work on improving the error messages. Probably we've made some changes and did not document them enough.

Let me know if this makes things clear.

marctatham commented 4 years ago

Thanks @b-onc that's been super helpful.

I've re-created a new stream development application to test and all is working quite well thanks. I suspect i posted those additional entries while I was testing the getstream pod (as opposed to GetStreamActivityFeed) - appreciate you took the time to help out with this 🙌