Example #1
0
    getMessages(){

        /*Gets the messages from the channel connected*/
        Sendbird.getMessageLoadMore({

            limit: 100,
            successFunc: data => {
                let _messageList = [];

                data.messages.reverse().forEach((msg, index) => {

                    if(Sendbird.isMessage(msg.cmd)){
                        _messageList.push(msg.payload);
                    }

                });

                this.setState({
                    messageList: _messageList.concat(this.state.messageList)
                });
            },
            errorFunc: (status, error) => {
                console.log('[Error load more msgs]: ' + error)
            }

        });

    }
	_getMessages: function() {
		var that = this;
		sendbird.getMessageLoadMore({
			limit: 100,
			successFunc: (data) => {
				var _messageList = [];
				var messages = [];
				data.messages.reverse().forEach(function(msg, index){
					if(sendbird.isMessage(msg.cmd)) {
						_messageList.push(msg.payload);
						var m = msg.payload;
						var _m = {};
						_m.text = m.message;
						_m.name = m.user.name;
						_m.image = {uri: m.user.image};
						_m.position = 'left';
						if(m.user.guest_id == that.props.user.guest_id)
							_m.position = 'right';
						_m.date = new Date(m.sts);
						messages.push(_m);
					}
				});
				this.setState({ 
					messageList: _messageList.concat(this.state.messageList),
					messages: messages.concat(this.state.messages)
				});
			},
			errorFunc: (status, error) => {
				console.log(status, error);
			}
		});
	},
    this.setState({isLoading: true}, () => {
      sendbird.getMessageLoadMore({
        limit: LOAD_MESSAGE_COUNT,
        successFunc: (data) => {
          var _messageList = [];
          data.messages.reverse().forEach((msg, index) => {
            var _position = 'left';
            if (msg.payload.user && msg.payload.user.guest_id == this.state.user.guest_id) {
              _position = 'right';
            }
            if(sendbird.isMessage(msg.cmd)) {
              _messageList.push({
                text: msg.payload.message,
                name: msg.payload.user.name,
                image: {uri: msg.payload.user.image},
                position: _position,
                date: new Date(msg.payload.ts)
              });
            } else if (sendbird.isFileMessage(msg.cmd)) {
              _messageList.push({
                text: msg.payload.name,
                name: msg.payload.user.name,
                image: {uri: msg.payload.user.image},
                position: _position,
                date: new Date(msg.payload.ts)
              });
            }
          });

          this.setState({ messageList: _messageList.concat(this.state.messageList) }, () => {
            this.setState({isLoading: false}, () => {
              if (this.firstDisplay) {
                this.firstDisplay = false;
                setTimeout(() => {this.scrollWithoutAnimationToBottom()}, 500);
              } else {
                setTimeout(() => {this._GiftedMessenger.scrollResponder.scrollTo(this.footerY - this.loadMoreY);}, 500)
              }
            });
          });
        },
        errorFunc: (status, error) => {
          console.log(status, error);
        }
      });
    });