Messagekit: SenderType protocol. Rename id.

Created on 28 Feb 2019  路  18Comments  路  Source: MessageKit/MessageKit

Hello, i'm using the 3.0.0-beta version and there the Sender become SenderType protocol with value id.
In my app i need 3 entities to fit this protocol and they already have the id var with Int extension. In that case i either to
1) Create own Sender entity that fits SenderType and transform my 3 to it first.
2) Rename my entity's id and implement the protocol's id , then is not convenience.
3) Ignore the deprecated message for Sender class from MessageKit.

My suggestion to rename SenderType's id to chatID or something like that.

stale

Most helpful comment

Sorry autocorrect, conform to the SenderType protocol. This means your loginUserProfile class should have a senderId and displayName get property

Sent with GitHawk

All 18 comments

What is your current id extension?

Sent with GitHawk

Current is Int. Btw, I use realm to store it.

Alright, but if it's an extension I presume it's not critical to your data model and the type could be changed? I believe most ids are strings in the form of a UUID which is why it's the way it is.

Sent with GitHawk

The id can be a string, even bool, but it's better to leave the framework flexible. I can change it to String, but app i already tailored to id as Int value (equitation). For example, guys, who create backend could be very... special and send int value.

This issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This issue has been auto-closed because there hasn't been any activity for at least 21 days. However, we really appreciate your contribution, so thank you for that! 馃檹 Also, feel free to open a new issue if you still experience this problem 馃憤.

So, what about implementing?

Yea, I'll change it to senderId but it will remain a string

Sent with GitHawk

@nathantannar4 great, thx!

Done

Hi , i need to know how do we set this senderType to my currentSender. I am stuck in here,
```extension ChatViewController : SenderType {
var senderId: String {
return loginUserProfile.userId
}
var displayName: String {
return loginUserProfile.fullName
}
}

extension ChatViewController : MessagesDataSource {
func currentSender() -> SenderType {
return SenderType.self as! SenderType
}
}

SenderType is a protocol. Confirm your user to it and then you can just return loginUserProfile

Sent with GitHawk

SenderType is a protocol. Confirm your user to it and then you can just return loginUserProfile

Sent with GitHawk

hi, I did not get what you meant by confirm your user, am I doing it wrongly?

Sorry autocorrect, conform to the SenderType protocol. This means your loginUserProfile class should have a senderId and displayName get property

Sent with GitHawk

Okay got it, but I am having another problem now :(
when I send chat message, my bubbles are switching there sides like if I am the sender as per my logic i will be on right , but my chat bubbles keep switching as i start messaging, this wasn't happening when I was using sender struct.
have a look in image. thanks for your support
IMG_6F8E9717D292-1

Review your logic in func messageStyle(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageStyle

I have created this object which conforming MessageType

```
extension ChatMessageObject : MessageType {
var sender: SenderType {
// here I did this before, publisher is the id where I am comparing in messageStyle.
// now what I have to put in here.
return Sender(id: publisher, displayName: "")

}
var messageId: String {
    return ""
}

var sentDate: Date {
    return Date()
}

var kind: MessageKind {
    return .text(message)
}

}```

//I did something like this but it did not worked.

```extension ChatMessageObject : SenderType {
var senderId: String {
return publisher
}

var displayName: String {
    return ""
}

}```

Okay I got it, I have to change my logic, thanks a lot for your time :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NiklasWilson picture NiklasWilson  路  4Comments

ChandraPrakashJangid picture ChandraPrakashJangid  路  3Comments

Abacaxi-Nelson picture Abacaxi-Nelson  路  4Comments

bilaalrashid picture bilaalrashid  路  3Comments

yspreen picture yspreen  路  3Comments