Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support tick messages #226

Merged
merged 6 commits into from
Jan 12, 2017

Conversation

jeromegrosse
Copy link
Contributor

I thought it would be a good idea to support ticks appearing in the bubble ala WhatsApp or Telegram depending if the message has been delivered and read.

Here is a screenshot of how it appears as of now with both the read and delivered flag set to true:

screenshot_20160907-164845

What do you think?

@kfiroo
Copy link
Collaborator

kfiroo commented Sep 7, 2016

@jeromegrosse Why are messageRead and messageDelivered props of GiftedChat?
Isn't it a per message state and not global?

@jeromegrosse
Copy link
Contributor Author

@kfiroo Yup, you are definitely right. I messed up there, I should use the messages array for that. I'll update the pull request with those changes as soon as possible.

@jeromegrosse
Copy link
Contributor Author

jeromegrosse commented Sep 8, 2016

@kfiroo I've just pushed a few changes:

  • The messageRead and messageDelivered props are no longer passed to GiftedChat as such but are instead set on a per message basis using the message state
  • Also, a message is not read or delivered but rather sent and delivered so as to be closer to the concept of the ticks in other mobile instant messaging software

What do you think? Here is a screenshot of how it looks like with the changes:
photo_2016-09-08_08-51-37

@kfiroo
Copy link
Collaborator

kfiroo commented Sep 8, 2016

@jeromegrosse Great! :)
I still have a few questions - I add them as inline comments

@@ -52,6 +53,20 @@ export default class Bubble extends React.Component {
return null;
}

renderTicks() {
_renderTick = function(displayTick) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating nested methods is very wasteful and not necasery in this case, so I think _renderTick should be a method of Bubble, or even as a stateless component.
Also looks like it is a global variable - did you forget the const?

@kfiroo
Copy link
Collaborator

kfiroo commented Sep 8, 2016

@jeromegrosse I'm missing a way to override the renderTicks method, If the user wants to change the style or behaviour.
But it might be good enough for the first commit, @FaridSafi what do you think?

@FaridSafi
Copy link
Owner

I'll take a look this weekend

@jeromegrosse
Copy link
Contributor Author

@kfiroo
Thanks a lot for your feedbacks!

I performed the following modifications:

  • Deletion of the nested method _renderTicks
  • Added the possibility to override the way the ticks are rendered

However, I have a couple of questions:

  • Should I rather put the ticks on the right of the time?
  • Should I restrict the ticks to only the message sent by the user and never display the ticks for the received message?

renderTicks() {
if (this.props.currentMessage.sent || this.props.currentMessage.received) {
const {currentMessage} = this.props;
if (this.props.renderTicks) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could go above the first if
The user might want to have different props for his sent / received props

@kfiroo
Copy link
Collaborator

kfiroo commented Sep 9, 2016

@jeromegrosse Great work!
Regarding your questions, maybe @FaridSafi would have an opinion :)

  • I would say put the ticks on the right so the time won't move when the status changes
  • I think only sent messages should show ticks for now, if users will request we can easily add it to the others

@jeromegrosse
Copy link
Contributor Author

@kfiroo @FaridSafi
I've just pushed the changes that you suggested:

  • The ticks are now display on the right-hand side of the time.
  • I fixed a styling problem that moved the time on the left of the message. It is now display on the right of the messages as it currently is in the master branch. Maybe now the ticks would be better on the left-hand side of the time?
  • There is a check that prevent the ticks from being displayed for the received messages.
  • I moved up the if statement as you suggested to allow an easier overriding of the function.
  • I modified the example so as to include the ticks feature.

return this.props.renderTicks(currentMessage);
}

const {currentMessage} = this.props;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be above the if statement - you are using currentMessage and it is not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid overlook from my part. Nice catch!

@kfiroo
Copy link
Collaborator

kfiroo commented Sep 10, 2016

@jeromegrosse Yeah, I would move them to the left now :) sorry!
That + the comment I left inline should have this feature closed I think.
@FaridSafi what do you think?

@jeromegrosse
Copy link
Contributor Author

