How to use the leancloud-realtime.TextMessage function in leancloud-realtime

To help you get started, we’ve selected a few leancloud-realtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leancloud / leanmessage-demo / src / app / conversation / conversationMessage / conversation.message.controller.js View on Github external
$scope.sendText = () => {
    const {draft} = $scope;
    if (!draft) {
      return;
    }
    const message = new TextMessage(draft);
    // 匹配出所有的 @
    const results = draft.match(/(^|\s)@(\S*)/g);
    if (results) {
      const mentionMatchResults = new Set(results.map(match => match.trim().slice(1)));
      console.log(mentionMatchResults);
      // 找出 @all
      if (mentionMatchResults.has('all')) {
        message.mentionAll();
        mentionMatchResults.delete('all');
      }
      message.setMentionList(Array.from(mentionMatchResults));
    }
    $scope.draft = '';
    $scope.smileysShow = false;

    return $scope.send(message);
github leancloud / leanmessage-demo / server / index.js View on Github external
function sendMessage(content, peerId, convId) {
  console.log('sending message [' + content + '] to peer [' + peerId + ']');
  var message = new TextMessage(content);
  var conversation = AV.Object.createWithoutData('_Conversation', convId);
  return conversation.send('MathBot', message, { toClients: [peerId] }, { useMasterKey: true }).then(function() {
    console.log('sended: ' + JSON.stringify(message));
  }, function(error) {
    console.error('send message error: ' + error.message);      
  });
}
github wujun4code / DoChat / chatkit-client / src / components / lc-conversation-list / lc-conversation-list.ts View on Github external
SharedService.client.getConversation(convIdStr, true).then(conv => {
      let txtMessage = new TextMessage(sendEventData.text);
      console.log(JSON.stringify(this.items));
      console.log('send(sendEventData)');
      return conv.send(txtMessage);
    }).then(message => {
      this.updateLastMessage(message);
github leancloud / leanmessage-demo / server / index.js View on Github external
AV.Cloud.define('chime', function() {
  if (!CHIME_CONV_ID) return console.warn('CHIME_CONV_ID not set, skip chiming');
  console.log('chime');
  var hours = Math.round((Date.now() / 3600000  + 8) % 24);
  var message = new TextMessage('北京时间 ' + hours + ' 点整');
  var conversation = AV.Object.createWithoutData('_Conversation', CHIME_CONV_ID);
  return conversation.broadcast('LeanObservatory', message, { validTill: Date.now() }, { useMasterKey: true }).then(function() {
    console.log('chimed');
  }, function(error) {
    console.error('broadcast message error: ' + error.message);      
  });
});