-implement create chat group

This commit is contained in:
tiago.kayaya
2021-01-21 16:27:04 +01:00
parent 608eee8cc2
commit f3c15e603a
56 changed files with 462 additions and 501 deletions
@@ -61,7 +61,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
/* harmony default export */
__webpack_exports__["default"] = "<ion-header class=\"ion-no-border\">\r\n <ion-toolbar class=\"header-toolbar\">\r\n <div class=\"main-header\">\r\n <div class=\"title-content\">\r\n <div class=\"back-icon\">\r\n <ion-icon (click)=\"close()\" slot=\"end\" src='assets/images/icons-arrow-arrow-left.svg'></ion-icon>\r\n </div>\r\n <div class=\"div-title\">\r\n <ion-label class=\"title\">Contactos</ion-label>\r\n </div>\r\n <app-btn-seguinte (click)=\"groupMessages()\"></app-btn-seguinte>\r\n </div>\r\n </div>\r\n </ion-toolbar>\r\n <ion-toolbar class=\"toolbar-search\">\r\n <div class=\"search\">\r\n <ion-searchbar (ionChange)=\"onChange($event)\" placeholder=\"Pesquisar por cantacto\" ></ion-searchbar>\r\n </div>\r\n </ion-toolbar>\r\n</ion-header>\r\n\r\n<ion-content>\r\n <ion-refresher name=\"refresher\" slot=\"fixed\" (ionRefresh)=\"doRefresh($event)\">\r\n <ion-progress-bar type=\"indeterminate\" *ngIf=\"showLoader\"></ion-progress-bar>\r\n <ion-refresher-content>\r\n </ion-refresher-content>\r\n </ion-refresher>\r\n <div class=\"main-content\">\r\n \r\n <!-- <ion-list>\r\n <ion-item *ngFor=\"let user of searchedItem\">\r\n {{user.name}}\r\n </ion-item>\r\n </ion-list> -->\r\n\r\n <ion-virtual-scroll [items]=\"users\" approxItemHeight=\"70px\" [headerFn]=\"separateLetter\">\r\n \r\n <div class=\"item-divider\" *virtualHeader=\"let header\">\r\n <ion-label>{{header}}</ion-label>\r\n </div>\r\n\r\n <div *virtualItem=\"let user\" class=\"item-checkbox\">\r\n <ion-checkbox color=\"primary\"></ion-checkbox>\r\n <p>{{user.first}} {{user.last}}</p>\r\n <ion-icon name=\"ellipse\"></ion-icon>\r\n </div>\r\n \r\n </ion-virtual-scroll>\r\n \r\n </div> \r\n</ion-content>\r\n";
__webpack_exports__["default"] = "<ion-header class=\"ion-no-border\">\r\n <ion-toolbar class=\"header-toolbar\">\r\n <div class=\"main-header\">\r\n <div class=\"title-content\">\r\n <div class=\"back-icon\">\r\n <ion-icon (click)=\"close()\" slot=\"end\" src='assets/images/icons-arrow-arrow-left.svg'></ion-icon>\r\n </div>\r\n <div class=\"div-title\">\r\n <ion-label class=\"title\">Contactos</ion-label>\r\n </div>\r\n <app-btn-seguinte (click)=\"groupMessages()\"></app-btn-seguinte>\r\n </div>\r\n </div>\r\n </ion-toolbar>\r\n <ion-toolbar class=\"toolbar-search\">\r\n <div class=\"search\">\r\n <ion-searchbar debounce=\"500\" (ionChange)=\"onChange($event)\" placeholder=\"Pesquisar por cantacto\" ></ion-searchbar>\r\n </div>\r\n </ion-toolbar>\r\n</ion-header>\r\n\r\n<ion-content>\r\n <ion-refresher name=\"refresher\" slot=\"fixed\" (ionRefresh)=\"doRefresh($event)\">\r\n <ion-progress-bar type=\"indeterminate\" *ngIf=\"showLoader\"></ion-progress-bar>\r\n <ion-refresher-content>\r\n </ion-refresher-content>\r\n </ion-refresher>\r\n \r\n <div class=\"main-content\">\r\n <ion-virtual-scroll [items]=\"users | filter:textSearch: 'name'\" approxItemHeight=\"70px\" [headerFn]=\"separateLetter\">\r\n \r\n <div class=\"item-divider\" *virtualHeader=\"let header\">\r\n <ion-label>{{header}}</ion-label>\r\n </div>\r\n\r\n <div *virtualItem=\"let user\" class=\"item-checkbox\">\r\n <ion-checkbox color=\"primary\"></ion-checkbox>\r\n <p>{{user.name}}</p>\r\n <ion-icon name=\"ellipse\"></ion-icon>\r\n </div>\r\n \r\n </ion-virtual-scroll>\r\n \r\n </div> \r\n</ion-content>\r\n";
/***/
},
@@ -1079,48 +1079,40 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
/* harmony import */
var _group_messages_page__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
var src_app_services_auth_service__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
/*! src/app/services/auth.service */
"./src/app/services/auth.service.ts");
/* harmony import */
var src_app_services_chat_service__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(
/*! src/app/services/chat.service */
"./src/app/services/chat.service.ts");
/* harmony import */
var _group_messages_page__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(
/*! ../group-messages.page */
"./src/app/pages/chat/group-messages/group-messages.page.ts");
var GroupContactsPage = /*#__PURE__*/function () {
function GroupContactsPage(modalController, http) {
function GroupContactsPage(modalController, http, chatService, authService) {
var _this6 = this;
_classCallCheck(this, GroupContactsPage);
this.modalController = modalController;
this.http = http;
this.chatService = chatService;
this.authService = authService;
this.users = [];
this.contact = [" Ana M.", "Andre F.", "Bruno G.", "Catarina T", "Tiago"];
this.contacts = [{
first: 'Ana',
last: 'Manuel',
url: 'https://randomuser.me/api/portraits/med/women/54.jpg'
}, {
first: 'Abdullah',
last: 'Hill',
url: 'https://randomuser.me/api/portraits/med/women/54.jpg'
}, {
first: 'Batur',
last: 'Oymen',
url: 'https://randomuser.me/api/portraits/med/women/54.jpg'
}, {
first: 'Bianca',
last: 'Costa',
url: 'https://randomuser.me/api/portraits/med/women/54.jpg'
}, {
first: 'Zaya',
last: 'Mary',
url: 'https://randomuser.me/api/portraits/med/women/54.jpg'
}, {
first: 'Tiago',
last: 'Kayaya',
url: 'https://randomuser.me/api/portraits/med/women/54.jpg'
}];
this.headers = new _angular_common_http__WEBPACK_IMPORTED_MODULE_1__["HttpHeaders"]();
this.headers = this.headers.set('Access-Control-Allow-Origin', '*');
this.headers = this.headers.set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
this.headers = this.headers.set('Accept', 'application/json');
this.headers = this.headers.set('content-type', 'application/json');
this.authService.userData$.subscribe(function (res) {
_this6.loggedUser = res;
});
this.textSearch = "";
this.dm = null;
this.room = null;
}
_createClass(GroupContactsPage, [{
@@ -1131,54 +1123,39 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: "loadUsers",
value: function loadUsers() {
var _this7 = this;
this.options = {
headers: this.headers
};
/* this.http.get('https://randomuser.me/api/?results=100', this.options)
.subscribe(res => {
this.users = res['results'].sort((a,b) => {
if(a.name.first < b.name.first){
this.chatService.getAllUsers().subscribe(function (res) {
console.log(res.users);
_this7.contacts = res.users.filter(function (data) {
return data.username != _this7.loggedUser.me.username;
});
_this7.users = _this7.contacts.sort(function (a, b) {
if (a.name < b.name) {
return -1;
}
if(a.name.first > b.name.first){
if (a.name > b.name) {
return 1;
}
return 0;
});
console.log(res);
console.log(this.users);
}); */
this.users = this.contacts.sort(function (a, b) {
if (a.first < b.first) {
return -1;
}
if (a.first > b.first) {
return 1;
}
return 0;
_this7.showLoader = false;
});
}
}, {
key: "separateLetter",
value: function separateLetter(record, recordIndex, records) {
/* if(recordIndex == 0){
return record.name.first[0];
}
let first_prev = records[recordIndex - 1].name.first[0];
let first_current = record.name.first[0];
if(first_prev != first_current){
return first_current;
}
return null; */
if (recordIndex == 0) {
return record.first[0];
return record.name[0];
}
var first_prev = records[recordIndex - 1].first[0];
var first_current = record.first[0];
var first_prev = records[recordIndex - 1].name[0];
var first_current = record.name[0];
if (first_prev != first_current) {
return first_current;
@@ -1192,11 +1169,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: "close",
value: function close() {
this.modalController.dismiss();
this.modalController.dismiss(true);
}
}, {
key: "onChange",
value: function onChange(event) {}
value: function onChange(event) {
this.textSearch = event.detail.value;
}
}, {
key: "clicked",
value: function clicked() {
@@ -1214,7 +1193,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
this.close();
_context6.next = 3;
return this.modalController.create({
component: _group_messages_page__WEBPACK_IMPORTED_MODULE_4__["GroupMessagesPage"],
component: _group_messages_page__WEBPACK_IMPORTED_MODULE_6__["GroupMessagesPage"],
componentProps: {},
cssClass: 'contacts',
backdropDismiss: false
@@ -1226,7 +1205,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return modal.present();
case 6:
modal.onDidDismiss();
modal.onDidDismiss().then(function (res) {
if (res.data) {
console.log('go to new group');
}
});
case 7:
case "end":
@@ -1246,6 +1229,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
type: _ionic_angular__WEBPACK_IMPORTED_MODULE_3__["ModalController"]
}, {
type: _angular_common_http__WEBPACK_IMPORTED_MODULE_1__["HttpClient"]
}, {
type: src_app_services_chat_service__WEBPACK_IMPORTED_MODULE_5__["ChatService"]
}, {
type: src_app_services_auth_service__WEBPACK_IMPORTED_MODULE_4__["AuthService"]
}];
};
@@ -1367,11 +1354,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
_createClass(GroupMessagesPage, [{
key: "ngOnInit",
value: function ngOnInit() {
var _this6 = this;
var _this8 = this;
this.authService.userData$.subscribe(function (res) {
_this6.loggedUser = res;
console.log(_this6.loggedUser);
_this8.loggedUser = res;
console.log(_this8.loggedUser);
});
this.getGroupContacts();
this.loadGroupMessages();
@@ -1379,45 +1366,45 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: "getGroupContacts",
value: function getGroupContacts() {
var _this7 = this;
var _this9 = this;
//If group is private call getGroupMembers
if (this.room.t === 'p') {
this.chatService.getGroupMembers(this.room._id).subscribe(function (res) {
console.log(res);
_this7.members = res['members'];
_this9.members = res['members'];
});
} //Otherwise call getChannelMembers for públic groups
else {
this.chatService.getChannelMembers(this.room._id).subscribe(function (res) {
console.log(res);
_this7.members = res['members'];
_this9.members = res['members'];
});
}
}
}, {
key: "loadGroupMessages",
value: function loadGroupMessages() {
var _this8 = this;
var _this10 = this;
//If group is private call getGroupMembers
if (this.room.t === 'p') {
this.chatService.getPrivateGroupMessages(this.room._id).subscribe(function (res) {
console.log(res);
_this8.messages = res['messages'].reverse();
_this10.messages = res['messages'].reverse();
});
} //Otherwise call getChannelMembers for públic groups
else {
this.chatService.getPublicGroupMessages(this.room._id).subscribe(function (res) {
console.log(res);
_this8.messages = res['messages'].reverse();
_this10.messages = res['messages'].reverse();
});
}
}
}, {
key: "sendMessage",
value: function sendMessage() {
var _this9 = this;
var _this11 = this;
var body = {
"message": {
@@ -1426,7 +1413,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}
};
this.chatService.sendMessage(body).subscribe(function (res) {
_this9.loadGroupMessages();
_this11.loadGroupMessages();
});
this.message = "";
}
@@ -1477,7 +1464,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
key: "openOptions",
value: function openOptions(ev) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
var _this10 = this;
var _this12 = this;
var popover;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
@@ -1503,7 +1490,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
case 5:
popover.onDidDismiss().then(function (res) {
if (res.data) {
_this10.modalController.dismiss();
_this12.modalController.dismiss();
}
;
@@ -1705,7 +1692,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var ContactsPage = /*#__PURE__*/function () {
function ContactsPage(modalController, http, chatService, authService) {
var _this11 = this;
var _this13 = this;
_classCallCheck(this, ContactsPage);
@@ -1715,7 +1702,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
this.authService = authService;
this.users = [];
this.authService.userData$.subscribe(function (res) {
_this11.loggedUser = res;
_this13.loggedUser = res;
});
this.textSearch = "";
this.dm = null;
@@ -1735,17 +1722,17 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: "loadUsers",
value: function loadUsers() {
var _this12 = this;
var _this14 = this;
this.options = {
headers: this.headers
};
this.chatService.getAllUsers().subscribe(function (res) {
console.log(res.users);
_this12.contacts = res.users.filter(function (data) {
return data.username != _this12.loggedUser.me.username;
_this14.contacts = res.users.filter(function (data) {
return data.username != _this14.loggedUser.me.username;
});
_this12.users = _this12.contacts.sort(function (a, b) {
_this14.users = _this14.contacts.sort(function (a, b) {
if (a.name < b.name) {
return -1;
}
@@ -1756,7 +1743,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return 0;
});
_this12.showLoader = false;
_this14.showLoader = false;
});
}
}, {
@@ -1791,32 +1778,32 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: "createRoom",
value: function createRoom(username) {
var _this13 = this;
var _this15 = this;
var body = {
username: username
};
this.chatService.createRoom(body).subscribe(function (res) {
console.log(res);
_this13.room = res['room'];
_this15.room = res['room'];
_this13.getDirectMessage(_this13.room._id);
_this15.getDirectMessage(_this15.room._id);
});
}
}, {
key: "getDirectMessage",
value: function getDirectMessage(roomId) {
var _this14 = this;
var _this16 = this;
console.log(roomId);
this.chatService.getAllDirectMessages().subscribe(function (res) {
var result = res['ims'].filter(function (data) {
return data._id == roomId;
});
_this14.dm = result[0];
console.log(_this14.dm);
_this16.dm = result[0];
console.log(_this16.dm);
_this14.openModal(_this14.dm);
_this16.openModal(_this16.dm);
});
}
}, {
@@ -2025,12 +2012,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
_createClass(MessagesPage, [{
key: "ngOnInit",
value: function ngOnInit() {
var _this15 = this;
var _this17 = this;
this.scrollToBottom();
this.authService.userData$.subscribe(function (res) {
_this15.loggedUser = res;
console.log(_this15.loggedUser);
_this17.loggedUser = res;
console.log(_this17.loggedUser);
});
/* console.log(this.dm); */
@@ -2065,16 +2052,16 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: "checkUserPresence",
value: function checkUserPresence() {
var _this16 = this;
var _this18 = this;
this.chatService.getUserPresence(this.dm.lastMessage.u._id).subscribe(function (res) {
_this16.userPresence = res['presence'];
_this18.userPresence = res['presence'];
});
}
}, {
key: "sendMessage",
value: function sendMessage() {
var _this17 = this;
var _this19 = this;
var body = {
"message": {
@@ -2083,31 +2070,31 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}
};
this.chatService.sendMessage(body).subscribe(function (res) {
_this17.loadMessages();
_this19.loadMessages();
});
this.message = "";
}
}, {
key: "loadMessages",
value: function loadMessages() {
var _this18 = this;
var _this20 = this;
this.chatService.getRoomMessages(this.dm._id).subscribe(function (res) {
/* console.log(res); */
_this18.messages = res['messages'].reverse();
_this20.messages = res['messages'].reverse();
});
}
}, {
key: "getChatMembers",
value: function getChatMembers() {
var _this19 = this;
var _this21 = this;
this.chatService.getMembers(this.dm._id).subscribe(function (res) {
_this19.dmUsers = res['members'].filter(function (data) {
return data.username != _this19.loggedUser.me.username;
_this21.dmUsers = res['members'].filter(function (data) {
return data.username != _this21.loggedUser.me.username;
});
console.log(res);
console.log(_this19.dmUsers);
console.log(_this21.dmUsers);
});
}
}, {
@@ -2655,7 +2642,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
key: "showPicker",
value: function showPicker() {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
var _this20 = this;
var _this22 = this;
var picker;
return regeneratorRuntime.wrap(function _callee20$(_context20) {
@@ -2674,29 +2661,29 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
cssClass: 'btn-cancel',
handler: function handler(value) {
console.log('button done pressed');
_this20.selectedDuration = [value.days.value, value.hours.value, value.minutes.value];
console.log(_this20.selectedDuration);
_this22.selectedDuration = [value.days.value, value.hours.value, value.minutes.value];
console.log(_this22.selectedDuration);
if (value.days.value != null && value.hours.value != null && value.minutes.value != null) {
if (value.days.value > 0) {
if (value.days.value == 1) {
if (value.hours.value == 1) {
_this20.displayDuration = value.days.value + " day " + value.hours.value + " hora " + value.minutes.value + " minutos";
_this22.displayDuration = value.days.value + " day " + value.hours.value + " hora " + value.minutes.value + " minutos";
} else {
_this20.displayDuration = value.days.value + " days " + value.hours.value + " horas " + value.minutes.value + " minutos";
_this22.displayDuration = value.days.value + " days " + value.hours.value + " horas " + value.minutes.value + " minutos";
}
} else {
if (value.hours.value == 1) {
_this20.displayDuration = value.days.value + " days " + value.hours.value + " hora " + value.minutes.value + " minutos";
_this22.displayDuration = value.days.value + " days " + value.hours.value + " hora " + value.minutes.value + " minutos";
} else {
_this20.displayDuration = value.days.value + " days " + value.hours.value + " horas " + value.minutes.value + " minutos";
_this22.displayDuration = value.days.value + " days " + value.hours.value + " horas " + value.minutes.value + " minutos";
}
}
} else {
if (value.hours.value == 1) {
_this20.displayDuration = value.hours.value + " hora " + value.minutes.value + " minutos";
_this22.displayDuration = value.hours.value + " hora " + value.minutes.value + " minutos";
} else {
_this20.displayDuration = value.hours.value + " horas " + value.minutes.value + " minutos";
_this22.displayDuration = value.hours.value + " horas " + value.minutes.value + " minutos";
}
}
}
@@ -2800,7 +2787,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
case 5:
picker.onDidDismiss().then(function (data) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(_this20, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(_this22, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
var day, hour, minutes;
return regeneratorRuntime.wrap(function _callee19$(_context19) {
while (1) {