I've push the change with the constant declaration that is declared after its first use if the function is overridden.

Regarding the ticks on the left, I've encountered a problem: The Time component has a marginLeft set to 10 which, I believe, is not that easy to override. The best result I could get with the ticks on the left is shown in the screenshot below:
photo_2016-09-11_00-01-56

@jeromegrosse
Copy link
Contributor Author

Have you got time to review it @kfiroo @FaridSafi ?

@kfiroo
Copy link
Collaborator

kfiroo commented Sep 19, 2016

@jeromegrosse @FaridSafi looks good to me :)

@jeromegrosse
Copy link
Contributor Author

@kfiroo @FaridSafi Just a little update to be able to customize how ticks are displayed (mainly overwriting the colour) by simple passing tickStyle to GiftedChat.

@benoist
Copy link

benoist commented Oct 25, 2016

Any update on this?

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 18, 2016

@dgdavid @cooperka @scarmuega would love your opinion on this

@cooperka
Copy link
Collaborator

Code LGTM, haven't tested on a device though. Nice work.

@dgdavid
Copy link
Contributor

dgdavid commented Dec 19, 2016

The code also looks good to me, but I've some doubts about merging it directly or improve it a little before.

I'll try to explain myself. As @cooperka said, this is a gifted chat component and this feature should be out-of-the-box. We agree on this, I think. But, Why on the left-side? Why with plain text and not using icons? Why there are not a sending status to give feedback to the user? I now that all these questions are out of the component's scope because each application should implement its own logic for each particular behavior. However, we can do little changes to make this easier.

I would split Bubble into three parts: Header, Content, and Footer. Then use the renderTime and renderTick methods into renderBubbleFooter or similar. In my opinion, this way gives a more clean logic and allows to override the entire footer at once without bloating GiftedChat with a lot of renderXXX props, since to change the order of ticks and time you could do something such as

...
renderBoobleFooter={ function() {
  renderTime();
  renderTicks();
} }
...

or change the entire footer passing a completely different logic.

As a more detailed example, below you have some of code that I'm using currently in my project:

...

  messageFooter(timeProps) {
    let icon = null
    const { currentMessage, position } = timeProps
    const time = moment.tz(currentMessage.createdAt, timezone).format('LT')
    const text = <Text style={styles[position].text}>{ time }</Text>

    // TODO: improve the icon logic
    if (showStatusIcon(currentMessage.status)) {
      icon =
          <Icon
            name={statusIcons[currentMessage.status]}
            style={[styles[position].text, styles[position].icon]}
          />
    }

    return (
      <View style={styles[position].container}>
        { text }
        {
          currentMessage.status === 'FAILED'
            ? <TouchableOpacity onPress={() => this.onSend([currentMessage])}>{icon}</TouchableOpacity>
            : icon
        }
      </View>
    )
  }

  render() {
    return (
      <View style={{ flex: 1 }}>
        <GiftedChat
          style={styles.mainContainer}
          messages={this.props.messages && this.props.messages.map(m => unflatten(m))}
          onSend={this.onSend}
          messageIdGenerator={uuid.v4}
          renderTime={this.messageFooter}
          user={{
            _id: this.props.currentUser.id,
          }}
        />
      </View>
    );
  }
}
...

I hope that you understand what I trying to say.

@cooperka
Copy link
Collaborator

cooperka commented Dec 19, 2016

@dgdavid: I agree with all points, though I think most of that can be held off for a future PR. I'm always in favor of merging early with an MVP and iterating from there. This PR is a fairly simple change that allows the possibility of showing send-receipts, and your suggestions seem to me like a larger structural change to the whole component (possibly breaking). I agree it should be done as you suggest, but perhaps in a separate PR after this one?

In terms of UX, WhatsApp (just as an example) uses icons on the right of the timestamp. Telegram is the same way. Below is a nice description of what each icon means on WhatsApp, showing how complex this could eventually be. Again, I don't think we need this now, but it's nice to see an example:

whatsapp-tick-marks-meanings

