UNPKG

3.11 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.Group = Group;
9
10var utils = _interopRequireWildcard(require("../utils"));
11
12var _events = require("events");
13
14/*
15Copyright 2017 New Vector Ltd
16Copyright 2019 The Matrix.org Foundation C.I.C.
17
18Licensed under the Apache License, Version 2.0 (the "License");
19you may not use this file except in compliance with the License.
20You may obtain a copy of the License at
21
22 http://www.apache.org/licenses/LICENSE-2.0
23
24Unless required by applicable law or agreed to in writing, software
25distributed under the License is distributed on an "AS IS" BASIS,
26WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27See the License for the specific language governing permissions and
28limitations under the License.
29*/
30
31/**
32 * @module models/group
33 */
34
35/**
36 * Construct a new Group.
37 *
38 * @param {string} groupId The ID of this group.
39 *
40 * @prop {string} groupId The ID of this group.
41 * @prop {string} name The human-readable display name for this group.
42 * @prop {string} avatarUrl The mxc URL for this group's avatar.
43 * @prop {string} myMembership The logged in user's membership of this group
44 * @prop {Object} inviter Infomation about the user who invited the logged in user
45 * to the group, if myMembership is 'invite'.
46 * @prop {string} inviter.userId The user ID of the inviter
47 */
48function Group(groupId) {
49 this.groupId = groupId;
50 this.name = null;
51 this.avatarUrl = null;
52 this.myMembership = null;
53 this.inviter = null;
54}
55
56utils.inherits(Group, _events.EventEmitter);
57
58Group.prototype.setProfile = function (name, avatarUrl) {
59 if (this.name === name && this.avatarUrl === avatarUrl) return;
60 this.name = name || this.groupId;
61 this.avatarUrl = avatarUrl;
62 this.emit("Group.profile", this);
63};
64
65Group.prototype.setMyMembership = function (membership) {
66 if (this.myMembership === membership) return;
67 this.myMembership = membership;
68 this.emit("Group.myMembership", this);
69};
70/**
71 * Sets the 'inviter' property. This does not emit an event (the inviter
72 * will only change when the user is revited / reinvited to a room),
73 * so set this before setting myMembership.
74 * @param {Object} inviter Infomation about who invited us to the room
75 */
76
77
78Group.prototype.setInviter = function (inviter) {
79 this.inviter = inviter;
80};
81/**
82 * Fires whenever a group's profile information is updated.
83 * This means the 'name' and 'avatarUrl' properties.
84 * @event module:client~MatrixClient#"Group.profile"
85 * @param {Group} group The group whose profile was updated.
86 * @example
87 * matrixClient.on("Group.profile", function(group){
88 * var name = group.name;
89 * });
90 */
91
92/**
93 * Fires whenever the logged in user's membership status of
94 * the group is updated.
95 * @event module:client~MatrixClient#"Group.myMembership"
96 * @param {Group} group The group in which the user's membership changed
97 * @example
98 * matrixClient.on("Group.myMembership", function(group){
99 * var myMembership = group.myMembership;
100 * });
101 */
\No newline at end of file