|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const AV = require('./av'); |
| 4 | + |
| 5 | +/** |
| 6 | + * @class |
| 7 | + * |
| 8 | + * <p>An AV.Conversation is a local representation of a LeanCloud realtime's |
| 9 | + * conversation. Tshi class is a subclass of an AV.Object, and retains the |
| 10 | + * same functionality of an AV.Object, but also extends it with various |
| 11 | + * conversation specific methods, like get members, creators of this conversation. |
| 12 | + * </p> |
| 13 | + */ |
| 14 | +module.exports = AV.Object.extend('_Conversation', { |
| 15 | + constructor: function(name, isSystem, isTransient) { |
| 16 | + AV.Object.prototype.constructor.call(this, null, null); |
| 17 | + this.set('name', name); |
| 18 | + this.set('sys', isSystem ? true : false); |
| 19 | + this.set('tr', isTransient ? true : false); |
| 20 | + }, |
| 21 | + /** |
| 22 | + * Get current conversation's creator. |
| 23 | + * |
| 24 | + * @return {String} |
| 25 | + */ |
| 26 | + getCreator: function() { |
| 27 | + return this.get('c'); |
| 28 | + }, |
| 29 | + |
| 30 | + /** |
| 31 | + * Get the last message's time. |
| 32 | + * |
| 33 | + * @return {Date} |
| 34 | + */ |
| 35 | + getLastMessageAt: function() { |
| 36 | + return this.get('lm'); |
| 37 | + }, |
| 38 | + |
| 39 | + /** |
| 40 | + * Get this conversation's members |
| 41 | + * |
| 42 | + * @return {Array} |
| 43 | + */ |
| 44 | + getMembers: function() { |
| 45 | + return this.get('m'); |
| 46 | + }, |
| 47 | + |
| 48 | + /** |
| 49 | + * Add a member to this conversation |
| 50 | + * |
| 51 | + * @param {String} member |
| 52 | + */ |
| 53 | + addMember: function(member) { |
| 54 | + this.add('m', member); |
| 55 | + }, |
| 56 | + |
| 57 | + /** |
| 58 | + * Get this conversation's members who set this conversation as muted. |
| 59 | + * |
| 60 | + * @return {Boolean} |
| 61 | + */ |
| 62 | + getMutedMembers: function() { |
| 63 | + return this.get('mu'); |
| 64 | + }, |
| 65 | + |
| 66 | + /** |
| 67 | + * Get this conversation's name field. |
| 68 | + * |
| 69 | + * @return String |
| 70 | + */ |
| 71 | + getName: function() { |
| 72 | + return this.get('name'); |
| 73 | + }, |
| 74 | + |
| 75 | + /** |
| 76 | + * Returns true if this conversation is transient conversation. |
| 77 | + * |
| 78 | + * @return {Boolean} |
| 79 | + */ |
| 80 | + isTransient: function() { |
| 81 | + return this.get('tr'); |
| 82 | + }, |
| 83 | + |
| 84 | + /** |
| 85 | + * Returns true if this conversation is system conversation. |
| 86 | + * |
| 87 | + * @return {Boolean} |
| 88 | + */ |
| 89 | + isSystem: function() { |
| 90 | + return this.get('sys'); |
| 91 | + }, |
| 92 | + |
| 93 | + send: function() { |
| 94 | + |
| 95 | + }, |
| 96 | +}); |
0 commit comments