TL;DR: Let's ship this PR and tweak things later :shipit:

@dgdavid
Copy link
Contributor

dgdavid commented Dec 19, 2016

@cooperka I also agree with you. I proposed to do it in this PR by the relation with the renderTime prop/method. But you're right, possibly it would be a big change across the whole component.

Thanks for the MVP link 😉

@jeromegrosse
Copy link
Contributor Author

jeromegrosse commented Dec 20, 2016

@dgdavid @cooperka
The ideas that you are proposing are definitely worth thinking about. When I first started this PR, the scope of what I was aiming for was way less than what you are suggesting. However, I'd be glad to continue this PR and/or help with a subsequent PR to help implement these new features.

EDIT: @cooperka this MVP link is indeed a good read

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 20, 2016

@jeromegrosse @cooperka @dgdavid Hey guys
So glad to see everybody's on board with improving this project!
I think this PR is pretty good on it's own, it provides a minimal functionality with minimal changes and as a "feature PR" it is pretty solid.

However, I would like to open a new issue(s?) for discussing the future of GiftedChat, where we should talk about:

  • Code style (eslint)
  • Technical issues (tests / GiftedChat API / renderXXX inconsistencies / etc)
  • Missing features (ticks / image zoom / others?)

Not so sure if we need a single issue or an issue for each topic but I guess we'll find out soon enough :)

@jeromegrosse
Copy link
Contributor Author

So, can this PR be merged and later on have other issues improving the feature or are there any work to be done in this PR?

@cooperka
Copy link
Collaborator

Friendly ping @kfiroo

@kfiroo kfiroo merged commit 78e1701 into FaridSafi:master Jan 12, 2017
@guns2410
Copy link

Please push to npm as well

@Maxwell2022
Copy link

Maxwell2022 commented May 16, 2017

@jeromegrosse Please add docs as well

@vvavepacket
Copy link

Can we add docs of this in front page?

@jeromegrosse jeromegrosse deleted the feature-tick-delivery-read branch March 8, 2018 11:31
@flashimxd
Copy link

This feature is already implemented? I couldn't find in the documentation, and I really need that..

Thank you guys!

@Faolain
Copy link
Contributor

Faolain commented Dec 8, 2018

Hey everyone any thoughts on the implementation here #644 for doing essentially the same thing but outside of the bubble? The only issue I found is that these two lines need to be commented out following that method

{this.renderMessageVideo()}
{this.renderUsername()} 

otherwise it will error out with "TypeError: undefined is not a function(evaluating 'this.renderMessageVideo()')". I find it strange though since these both exist on the initial Bubble Component which they are extended from? Any suggestions as to which route to take, and if this latter approach works why these two methods might be failing as undefined?

@Usamaliaquat123
Copy link
Contributor

Any update about this how we can implement a tick when delever and seen message

@kesha-antonov
Copy link
Collaborator

Any update about this how we can implement a tick when delever and seen message

To message object add

            sent: true,
            received: true,
            pending: false,

@Usamaliaquat123
Copy link
Contributor

any update about seen messages and unseen message? and how to implement the isTyping option?

@hindsricardo
Copy link

?? soooo, is seen implemented or not? If so, where is the documentation?

@mkhoussid
Copy link

mkhoussid commented Oct 28, 2019

any update about seen messages and unseen message? and how to implement the isTyping option?

Re isTyping, use the onInputTextChanged prop.

@Thanujabadabagni
Copy link

hi am unable to bind messages to giftedchat messages using global list.Iin contructor i declared like global.messagesList=[];

<GiftedChat
messages={global.messagesList}
// onSend={messages => this.onSend(messages)}
user={{
_id:this.state.LoginId,
}}
/>
please suggest how to use global list to giftedchat messages...

@rusakovic
Copy link

Any update about this how we can implement a tick when delever and seen message

To message object add

            sent: true,
            received: true,
            pending: false,

Please, add it into the Readme file

@nwdeer
Copy link

nwdeer commented Oct 6, 2023

So, is it possible to indicate that the message was not only delivered but also read?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.