From 46733f4b215f34b06d87452f92bd9a1bf9619f1e Mon Sep 17 00:00:00 2001 From: deissh Date: Thu, 4 Apr 2019 09:37:51 +0300 Subject: [PATCH 01/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=83=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D0=BC=D0=BE=D1=82=D1=80=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=B8=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xml | 3 +- src/app/app-routing.module.ts | 2 + src/app/pages/chat-id/chat-id.module.ts | 26 ++++++++++ src/app/pages/chat-id/chat-id.page.html | 9 ++++ src/app/pages/chat-id/chat-id.page.scss | 0 src/app/pages/chat-id/chat-id.page.spec.ts | 27 ++++++++++ src/app/pages/chat-id/chat-id.page.ts | 38 ++++++++++++++ src/app/pages/chats/chats.module.ts | 26 ++++++++++ src/app/pages/chats/chats.page.html | 34 ++++++++++++ src/app/pages/chats/chats.page.scss | 0 src/app/pages/chats/chats.page.spec.ts | 27 ++++++++++ src/app/pages/chats/chats.page.ts | 58 +++++++++++++++++++++ src/app/providers/interfaces.ts | 60 ++++++++++++++++++++++ 13 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 src/app/pages/chat-id/chat-id.module.ts create mode 100644 src/app/pages/chat-id/chat-id.page.html create mode 100644 src/app/pages/chat-id/chat-id.page.scss create mode 100644 src/app/pages/chat-id/chat-id.page.spec.ts create mode 100644 src/app/pages/chat-id/chat-id.page.ts create mode 100644 src/app/pages/chats/chats.module.ts create mode 100644 src/app/pages/chats/chats.page.html create mode 100644 src/app/pages/chats/chats.page.scss create mode 100644 src/app/pages/chats/chats.page.spec.ts create mode 100644 src/app/pages/chats/chats.page.ts diff --git a/config.xml b/config.xml index 9ea3dc2..4dead05 100644 --- a/config.xml +++ b/config.xml @@ -90,7 +90,8 @@ - + + diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 25b063d..29e8547 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -16,6 +16,8 @@ const routes: Routes = [ { path: 'comments/:id', loadChildren: './pages/comments/comments.module#CommentsPageModule', canActivate: [LoginGuard] }, { path: 'user/:id', loadChildren: './pages/user/user.module#UserPageModule' }, { path: 'news/:id', loadChildren: './pages/news/news.module#NewsPageModule' }, + { path: 'chats', loadChildren: './pages/chats/chats.module#ChatsPageModule' }, + { path: 'chat-id/:id', loadChildren: './pages/chat-id/chat-id.module#ChatIdPageModule' }, ]; @NgModule({ imports: [RouterModule.forRoot(routes)], diff --git a/src/app/pages/chat-id/chat-id.module.ts b/src/app/pages/chat-id/chat-id.module.ts new file mode 100644 index 0000000..d26c59a --- /dev/null +++ b/src/app/pages/chat-id/chat-id.module.ts @@ -0,0 +1,26 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; +import { Routes, RouterModule } from '@angular/router'; + +import { IonicModule } from '@ionic/angular'; + +import { ChatIdPage } from './chat-id.page'; + +const routes: Routes = [ + { + path: '', + component: ChatIdPage + } +]; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + RouterModule.forChild(routes) + ], + declarations: [ChatIdPage] +}) +export class ChatIdPageModule {} diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html new file mode 100644 index 0000000..f04894d --- /dev/null +++ b/src/app/pages/chat-id/chat-id.page.html @@ -0,0 +1,9 @@ + + + chat-id + + + + + + diff --git a/src/app/pages/chat-id/chat-id.page.scss b/src/app/pages/chat-id/chat-id.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/chat-id/chat-id.page.spec.ts b/src/app/pages/chat-id/chat-id.page.spec.ts new file mode 100644 index 0000000..79f1736 --- /dev/null +++ b/src/app/pages/chat-id/chat-id.page.spec.ts @@ -0,0 +1,27 @@ +import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ChatIdPage } from './chat-id.page'; + +describe('ChatIdPage', () => { + let component: ChatIdPage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ChatIdPage ], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ChatIdPage); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts new file mode 100644 index 0000000..71ed1b1 --- /dev/null +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -0,0 +1,38 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { LoadingController } from '@ionic/angular'; +import { IChat, IMessage } from 'src/app/providers/interfaces'; + +@Component({ + selector: 'app-chat-id', + templateUrl: './chat-id.page.html', + styleUrls: ['./chat-id.page.scss'], +}) +export class ChatIdPage implements OnInit { + + private id: string; + public chatinfo: IChat; + public messages: IMessage; + + private spiner: HTMLIonLoadingElement; + + constructor( + private route: ActivatedRoute, + private router: Router, + private loadingController: LoadingController, + ) { } + + async ngOnInit() { + this.id = this.route.snapshot.paramMap.get('id'); + this.spiner = await this.loadingController.create({ + message: 'Загрузка...', + duration: 5000 + }); + await this.spiner.present(); + } + + private async load() { + + await this.spiner.dismiss(); + } +} diff --git a/src/app/pages/chats/chats.module.ts b/src/app/pages/chats/chats.module.ts new file mode 100644 index 0000000..558df83 --- /dev/null +++ b/src/app/pages/chats/chats.module.ts @@ -0,0 +1,26 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; +import { Routes, RouterModule } from '@angular/router'; + +import { IonicModule } from '@ionic/angular'; + +import { ChatsPage } from './chats.page'; + +const routes: Routes = [ + { + path: '', + component: ChatsPage + } +]; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + RouterModule.forChild(routes) + ], + declarations: [ChatsPage] +}) +export class ChatsPageModule {} diff --git a/src/app/pages/chats/chats.page.html b/src/app/pages/chats/chats.page.html new file mode 100644 index 0000000..776b73a --- /dev/null +++ b/src/app/pages/chats/chats.page.html @@ -0,0 +1,34 @@ + + + Активные чаты + + + + + + + + + + + + + + + + + + + {{ item.name }} + +

{{ item.lastmessage.user.name }}: {{ item.lastmessage.body }}

+
+
+
+
diff --git a/src/app/pages/chats/chats.page.scss b/src/app/pages/chats/chats.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/chats/chats.page.spec.ts b/src/app/pages/chats/chats.page.spec.ts new file mode 100644 index 0000000..e535ace --- /dev/null +++ b/src/app/pages/chats/chats.page.spec.ts @@ -0,0 +1,27 @@ +import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ChatsPage } from './chats.page'; + +describe('ChatsPage', () => { + let component: ChatsPage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ChatsPage ], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ChatsPage); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/chats/chats.page.ts b/src/app/pages/chats/chats.page.ts new file mode 100644 index 0000000..5250b8e --- /dev/null +++ b/src/app/pages/chats/chats.page.ts @@ -0,0 +1,58 @@ +import { Component, OnInit } from '@angular/core'; +import { IChat } from 'src/app/providers/interfaces'; +import { Router } from '@angular/router'; + +@Component({ + selector: 'app-chats', + templateUrl: './chats.page.html', + styleUrls: ['./chats.page.scss'], +}) +export class ChatsPage implements OnInit { + + public chats: IChat[] = []; + + constructor( + private router: Router + ) { } + + async ngOnInit() { + await this.load(); + } + + public async update(event: any) { + this.load() + .then(() => event.target.complete()) + .catch(() => event.target.cansel()); + } + + public async open(id: string) { + this.router.navigateByUrl(`/chat-id/${id}`); + } + + private async load(): Promise { + this.chats = [ + { + id: '1', + name: 'Chat nomer odin', + picture: 'https://cdn.anibe.ru/avatars/5c533dbb889e940019ec1d9c/1551757027703', + users: [], + lastmessage: { + id: '12312312', + body: 'some text', + user: { + id: '12', + name: 'deissh', + online: '1', + badges: [], + picture: 'https://cdn.anibe.ru/avatars/5c533dbb889e940019ec1d9c/1551757027703', + role: 'admin' + }, + createdAt: '12.03.2019', + updatedAt: '04.04.2019', + }, + createdAt: '12.03.2019', + updatedAt: '04.04.2019', + } + ]; + } +} diff --git a/src/app/providers/interfaces.ts b/src/app/providers/interfaces.ts index e6fb675..0bbc746 100644 --- a/src/app/providers/interfaces.ts +++ b/src/app/providers/interfaces.ts @@ -95,3 +95,63 @@ export interface INotif { createdAt: string; updatedAt: string; } + + + +export interface IChat { + id: string; + name: string; + picture: string; + users: IUser[]; + lastmessage?: IMessage; + + createdAt: string; + updatedAt: string; +} + +export interface IMessage { + id: string; + body: string; + user: IUser; + attachments?: { + images?: string[]; + links?: string[]; + sticker?: string; + }; + + createdAt: string; + updatedAt: string; +} + +export interface IUserBadge { + name: string; + icon: string; +} + +export interface IUser { + id: string; + online: string; + name: string; + picture: string; + role: string; + badges: IUserBadge[]; +} + +export interface IUserSelf { + id: string; + online: string; + name: string; + picture: string; + desc: string; + email: string; + enablefcm: boolean; + role: string; + favorite: IPost[]; + thrown: IPost[]; + inprogress: IPost[]; + readed: IPost[]; + willread: IPost[]; + createdAt: string; + updatedAt: string; + badges: IUserBadge[]; +} From c2ce04910b78f4dd972840895d21c88de25494ed Mon Sep 17 00:00:00 2001 From: deissh Date: Thu, 4 Apr 2019 09:53:16 +0300 Subject: [PATCH 02/26] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/chat-id/chat-id.page.html | 52 ++++++++- src/app/pages/chat-id/chat-id.page.scss | 148 ++++++++++++++++++++++++ src/app/pages/chat-id/chat-id.page.ts | 1 + 3 files changed, 200 insertions(+), 1 deletion(-) diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index f04894d..fa4e3c9 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -4,6 +4,56 @@ - + +
+ +
+ + +
+
+

+ deissh   09:20 +

+
+
+ +

Супер крутое сообщение

+
+
+
+ +
+ +
+
+

+ deissh   09:20 +

+
+
+ +

Ну, тут будет не менее крутое сообщение. А так же текст который позволит сделать сообщение подлинее!

+
+
+
+ + + +
diff --git a/src/app/pages/chat-id/chat-id.page.scss b/src/app/pages/chat-id/chat-id.page.scss index e69de29..e434f16 100644 --- a/src/app/pages/chat-id/chat-id.page.scss +++ b/src/app/pages/chat-id/chat-id.page.scss @@ -0,0 +1,148 @@ +$userBackgroundColor: #387ef5; +$toUserBackgroundColor: #fff; + +ion-content .scroll-content { + background-color: #f5f5f5; +} + +ion-footer { + box-shadow: 0 0 4px rgba(0, 0, 0, 0.11); + background-color: #fff; + height: 255px; +} + +.line-breaker { + white-space: pre-line; +} + +.input-wrap { + padding: 5px; + display: flex; + + textarea { + flex: 1; + border: 0; + border-bottom: 1px $userBackgroundColor; + border-style: solid; + } +} + +.message-wrap { + padding: 0 10px; + + .message { + position: relative; + padding: 7px 0; + + .user-img { + position: absolute; + border-radius: 45px; + width: 45px; + height: 45px; + box-shadow: 0 0 2px rgba(0, 0, 0, 0.36); + } + + .msg-detail { + width: 100%; + display: inline-block; + + p { + margin: 0; + } + + .msg-info { + p { + font-size: .8em; + color: #888; + } + } + + .msg-content { + position: relative; + margin-top: 5px; + border-radius: 5px; + padding: 8px; + border: 1px solid #ddd; + color: #fff; + width: auto; + max-width: 80%; + + span.triangle { + background-color: #fff; + border-radius: 2px; + height: 8px; + width: 8px; + top: 12px; + display: block; + border-style: solid; + border-color: #ddd; + border-width: 1px; + -webkit-transform: rotate(45deg); + transform: rotate(45deg); + position: absolute; + } + } + + } + } + + .message.left { + .msg-content { + background-color: $toUserBackgroundColor; + float: left; + } + + .msg-detail { + padding-left: 60px; + } + + .user-img { + left: 0; + } + + .msg-content { + color: #343434 !important; + + span.triangle { + border-top-width: 0; + border-right-width: 0; + left: -5px; + } + } + + } + + .message.right { + .msg-detail { + padding-right: 60px; + + .msg-info { + text-align: right; + } + } + + .user-img { + right: 0; + } + + ion-spinner { + position: absolute; + right: 10px; + top: 50px; + } + + .msg-content { + background-color: $userBackgroundColor; + float: right; + + span.triangle { + background-color: $userBackgroundColor; + border-bottom-width: 0; + border-left-width: 0; + right: -5px; + } + } + + } + +} diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index 71ed1b1..84fe927 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -29,6 +29,7 @@ export class ChatIdPage implements OnInit { duration: 5000 }); await this.spiner.present(); + await this.load(); } private async load() { From 40389126941f54a822ae6556cc9eff44f37db3ad Mon Sep 17 00:00:00 2001 From: deissh Date: Thu, 4 Apr 2019 12:45:02 +0300 Subject: [PATCH 03/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D0=BB=D0=B5=20=D0=B2=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/chat-id/chat-id.page.html | 20 ++++++++++++++++++-- src/app/pages/chat-id/chat-id.page.scss | 2 +- src/app/pages/chat-id/chat-id.page.ts | 9 +++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index fa4e3c9..7a736a1 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -34,7 +34,8 @@
-

Ну, тут будет не менее крутое сообщение. А так же текст который позволит сделать сообщение подлинее!

+

Ну, тут будет не менее крутое сообщение. А так же текст который позволит сделать + сообщение подлинее!

@@ -46,7 +47,7 @@
-

+

@@ -57,3 +58,18 @@
-->
+ + + + + + + + + + + + + + + diff --git a/src/app/pages/chat-id/chat-id.page.scss b/src/app/pages/chat-id/chat-id.page.scss index e434f16..720b84b 100644 --- a/src/app/pages/chat-id/chat-id.page.scss +++ b/src/app/pages/chat-id/chat-id.page.scss @@ -8,7 +8,7 @@ ion-content .scroll-content { ion-footer { box-shadow: 0 0 4px rgba(0, 0, 0, 0.11); background-color: #fff; - height: 255px; + // height: 255px; } .line-breaker { diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index 84fe927..e7cb163 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -14,6 +14,11 @@ export class ChatIdPage implements OnInit { public chatinfo: IChat; public messages: IMessage; + /** + * @description contain current message + */ + public editorMsg: string; + private spiner: HTMLIonLoadingElement; constructor( @@ -32,6 +37,10 @@ export class ChatIdPage implements OnInit { await this.load(); } + public async send() { + // todo this + } + private async load() { await this.spiner.dismiss(); From ccf89cad45ea833f2f88678f41017cd98da8f665 Mon Sep 17 00:00:00 2001 From: deissh Date: Thu, 4 Apr 2019 12:56:52 +0300 Subject: [PATCH 04/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/providers/chat.service.spec.ts | 12 +++ src/app/providers/chat.service.ts | 101 +++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/app/providers/chat.service.spec.ts create mode 100644 src/app/providers/chat.service.ts diff --git a/src/app/providers/chat.service.spec.ts b/src/app/providers/chat.service.spec.ts new file mode 100644 index 0000000..f9d1b52 --- /dev/null +++ b/src/app/providers/chat.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { ChatService } from './chat.service'; + +describe('ChatService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: ChatService = TestBed.get(ChatService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts new file mode 100644 index 0000000..5cf4f23 --- /dev/null +++ b/src/app/providers/chat.service.ts @@ -0,0 +1,101 @@ +import { Injectable } from '@angular/core'; +import { API } from './api.service'; +import { IPostFull, RequestParam, IPost, IComment, IChat, IMessage } from './interfaces'; +import { Storage } from '@ionic/storage'; +import { ToastController } from '@ionic/angular'; + +@Injectable({ + providedIn: 'root' +}) +export class ChatService { + /** + * Экземпляр класса для работы с апи через небольшую обертку + */ + private api: API; + private token: string; + private ready: Promise; + + constructor( + private storage: Storage, + private toast: ToastController + ) { + this.api = new API({ }); + } + + /** + * Получить чат по его айди + * @async + * @param {string} id uuid чата + * @returns {Promise} результат + */ + public async get(id: string): Promise { + this.token = await this.storage.get('token') || ''; + const url = `/chats/${id}`; + + const res = await this.api.get(url, { + 'Authorization': 'Bearer ' + this.token + }); + return JSON.parse(res.data); + } + + /** + * Получение всех активных чатов для пользователя + * @async + * @param {string} query Название чата, может быть null + * @returns {Promise} + */ + public async getAll(query?: string): Promise { + this.token = await this.storage.get('token') || ''; + let url = `/chats`; + if (query) { + url += `?q=${query}`; + } + + const res = await this.api.get(url, { + 'Authorization': 'Bearer ' + this.token + }); + + return JSON.parse(res.data).rows; + } + + /** + * Отправляет сообщение в чат + * @param chat_id uuid чата + * @param body сообщение + * @param attachments прикрепления к сообщению + */ + public async createComment( + chat_id: string, + body: string, + attachments?: { + images: string[], + links: string[], + videos: string[], + sticker: string + } + ): Promise { + this.token = await this.storage.get('token') || ''; + + const res = await this.api.post(`/chats/${chat_id}`, { + body, + attachments + }, { + 'Authorization': 'Bearer ' + this.token + }); + return JSON.parse(res.data); + } + + /** + * Получение сообщений с паджинацией + * @param {string} id uuid чата + */ + public async getMessage(id: string, page: number = 1): Promise { + this.token = await this.storage.get('token') || ''; + + const res = await this.api.get(`/chats/${id}?page=${page}`, { + 'Authorization': 'Bearer ' + this.token + }); + + return JSON.parse(res.data); + } +} From 4ab9ef59ac451e19b4ba4c5d31e2740e73c9aeff Mon Sep 17 00:00:00 2001 From: deissh Date: Thu, 4 Apr 2019 13:44:54 +0300 Subject: [PATCH 05/26] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20+=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/chat-id/chat-id.page.html | 50 +++++++++++++------------ src/app/pages/chat-id/chat-id.page.scss | 6 +-- src/app/pages/chat-id/chat-id.page.ts | 30 +++++++++++++-- src/app/providers/chat.service.ts | 4 +- 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index 7a736a1..ceb1b83 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -1,6 +1,6 @@ - - chat-id + + {{ chatinfo.name }} Онлайн {{online()}}/{{ chatinfo.users.length }} @@ -8,23 +8,27 @@
-
- - +
+

- deissh   09:20 + {{ msg.user.name }}   {{ msg.createdAt | date }}

-

Супер крутое сообщение

+

{{ msg.body }}

-
+
@@ -39,23 +43,23 @@
- - - + +
diff --git a/src/app/pages/chat-id/chat-id.page.scss b/src/app/pages/chat-id/chat-id.page.scss index 720b84b..516151d 100644 --- a/src/app/pages/chat-id/chat-id.page.scss +++ b/src/app/pages/chat-id/chat-id.page.scss @@ -29,7 +29,6 @@ ion-footer { .message-wrap { padding: 0 10px; - .message { position: relative; padding: 7px 0; @@ -68,14 +67,12 @@ ion-footer { max-width: 80%; span.triangle { - background-color: #fff; border-radius: 2px; height: 8px; width: 8px; top: 12px; display: block; border-style: solid; - border-color: #ddd; border-width: 1px; -webkit-transform: rotate(45deg); transform: rotate(45deg); @@ -104,6 +101,8 @@ ion-footer { color: #343434 !important; span.triangle { + background-color: $toUserBackgroundColor; + border-color: $toUserBackgroundColor; border-top-width: 0; border-right-width: 0; left: -5px; @@ -137,6 +136,7 @@ ion-footer { span.triangle { background-color: $userBackgroundColor; + border-color: $userBackgroundColor; border-bottom-width: 0; border-left-width: 0; right: -5px; diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index e7cb163..c7e7de9 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -1,7 +1,9 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { LoadingController } from '@ionic/angular'; -import { IChat, IMessage } from 'src/app/providers/interfaces'; +import { IChat, IMessage, IUserSelf } from 'src/app/providers/interfaces'; +import { ChatService } from 'src/app/providers/chat.service'; +import { Storage } from '@ionic/storage'; @Component({ selector: 'app-chat-id', @@ -12,7 +14,11 @@ export class ChatIdPage implements OnInit { private id: string; public chatinfo: IChat; - public messages: IMessage; + public user: IUserSelf; + public messages: IMessage[]; + + private page: number = 0; + private attachments: any; /** * @description contain current message @@ -22,8 +28,10 @@ export class ChatIdPage implements OnInit { private spiner: HTMLIonLoadingElement; constructor( + private cs: ChatService, private route: ActivatedRoute, private router: Router, + private storage: Storage, private loadingController: LoadingController, ) { } @@ -33,16 +41,30 @@ export class ChatIdPage implements OnInit { message: 'Загрузка...', duration: 5000 }); + + this.user = await this.storage.get('user_local'); + await this.spiner.present(); await this.load(); } + public async msgmenu(event: any) { + console.log(this); + } + public async send() { - // todo this + const msg = await this.cs.createMessage(this.id, this.editorMsg, this.attachments) + this.messages.push(msg); } - private async load() { + public online(): number { + const online = this.chatinfo.users.filter((u) => u.online !== '0'); + return online.length; + } + private async load() { + // this.messages = await this.cs.getMessages(this.id, this.page); + // this.chatinfo = await this.cs.get(this.id); await this.spiner.dismiss(); } } diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index 5cf4f23..bb79df5 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -64,7 +64,7 @@ export class ChatService { * @param body сообщение * @param attachments прикрепления к сообщению */ - public async createComment( + public async createMessage( chat_id: string, body: string, attachments?: { @@ -89,7 +89,7 @@ export class ChatService { * Получение сообщений с паджинацией * @param {string} id uuid чата */ - public async getMessage(id: string, page: number = 1): Promise { + public async getMessages(id: string, page: number = 1): Promise { this.token = await this.storage.get('token') || ''; const res = await this.api.get(`/chats/${id}?page=${page}`, { From 1e5d54f0f492b607fd92361794b0fbb8361cdd1d Mon Sep 17 00:00:00 2001 From: deissh Date: Thu, 4 Apr 2019 22:10:03 +0300 Subject: [PATCH 06/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83?= =?UTF-8?q?=20=D0=B0=D0=BF=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xml | 3 +- src/app/app-routing.module.ts | 4 +-- src/app/pages/chat-id/chat-id.page.html | 38 ++----------------------- src/app/pages/chat-id/chat-id.page.ts | 23 ++++++++------- src/app/pages/chats/chats.page.html | 2 +- src/app/pages/chats/chats.page.ts | 29 +++---------------- src/app/providers/api.service.ts | 2 +- src/app/providers/chat.service.ts | 10 +++---- src/app/providers/interfaces.ts | 3 +- 9 files changed, 32 insertions(+), 82 deletions(-) diff --git a/config.xml b/config.xml index 4dead05..fd53c47 100644 --- a/config.xml +++ b/config.xml @@ -90,8 +90,9 @@ - + + diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 29e8547..ce50532 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -16,8 +16,8 @@ const routes: Routes = [ { path: 'comments/:id', loadChildren: './pages/comments/comments.module#CommentsPageModule', canActivate: [LoginGuard] }, { path: 'user/:id', loadChildren: './pages/user/user.module#UserPageModule' }, { path: 'news/:id', loadChildren: './pages/news/news.module#NewsPageModule' }, - { path: 'chats', loadChildren: './pages/chats/chats.module#ChatsPageModule' }, - { path: 'chat-id/:id', loadChildren: './pages/chat-id/chat-id.module#ChatIdPageModule' }, + { path: 'chats', loadChildren: './pages/chats/chats.module#ChatsPageModule', canActivate: [LoginGuard] }, + { path: 'chat-id/:id', loadChildren: './pages/chat-id/chat-id.module#ChatIdPageModule', canActivate: [LoginGuard] }, ]; @NgModule({ imports: [RouterModule.forRoot(routes)], diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index ceb1b83..2ca48c6 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -1,6 +1,6 @@ - {{ chatinfo.name }} Онлайн {{online()}}/{{ chatinfo.users.length }} + {{ chatinfo.name }} @@ -11,14 +11,14 @@

- {{ msg.user.name }}   {{ msg.createdAt | date }} + {{ msg.user.name }}   {{ msg.createdAt | date:'dd.MM, HH:mm'}}

@@ -28,38 +28,6 @@
-
- -
-
-

- deissh   09:20 -

-
-
- -

Ну, тут будет не менее крутое сообщение. А так же текст который позволит сделать - сообщение подлинее!

-
-
-
-
- -
-
-

- deissh   09:20 -

-
-
- -

Ну, тут будет не менее крутое сообщение. А так же текст который позволит сделать - сообщение подлинее!

-
-
-
- -
diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index c7e7de9..d1635b6 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -4,6 +4,7 @@ import { LoadingController } from '@ionic/angular'; import { IChat, IMessage, IUserSelf } from 'src/app/providers/interfaces'; import { ChatService } from 'src/app/providers/chat.service'; import { Storage } from '@ionic/storage'; +import { UserService } from 'src/app/providers/user.service'; @Component({ selector: 'app-chat-id', @@ -17,7 +18,7 @@ export class ChatIdPage implements OnInit { public user: IUserSelf; public messages: IMessage[]; - private page: number = 0; + private page: number = 1; private attachments: any; /** @@ -31,7 +32,7 @@ export class ChatIdPage implements OnInit { private cs: ChatService, private route: ActivatedRoute, private router: Router, - private storage: Storage, + private us: UserService, private loadingController: LoadingController, ) { } @@ -42,12 +43,16 @@ export class ChatIdPage implements OnInit { duration: 5000 }); - this.user = await this.storage.get('user_local'); - await this.spiner.present(); await this.load(); } + public async update(event: any) { + this.load() + .then(() => event.target.complete()) + .catch(() => event.target.cansel()); + } + public async msgmenu(event: any) { console.log(this); } @@ -57,14 +62,10 @@ export class ChatIdPage implements OnInit { this.messages.push(msg); } - public online(): number { - const online = this.chatinfo.users.filter((u) => u.online !== '0'); - return online.length; - } - private async load() { - // this.messages = await this.cs.getMessages(this.id, this.page); - // this.chatinfo = await this.cs.get(this.id); + this.user = await this.us.getSelf(); + this.messages = (await this.cs.getMessages(this.id, this.page)).reverse(); + this.chatinfo = await this.cs.get(this.id); await this.spiner.dismiss(); } } diff --git a/src/app/pages/chats/chats.page.html b/src/app/pages/chats/chats.page.html index 776b73a..e80035b 100644 --- a/src/app/pages/chats/chats.page.html +++ b/src/app/pages/chats/chats.page.html @@ -27,7 +27,7 @@ {{ item.name }} -

{{ item.lastmessage.user.name }}: {{ item.lastmessage.body }}

+

{{ item.lastmessage.body }}

diff --git a/src/app/pages/chats/chats.page.ts b/src/app/pages/chats/chats.page.ts index 5250b8e..a8739f7 100644 --- a/src/app/pages/chats/chats.page.ts +++ b/src/app/pages/chats/chats.page.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { IChat } from 'src/app/providers/interfaces'; import { Router } from '@angular/router'; +import { ChatService } from 'src/app/providers/chat.service'; @Component({ selector: 'app-chats', @@ -12,7 +13,8 @@ export class ChatsPage implements OnInit { public chats: IChat[] = []; constructor( - private router: Router + private router: Router, + private cs: ChatService ) { } async ngOnInit() { @@ -30,29 +32,6 @@ export class ChatsPage implements OnInit { } private async load(): Promise { - this.chats = [ - { - id: '1', - name: 'Chat nomer odin', - picture: 'https://cdn.anibe.ru/avatars/5c533dbb889e940019ec1d9c/1551757027703', - users: [], - lastmessage: { - id: '12312312', - body: 'some text', - user: { - id: '12', - name: 'deissh', - online: '1', - badges: [], - picture: 'https://cdn.anibe.ru/avatars/5c533dbb889e940019ec1d9c/1551757027703', - role: 'admin' - }, - createdAt: '12.03.2019', - updatedAt: '04.04.2019', - }, - createdAt: '12.03.2019', - updatedAt: '04.04.2019', - } - ]; + this.chats = await this.cs.getAll(); } } diff --git a/src/app/providers/api.service.ts b/src/app/providers/api.service.ts index 3af9531..349ca26 100644 --- a/src/app/providers/api.service.ts +++ b/src/app/providers/api.service.ts @@ -32,7 +32,7 @@ export class API { * @description содержит ссылку на api * @type {string} */ - private baseURL = 'https://api.anibe.ru'; + private baseURL = 'http://127.0.0.1:8080'; /** * @private * @description тип содержимого ответа и запроса diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index bb79df5..3e34d9c 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -67,16 +67,16 @@ export class ChatService { public async createMessage( chat_id: string, body: string, - attachments?: { + attachments: { images: string[], links: string[], videos: string[], sticker: string - } + } = { images: [], links: [], videos: [], sticker: ''} ): Promise { this.token = await this.storage.get('token') || ''; - const res = await this.api.post(`/chats/${chat_id}`, { + const res = await this.api.post(`/messages/${chat_id}`, { body, attachments }, { @@ -92,10 +92,10 @@ export class ChatService { public async getMessages(id: string, page: number = 1): Promise { this.token = await this.storage.get('token') || ''; - const res = await this.api.get(`/chats/${id}?page=${page}`, { + const res = await this.api.get(`/messages/${id}?page=${page}`, { 'Authorization': 'Bearer ' + this.token }); - return JSON.parse(res.data); + return JSON.parse(res.data).rows; } } diff --git a/src/app/providers/interfaces.ts b/src/app/providers/interfaces.ts index 0bbc746..f184d25 100644 --- a/src/app/providers/interfaces.ts +++ b/src/app/providers/interfaces.ts @@ -102,7 +102,8 @@ export interface IChat { id: string; name: string; picture: string; - users: IUser[]; + users: string[]; + admin: string; lastmessage?: IMessage; createdAt: string; From 5bb523c13975d112fc8092510ceac4339110116c Mon Sep 17 00:00:00 2001 From: deissh Date: Fri, 5 Apr 2019 08:15:23 +0300 Subject: [PATCH 07/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=B0=D0=B2=D1=82=D0=BE=D1=81=D0=BA=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20+=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/chat-id/chat-id.page.html | 10 ++++----- src/app/pages/chat-id/chat-id.page.scss | 5 +++++ src/app/pages/chat-id/chat-id.page.ts | 27 ++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index 2ca48c6..ecd4d8c 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -6,7 +6,7 @@ -
+
- +

@@ -22,7 +22,7 @@

- +

{{ msg.body }}

@@ -36,10 +36,10 @@ - + - + diff --git a/src/app/pages/chat-id/chat-id.page.scss b/src/app/pages/chat-id/chat-id.page.scss index 516151d..71ffe35 100644 --- a/src/app/pages/chat-id/chat-id.page.scss +++ b/src/app/pages/chat-id/chat-id.page.scss @@ -19,6 +19,11 @@ ion-footer { padding: 5px; display: flex; + ion-button { + --padding-end: 0px; + --padding-start: 0px; + } + textarea { flex: 1; border: 0; diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index d1635b6..029e36f 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -1,9 +1,8 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { LoadingController } from '@ionic/angular'; +import { LoadingController, IonContent } from '@ionic/angular'; import { IChat, IMessage, IUserSelf } from 'src/app/providers/interfaces'; import { ChatService } from 'src/app/providers/chat.service'; -import { Storage } from '@ionic/storage'; import { UserService } from 'src/app/providers/user.service'; @Component({ @@ -18,6 +17,7 @@ export class ChatIdPage implements OnInit { public user: IUserSelf; public messages: IMessage[]; + @ViewChild(IonContent) contentArea: IonContent; private page: number = 1; private attachments: any; @@ -45,6 +45,8 @@ export class ChatIdPage implements OnInit { await this.spiner.present(); await this.load(); + + this.scrollToBottom(); } public async update(event: any) { @@ -57,9 +59,17 @@ export class ChatIdPage implements OnInit { console.log(this); } + public openUser(id: string): void { + this.router.navigateByUrl(`/user/${id}`); + } + public async send() { + if (!this.editorMsg) { + return; + } const msg = await this.cs.createMessage(this.id, this.editorMsg, this.attachments) this.messages.push(msg); + this.scrollToBottom(); } private async load() { @@ -68,4 +78,15 @@ export class ChatIdPage implements OnInit { this.chatinfo = await this.cs.get(this.id); await this.spiner.dismiss(); } + + /** + * @description Позволяет спускаться вниз + */ + private scrollToBottom() { + setTimeout(() => { + if (this.contentArea.scrollToBottom) { + this.contentArea.scrollToBottom(); + } + }, 0); + } } From f58f9aa3cb23f9d2ca17034c5c544145b44243d7 Mon Sep 17 00:00:00 2001 From: deissh Date: Fri, 5 Apr 2019 08:53:52 +0300 Subject: [PATCH 08/26] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app-routing.module.ts | 1 - src/app/pages/chat-id/chat-id.page.html | 22 ++++++++++++++-------- src/app/pages/chat-id/chat-id.page.ts | 17 +++++++++++++++-- src/app/tabs/tabs.page.html | 5 +++++ src/app/tabs/tabs.router.module.ts | 11 +++++++++++ 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index ce50532..724f454 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -16,7 +16,6 @@ const routes: Routes = [ { path: 'comments/:id', loadChildren: './pages/comments/comments.module#CommentsPageModule', canActivate: [LoginGuard] }, { path: 'user/:id', loadChildren: './pages/user/user.module#UserPageModule' }, { path: 'news/:id', loadChildren: './pages/news/news.module#NewsPageModule' }, - { path: 'chats', loadChildren: './pages/chats/chats.module#ChatsPageModule', canActivate: [LoginGuard] }, { path: 'chat-id/:id', loadChildren: './pages/chat-id/chat-id.module#ChatIdPageModule', canActivate: [LoginGuard] }, ]; @NgModule({ diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index ecd4d8c..3c1b405 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -1,6 +1,11 @@ - - {{ chatinfo.name }} + + + + + + + {{ chatinfo.name }} @@ -8,12 +13,13 @@
-
+ + + + + +
diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index 029e36f..341a168 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -45,8 +45,7 @@ export class ChatIdPage implements OnInit { await this.spiner.present(); await this.load(); - - this.scrollToBottom(); + this.scrollToBottom() } public async update(event: any) { @@ -55,10 +54,24 @@ export class ChatIdPage implements OnInit { .catch(() => event.target.cansel()); } + public async loadMore(event: any) { + if (this.page !== 1) { + this.page += 1; + } + this.load() + .then(() => event.target.complete()) + .then(() => this.scrollToBottom()) + .catch(() => event.target.cansel()); + } + public async msgmenu(event: any) { console.log(this); } + public async goback() { + + } + public openUser(id: string): void { this.router.navigateByUrl(`/user/${id}`); } diff --git a/src/app/tabs/tabs.page.html b/src/app/tabs/tabs.page.html index 489e882..a174fcc 100644 --- a/src/app/tabs/tabs.page.html +++ b/src/app/tabs/tabs.page.html @@ -12,6 +12,11 @@ Поиск + + + Чаты + + Уведомления diff --git a/src/app/tabs/tabs.router.module.ts b/src/app/tabs/tabs.router.module.ts index 4c0d2ba..8a283b3 100644 --- a/src/app/tabs/tabs.router.module.ts +++ b/src/app/tabs/tabs.router.module.ts @@ -58,6 +58,17 @@ const routes: Routes = [ path: '', redirectTo: '/tabs/tab1', pathMatch: 'full' + }, + { + path: 'chats', + children: [ + { + path: '', + loadChildren: '../pages/chats/chats.module#ChatsPageModule' + // component: ChatsPage + } + ], + canActivate: [LoginGuard] } ] }, From 6fb084a26718458641b82ebac9acc190b29e7cc4 Mon Sep 17 00:00:00 2001 From: deissh Date: Fri, 5 Apr 2019 11:26:38 +0300 Subject: [PATCH 09/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B7=D0=B0=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BA=D1=83?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE=D0=BA=D0=B5=D1=82=D0=B8?= =?UTF-8?q?=D0=BE=20+=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xml | 3 +- package-lock.json | 42 ++++++++-- package.json | 4 +- src/app/pages/chat-id/chat-id.page.html | 8 +- src/app/pages/chat-id/chat-id.page.scss | 6 ++ src/app/pages/chat-id/chat-id.page.ts | 8 +- src/app/providers/api.service.ts | 2 +- src/app/providers/chat.service.ts | 22 +++++ yarn.lock | 103 +++++++++++++++++++++--- 9 files changed, 167 insertions(+), 31 deletions(-) diff --git a/config.xml b/config.xml index fd53c47..2914817 100644 --- a/config.xml +++ b/config.xml @@ -90,9 +90,8 @@ - + - diff --git a/package-lock.json b/package-lock.json index a0b6342..0f9d604 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1103,6 +1103,12 @@ "integrity": "sha512-4GbNCDs98uHCT/OMv40qQC/OpoPbYn9XdXeTiFwHBBFO6eJhYEPUu2zDKirXSbHlvDV8oZ9l8EQ+HrEx/YS9DQ==", "dev": true }, + "@types/socket.io-client": { + "version": "1.4.32", + "resolved": "https://registry.npmjs.org/@types/socket.io-client/-/socket.io-client-1.4.32.tgz", + "integrity": "sha512-Vs55Kq8F+OWvy1RLA31rT+cAyemzgm0EWNeax6BWF8H7QiiOYMJIdcwSDdm5LVgfEkoepsWkS+40+WNb7BUMbg==", + "dev": true + }, "@webassemblyjs/ast": { "version": "1.7.10", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.7.10.tgz", @@ -1463,6 +1469,7 @@ "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", "dev": true, + "optional": true, "requires": { "delegates": "^1.0.0", "readable-stream": "^2.0.6" @@ -2730,7 +2737,8 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true + "dev": true, + "optional": true }, "constants-browserify": { "version": "1.0.0", @@ -8726,7 +8734,8 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", - "dev": true + "dev": true, + "optional": true }, "depd": { "version": "1.1.2", @@ -10344,6 +10353,7 @@ "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", "integrity": "sha1-XB+x8RdHcRTwYyoOtLcbPLD9MXE=", "dev": true, + "optional": true, "requires": { "graceful-fs": "^4.1.2", "inherits": "~2.0.0", @@ -10356,6 +10366,7 @@ "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", "dev": true, + "optional": true, "requires": { "aproba": "^1.0.3", "console-control-strings": "^1.0.0", @@ -10393,7 +10404,8 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz", "integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=", - "dev": true + "dev": true, + "optional": true }, "get-stream": { "version": "3.0.0", @@ -10637,7 +10649,8 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", - "dev": true + "dev": true, + "optional": true }, "has-value": { "version": "1.0.0", @@ -11349,7 +11362,8 @@ "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=", - "dev": true + "dev": true, + "optional": true }, "is-windows": { "version": "1.0.2", @@ -12006,6 +12020,7 @@ "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "dev": true, + "optional": true, "requires": { "graceful-fs": "^4.1.2", "parse-json": "^2.2.0", @@ -12018,7 +12033,8 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", - "dev": true + "dev": true, + "optional": true } } }, @@ -12346,7 +12362,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=", - "dev": true + "dev": true, + "optional": true }, "map-visit": { "version": "1.0.0", @@ -12978,6 +12995,7 @@ "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", "dev": true, + "optional": true, "requires": { "are-we-there-yet": "~1.1.2", "console-control-strings": "~1.1.0", @@ -14080,6 +14098,7 @@ "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", "dev": true, + "optional": true, "requires": { "load-json-file": "^1.0.0", "normalize-package-data": "^2.3.2", @@ -14091,6 +14110,7 @@ "resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz", "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", "dev": true, + "optional": true, "requires": { "graceful-fs": "^4.1.2", "pify": "^2.0.0", @@ -14101,7 +14121,8 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", - "dev": true + "dev": true, + "optional": true } } }, @@ -14110,6 +14131,7 @@ "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz", "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", "dev": true, + "optional": true, "requires": { "find-up": "^1.0.0", "read-pkg": "^1.0.0" @@ -14120,6 +14142,7 @@ "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", "dev": true, + "optional": true, "requires": { "path-exists": "^2.0.0", "pinkie-promise": "^2.0.0" @@ -14130,6 +14153,7 @@ "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", "dev": true, + "optional": true, "requires": { "pinkie-promise": "^2.0.0" } @@ -15409,6 +15433,7 @@ "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", "dev": true, + "optional": true, "requires": { "is-utf8": "^0.2.0" } @@ -16763,6 +16788,7 @@ "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", "dev": true, + "optional": true, "requires": { "string-width": "^1.0.2 || 2" } diff --git a/package.json b/package.json index 7f6705b..71c3ff8 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "core-js": "^2.5.4", "hammerjs": "^2.0.8", "rxjs": "~6.3.3", + "socket.io": "^2.2.0", "zone.js": "~0.8.26" }, "devDependencies": { @@ -64,6 +65,7 @@ "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.3", "@types/node": "~10.12.0", + "@types/socket.io-client": "^1.4.32", "codelyzer": "~4.5.0", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", @@ -99,4 +101,4 @@ "android" ] } -} \ No newline at end of file +} diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index 3c1b405..24798f1 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -1,8 +1,8 @@ - - + + {{ chatinfo.name }} @@ -31,6 +31,10 @@

{{ msg.body }}

+ +
+ +
diff --git a/src/app/pages/chat-id/chat-id.page.scss b/src/app/pages/chat-id/chat-id.page.scss index 71ffe35..64772b0 100644 --- a/src/app/pages/chat-id/chat-id.page.scss +++ b/src/app/pages/chat-id/chat-id.page.scss @@ -85,6 +85,12 @@ ion-footer { } } + .images { + img { + border-radius: 10px; + } + } + } } diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index 341a168..828a999 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -48,6 +48,10 @@ export class ChatIdPage implements OnInit { this.scrollToBottom() } + public goBack() { + this.router.navigateByUrl('/tabs/chats'); + } + public async update(event: any) { this.load() .then(() => event.target.complete()) @@ -68,10 +72,6 @@ export class ChatIdPage implements OnInit { console.log(this); } - public async goback() { - - } - public openUser(id: string): void { this.router.navigateByUrl(`/user/${id}`); } diff --git a/src/app/providers/api.service.ts b/src/app/providers/api.service.ts index 349ca26..ab204af 100644 --- a/src/app/providers/api.service.ts +++ b/src/app/providers/api.service.ts @@ -32,7 +32,7 @@ export class API { * @description содержит ссылку на api * @type {string} */ - private baseURL = 'http://127.0.0.1:8080'; + private baseURL = 'http://192.168.43.165:8080'; /** * @private * @description тип содержимого ответа и запроса diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index 3e34d9c..92abbba 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -3,6 +3,10 @@ import { API } from './api.service'; import { IPostFull, RequestParam, IPost, IComment, IChat, IMessage } from './interfaces'; import { Storage } from '@ionic/storage'; import { ToastController } from '@ionic/angular'; +import * as socketIo from 'socket.io-client'; +import { Observable } from 'rxjs'; + +const SERVER_URL = 'http://localhost:8080'; @Injectable({ providedIn: 'root' @@ -14,6 +18,7 @@ export class ChatService { private api: API; private token: string; private ready: Promise; + private socket: any; constructor( private storage: Storage, @@ -22,6 +27,23 @@ export class ChatService { this.api = new API({ }); } + public initSocket(): void { + this.socket = socketIo(SERVER_URL); + } + public send(message: IMessage): void { + this.socket.emit('message', message); + } + public onMessage(): Observable { + return new Observable((observer: { next: (arg0: IMessage) => void; }) => { + this.socket.on('message', (data: IMessage) => observer.next(data)); + }); + } + public onEvent(event: Event): Observable { + return new Observable((observer: { next: () => void; }) => { + this.socket.on(event, () => observer.next()); + }); + } + /** * Получить чат по его айди * @async diff --git a/yarn.lock b/yarn.lock index f96f4ff..8787a9c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2361,10 +2361,10 @@ cordova-lib@8.1.1: which "^1.3.1" xcode "^1.0.0" -cordova-plugin-advanced-http@^2.0.4: - version "2.0.6" - resolved "https://registry.yarnpkg.com/cordova-plugin-advanced-http/-/cordova-plugin-advanced-http-2.0.6.tgz#48c0b3281e1264fb3f92252e1aa39201949ffa22" - integrity sha512-MWPnl0P1z0Bv7O1s9di78tLXq8i3V8TwKqDB7H+583yOnnByTHLd9Fq5senpt37Ifs3c6x3NIgTTR+XBbYGiFg== +cordova-plugin-advanced-http@^2.0.6: + version "2.0.7" + resolved "https://registry.yarnpkg.com/cordova-plugin-advanced-http/-/cordova-plugin-advanced-http-2.0.7.tgz#07b1fdf320f8694eb5cb61de78eeac69e49c0735" + integrity sha512-dG7Vsjc64QPna1jFyqmd+q+Hjj9Cpl4Mz8D2ItKfzgAD3as1U9sTbtdUcaw2AZD/qsK1bkLcRdogTmtKFe8L+g== cordova-plugin-android-permissions@^1.0.0: version "1.0.0" @@ -2391,10 +2391,10 @@ cordova-plugin-ionic-keyboard@^2.1.3: resolved "https://registry.yarnpkg.com/cordova-plugin-ionic-keyboard/-/cordova-plugin-ionic-keyboard-2.1.3.tgz#6b050d5b7cb4393d5758b55f45a46372f25178fe" integrity sha512-6ucQ6FdlLdBm8kJfFnzozmBTjru/0xekHP/dAhjoCZggkGRlgs8TsUJFkxa/bV+qi7Dlo50JjmpE4UMWAO+aOQ== -cordova-plugin-ionic-webview@^2.3.3: - version "2.4.0" - resolved "https://registry.yarnpkg.com/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-2.4.0.tgz#dad20977ebc3a8602bfadddd3dbcc67ac5b7a0db" - integrity sha512-8KQdg0AO0t4pkq/azb14KKLUar3arz+wO7OI7/rbmnL7gt03pfk3Icn66v5wBy8hM2lb8CLmGbdfTcN0f0seiA== +cordova-plugin-ionic-webview@^2.4.0: + version "2.4.1" + resolved "https://registry.yarnpkg.com/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-2.4.1.tgz#102d258c58e83f540fecf6bd010d53cb3c9cc084" + integrity sha512-//Ul3P6LbsglY7NaeSgttcR2KRIJ9XAbUCRWlH5SlZE0JZ6Y5hCyS5VX9Wqct04nwJ+rEF3fHv74h/JyRr/BoA== cordova-plugin-splashscreen@^5.0.2: version "5.0.2" @@ -2406,10 +2406,10 @@ cordova-plugin-statusbar@^2.4.2: resolved "https://registry.yarnpkg.com/cordova-plugin-statusbar/-/cordova-plugin-statusbar-2.4.2.tgz#fc1fbdc0d8d7033a7e8e1f1f7ff167ac9bd4faf6" integrity sha1-/B+9wNjXAzp+jh8ff/FnrJvU+vY= -cordova-plugin-telerik-imagepicker@2.2.3: - version "2.2.3" - resolved "https://registry.yarnpkg.com/cordova-plugin-telerik-imagepicker/-/cordova-plugin-telerik-imagepicker-2.2.3.tgz#797652190b40f9bd1b11f363a9f69315ae60cdc9" - integrity sha512-jR8SvH5tou2C5iueqFlH/eU5ZvED4hSLbrymrPfX9NFt+/GuejIRc4Q1pxosdESXJ8xLwZADaGTxgs0e5/IG0g== +cordova-plugin-telerik-imagepicker@^2.2.3: + version "2.3.2" + resolved "https://registry.yarnpkg.com/cordova-plugin-telerik-imagepicker/-/cordova-plugin-telerik-imagepicker-2.3.2.tgz#cd95b23292893f0ca4e5a22b871a664e27a9673c" + integrity sha512-YF98mdjv4jtSvY/nyPj2AQpqSLb2HsulHtQFkznjGkcU9gLeNLQutc48gejsFxL7hMKctQHnIHFi1mj20awqJg== cordova-plugin-whitelist@^1.3.3: version "1.3.3" @@ -2659,7 +2659,7 @@ debug@^3.1.0, debug@^3.2.5: dependencies: ms "^2.1.1" -debug@^4.0.0: +debug@^4.0.0, debug@~4.1.0: version "4.1.1" resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== @@ -3049,6 +3049,23 @@ engine.io-client@~3.2.0: xmlhttprequest-ssl "~1.5.4" yeast "0.1.2" +engine.io-client@~3.3.1: + version "3.3.2" + resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-3.3.2.tgz#04e068798d75beda14375a264bb3d742d7bc33aa" + integrity sha512-y0CPINnhMvPuwtqXfsGuWE8BB66+B6wTtCofQDRecMQPYX3MYUZXFNKDhdrSe3EVjgOu4V3rxdeqN/Tr91IgbQ== + dependencies: + component-emitter "1.2.1" + component-inherit "0.0.3" + debug "~3.1.0" + engine.io-parser "~2.1.1" + has-cors "1.1.0" + indexof "0.0.1" + parseqs "0.0.5" + parseuri "0.0.5" + ws "~6.1.0" + xmlhttprequest-ssl "~1.5.4" + yeast "0.1.2" + engine.io-parser@~2.1.0, engine.io-parser@~2.1.1: version "2.1.3" resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-2.1.3.tgz#757ab970fbf2dfb32c7b74b033216d5739ef79a6" @@ -3072,6 +3089,18 @@ engine.io@~3.2.0: engine.io-parser "~2.1.0" ws "~3.3.1" +engine.io@~3.3.1: + version "3.3.2" + resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-3.3.2.tgz#18cbc8b6f36e9461c5c0f81df2b830de16058a59" + integrity sha512-AsaA9KG7cWPXWHp5FvHdDWY3AMWeZ8x+2pUVLcn71qE5AtAzgGbxuclOytygskw8XGmiQafTmnI9Bix3uihu2w== + dependencies: + accepts "~1.3.4" + base64id "1.0.0" + cookie "0.3.1" + debug "~3.1.0" + engine.io-parser "~2.1.0" + ws "~6.1.0" + enhanced-resolve@4.1.0, enhanced-resolve@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.0.tgz#41c7e0bfdfe74ac1ffe1e57ad6a5c6c9f3742a7f" @@ -7807,6 +7836,26 @@ socket.io-client@2.1.1: socket.io-parser "~3.2.0" to-array "0.1.4" +socket.io-client@2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-2.2.0.tgz#84e73ee3c43d5020ccc1a258faeeb9aec2723af7" + integrity sha512-56ZrkTDbdTLmBIyfFYesgOxsjcLnwAKoN4CiPyTVkMQj3zTUh0QAx3GbvIvLpFEOvQWu92yyWICxB0u7wkVbYA== + dependencies: + backo2 "1.0.2" + base64-arraybuffer "0.1.5" + component-bind "1.0.0" + component-emitter "1.2.1" + debug "~3.1.0" + engine.io-client "~3.3.1" + has-binary2 "~1.0.2" + has-cors "1.1.0" + indexof "0.0.1" + object-component "0.0.3" + parseqs "0.0.5" + parseuri "0.0.5" + socket.io-parser "~3.3.0" + to-array "0.1.4" + socket.io-parser@~3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.2.0.tgz#e7c6228b6aa1f814e6148aea325b51aa9499e077" @@ -7816,6 +7865,15 @@ socket.io-parser@~3.2.0: debug "~3.1.0" isarray "2.0.1" +socket.io-parser@~3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.3.0.tgz#2b52a96a509fdf31440ba40fed6094c7d4f1262f" + integrity sha512-hczmV6bDgdaEbVqhAeVMM/jfUfzuEZHsQg6eOmLgJht6G3mPKMxYm75w2+qhAQZ+4X+1+ATZ+QFKeOZD5riHng== + dependencies: + component-emitter "1.2.1" + debug "~3.1.0" + isarray "2.0.1" + socket.io@2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-2.1.1.tgz#a069c5feabee3e6b214a75b40ce0652e1cfb9980" @@ -7828,6 +7886,18 @@ socket.io@2.1.1: socket.io-client "2.1.1" socket.io-parser "~3.2.0" +socket.io@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-2.2.0.tgz#f0f633161ef6712c972b307598ecd08c9b1b4d5b" + integrity sha512-wxXrIuZ8AILcn+f1B4ez4hJTPG24iNgxBBDaJfT6MsyOhVYiTXWexGoPkd87ktJG8kQEcL/NBvRi64+9k4Kc0w== + dependencies: + debug "~4.1.0" + engine.io "~3.3.1" + has-binary2 "~1.0.2" + socket.io-adapter "~1.1.0" + socket.io-client "2.2.0" + socket.io-parser "~3.3.0" + sockjs-client@1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.3.0.tgz#12fc9d6cb663da5739d3dc5fb6e8687da95cb177" @@ -9191,6 +9261,13 @@ ws@~3.3.1: safe-buffer "~5.1.0" ultron "~1.1.0" +ws@~6.1.0: + version "6.1.4" + resolved "https://registry.yarnpkg.com/ws/-/ws-6.1.4.tgz#5b5c8800afab925e94ccb29d153c8d02c1776ef9" + integrity sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA== + dependencies: + async-limiter "~1.0.0" + xcode@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/xcode/-/xcode-1.1.0.tgz#9fcb63f417a9af377bfb743a5c22afce4e1da964" From 8a6d5e031d42e9302db649919e2ffed16705654a Mon Sep 17 00:00:00 2001 From: deissh Date: Fri, 5 Apr 2019 11:41:57 +0300 Subject: [PATCH 10/26] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/app/pages/chat-id/chat-id.page.ts | 28 +++++++++++++++------------ yarn.lock | 5 +++++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 71c3ff8..c7ffaed 100644 --- a/package.json +++ b/package.json @@ -101,4 +101,4 @@ "android" ] } -} +} \ No newline at end of file diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index 828a999..4970510 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -15,10 +15,10 @@ export class ChatIdPage implements OnInit { private id: string; public chatinfo: IChat; public user: IUserSelf; - public messages: IMessage[]; + public messages: IMessage[] = []; @ViewChild(IonContent) contentArea: IonContent; - private page: number = 1; + private page = 0; private attachments: any; /** @@ -45,7 +45,7 @@ export class ChatIdPage implements OnInit { await this.spiner.present(); await this.load(); - this.scrollToBottom() + this.scrollToBottom(); } public goBack() { @@ -59,13 +59,11 @@ export class ChatIdPage implements OnInit { } public async loadMore(event: any) { - if (this.page !== 1) { - this.page += 1; - } - this.load() - .then(() => event.target.complete()) - .then(() => this.scrollToBottom()) - .catch(() => event.target.cansel()); + event.target.complete() + // this.load() + // .then(() => event.target.complete()) + // .then(() => this.scrollToBottom()) + // .catch(() => event.target.cansel()); } public async msgmenu(event: any) { @@ -80,15 +78,21 @@ export class ChatIdPage implements OnInit { if (!this.editorMsg) { return; } - const msg = await this.cs.createMessage(this.id, this.editorMsg, this.attachments) + const msg = await this.cs.createMessage(this.id, this.editorMsg, this.attachments); this.messages.push(msg); this.scrollToBottom(); } private async load() { + this.page += 1; this.user = await this.us.getSelf(); - this.messages = (await this.cs.getMessages(this.id, this.page)).reverse(); + const messages = await this.cs.getMessages(this.id, this.page); this.chatinfo = await this.cs.get(this.id); + + messages.forEach((msg: IMessage) => { + this.messages.unshift(msg); + }); + await this.spiner.dismiss(); } diff --git a/yarn.lock b/yarn.lock index 8787a9c..fdfe85c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -483,6 +483,11 @@ resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.14.tgz#0b20a2370e6b1b8322c9c3dfcaa409e6c7c0c0a9" integrity sha512-4GbNCDs98uHCT/OMv40qQC/OpoPbYn9XdXeTiFwHBBFO6eJhYEPUu2zDKirXSbHlvDV8oZ9l8EQ+HrEx/YS9DQ== +"@types/socket.io-client@^1.4.32": + version "1.4.32" + resolved "https://registry.yarnpkg.com/@types/socket.io-client/-/socket.io-client-1.4.32.tgz#988a65a0386c274b1c22a55377fab6a30789ac14" + integrity sha512-Vs55Kq8F+OWvy1RLA31rT+cAyemzgm0EWNeax6BWF8H7QiiOYMJIdcwSDdm5LVgfEkoepsWkS+40+WNb7BUMbg== + "@webassemblyjs/ast@1.7.10": version "1.7.10" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.7.10.tgz#0cfc61d61286240b72fc522cb755613699eea40a" From 58b21b4b18df8c61a193ba9c66925350c2f0c6ed Mon Sep 17 00:00:00 2001 From: deissh Date: Fri, 5 Apr 2019 11:42:31 +0300 Subject: [PATCH 11/26] fix lint --- src/app/pages/chat-id/chat-id.page.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index 4970510..515d47a 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -59,7 +59,7 @@ export class ChatIdPage implements OnInit { } public async loadMore(event: any) { - event.target.complete() + event.target.complete(); // this.load() // .then(() => event.target.complete()) // .then(() => this.scrollToBottom()) From 91e1cfb32d7b02948e1109c4e779c608b57b2e9a Mon Sep 17 00:00:00 2001 From: deissh Date: Tue, 9 Apr 2019 14:41:52 +0300 Subject: [PATCH 12/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xml | 2 +- src/app/pages/chat-id/chat-id.page.ts | 11 +++++++--- src/app/providers/api.service.ts | 2 +- src/app/providers/chat.service.ts | 29 +++++++++++++++++++++------ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/config.xml b/config.xml index 2914817..2a057ae 100644 --- a/config.xml +++ b/config.xml @@ -90,7 +90,7 @@ - + diff --git a/src/app/pages/chat-id/chat-id.page.ts b/src/app/pages/chat-id/chat-id.page.ts index 515d47a..db295e0 100644 --- a/src/app/pages/chat-id/chat-id.page.ts +++ b/src/app/pages/chat-id/chat-id.page.ts @@ -46,6 +46,12 @@ export class ChatIdPage implements OnInit { await this.spiner.present(); await this.load(); this.scrollToBottom(); + + await this.cs.initSocket(); + this.cs.onMessage().subscribe((msg: IMessage) => { + this.messages.push(msg); + this.scrollToBottom(); + }); } public goBack() { @@ -78,9 +84,8 @@ export class ChatIdPage implements OnInit { if (!this.editorMsg) { return; } - const msg = await this.cs.createMessage(this.id, this.editorMsg, this.attachments); - this.messages.push(msg); - this.scrollToBottom(); + await this.cs.send(this.id, this.editorMsg, this.attachments); + this.editorMsg = ''; } private async load() { diff --git a/src/app/providers/api.service.ts b/src/app/providers/api.service.ts index ab204af..349ca26 100644 --- a/src/app/providers/api.service.ts +++ b/src/app/providers/api.service.ts @@ -32,7 +32,7 @@ export class API { * @description содержит ссылку на api * @type {string} */ - private baseURL = 'http://192.168.43.165:8080'; + private baseURL = 'http://127.0.0.1:8080'; /** * @private * @description тип содержимого ответа и запроса diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index 92abbba..efd2fd7 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -6,7 +6,7 @@ import { ToastController } from '@ionic/angular'; import * as socketIo from 'socket.io-client'; import { Observable } from 'rxjs'; -const SERVER_URL = 'http://localhost:8080'; +const SERVER_URL = 'http://127.0.0.1:2300'; @Injectable({ providedIn: 'root' @@ -27,15 +27,32 @@ export class ChatService { this.api = new API({ }); } - public initSocket(): void { - this.socket = socketIo(SERVER_URL); + public async initSocket(): Promise { + this.socket = socketIo(SERVER_URL, { + query: { + token: await this.storage.get('token') || '' + } + }); } - public send(message: IMessage): void { - this.socket.emit('message', message); + public send( + chat_id: string, + body: string, + attachments: { + images: string[], + links: string[], + videos: string[], + sticker: string + } = { images: [], links: [], videos: [], sticker: ''} + ): void { + this.socket.emit('new_message', { + chat_id, + body, + attachments + }); } public onMessage(): Observable { return new Observable((observer: { next: (arg0: IMessage) => void; }) => { - this.socket.on('message', (data: IMessage) => observer.next(data)); + this.socket.on('new_message', (data: IMessage) => observer.next(data)); }); } public onEvent(event: Event): Observable { From 0e06473ccd11a421601a7bac2a33234e3e6c5523 Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 14 Apr 2019 14:15:02 +0300 Subject: [PATCH 13/26] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=20=D0=BA=20ws=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/tab1/tab1.page.ts | 2 +- src/app/providers/api.service.ts | 2 +- src/app/providers/chat.service.spec.ts | 12 ------------ src/app/providers/chat.service.ts | 3 ++- 4 files changed, 4 insertions(+), 15 deletions(-) delete mode 100644 src/app/providers/chat.service.spec.ts diff --git a/src/app/pages/tab1/tab1.page.ts b/src/app/pages/tab1/tab1.page.ts index cd5a9aa..e293e0c 100644 --- a/src/app/pages/tab1/tab1.page.ts +++ b/src/app/pages/tab1/tab1.page.ts @@ -103,7 +103,7 @@ export class Tab1Page implements OnInit { } } if (this.storage.get('token')) { - this.recommendations = await this.user.getOffer(); + this.recommendations = await this.user.getRecommendations(); } } diff --git a/src/app/providers/api.service.ts b/src/app/providers/api.service.ts index 349ca26..3af9531 100644 --- a/src/app/providers/api.service.ts +++ b/src/app/providers/api.service.ts @@ -32,7 +32,7 @@ export class API { * @description содержит ссылку на api * @type {string} */ - private baseURL = 'http://127.0.0.1:8080'; + private baseURL = 'https://api.anibe.ru'; /** * @private * @description тип содержимого ответа и запроса diff --git a/src/app/providers/chat.service.spec.ts b/src/app/providers/chat.service.spec.ts deleted file mode 100644 index f9d1b52..0000000 --- a/src/app/providers/chat.service.spec.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { ChatService } from './chat.service'; - -describe('ChatService', () => { - beforeEach(() => TestBed.configureTestingModule({})); - - it('should be created', () => { - const service: ChatService = TestBed.get(ChatService); - expect(service).toBeTruthy(); - }); -}); diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index efd2fd7..7be7d72 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -6,7 +6,7 @@ import { ToastController } from '@ionic/angular'; import * as socketIo from 'socket.io-client'; import { Observable } from 'rxjs'; -const SERVER_URL = 'http://127.0.0.1:2300'; +const SERVER_URL = 'https://api.anibe.ru'; @Injectable({ providedIn: 'root' @@ -29,6 +29,7 @@ export class ChatService { public async initSocket(): Promise { this.socket = socketIo(SERVER_URL, { + // path: '/ws/', query: { token: await this.storage.get('token') || '' } From c06d831e211472cb586c37af478bd8b2f315d8db Mon Sep 17 00:00:00 2001 From: deissh Date: Tue, 16 Apr 2019 06:54:48 +0300 Subject: [PATCH 14/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D1=87?= =?UTF-8?q?=D0=B0=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/providers/chat.service.ts | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index 7be7d72..a38692d 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -138,4 +138,56 @@ export class ChatService { return JSON.parse(res.data).rows; } + + /** + * Отправляет сообщение в чат + * @param {string} name имя нового чата + * @param {string} picture картинка нового чата + */ + public async createChat( + name: string, + picture: string + ): Promise { + this.token = await this.storage.get('token') || ''; + + const res = await this.api.post(`/chats`, { + name, + picture + }, { + 'Authorization': 'Bearer ' + this.token + }); + return JSON.parse(res.data); + } + + /** + * Удаляет чат по его айди (только если админ или создатель) + * @param {string} chat_id id чата + */ + public async deleteChat(chat_id: string) { + this.token = await this.storage.get('token') || ''; + + const res = await this.api.delete(`/chats`, { + 'Authorization': 'Bearer ' + this.token + }); + return JSON.parse(res.data); + } + + /** + * ВЫполняет действия внутри чата, например добавить нового пользователя + * @param chat_id id чата + * @param action действие (add, ban) + */ + public async actionsChat( + chat_id: string, + action: string, + ): Promise { + this.token = await this.storage.get('token') || ''; + + const res = await this.api.post(`/chats/${chat_id}/actions`, { + action + }, { + 'Authorization': 'Bearer ' + this.token + }); + return JSON.parse(res.data); + } } From 79143bbd5ecd20a04f1a8541d866b639d751c484 Mon Sep 17 00:00:00 2001 From: deissh Date: Tue, 16 Apr 2019 07:04:51 +0300 Subject: [PATCH 15/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B7=D0=B0=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BA=D1=83?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=87=D0=B0=D1=82=D0=B0=20+=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=B3=D0=BB=D0=B0=D1=88=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/chat-create/chat-create.module.ts | 26 ++++++++++++++++++ .../pages/chat-create/chat-create.page.html | 12 +++++++++ .../pages/chat-create/chat-create.page.scss | 0 .../chat-create/chat-create.page.spec.ts | 27 +++++++++++++++++++ src/app/pages/chat-create/chat-create.page.ts | 15 +++++++++++ src/app/pages/chats/chats.module.ts | 4 ++- src/app/pages/chats/chats.page.html | 5 ++++ src/app/pages/chats/chats.page.ts | 13 ++++++++- 8 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 src/app/pages/chat-create/chat-create.module.ts create mode 100644 src/app/pages/chat-create/chat-create.page.html create mode 100644 src/app/pages/chat-create/chat-create.page.scss create mode 100644 src/app/pages/chat-create/chat-create.page.spec.ts create mode 100644 src/app/pages/chat-create/chat-create.page.ts diff --git a/src/app/pages/chat-create/chat-create.module.ts b/src/app/pages/chat-create/chat-create.module.ts new file mode 100644 index 0000000..7e73ff0 --- /dev/null +++ b/src/app/pages/chat-create/chat-create.module.ts @@ -0,0 +1,26 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; +import { Routes, RouterModule } from '@angular/router'; + +import { IonicModule } from '@ionic/angular'; + +import { ChatCreatePage } from './chat-create.page'; + +const routes: Routes = [ + { + path: '', + component: ChatCreatePage + } +]; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + RouterModule.forChild(routes) + ], + declarations: [ChatCreatePage] +}) +export class ChatCreatePageModule {} diff --git a/src/app/pages/chat-create/chat-create.page.html b/src/app/pages/chat-create/chat-create.page.html new file mode 100644 index 0000000..00ad46d --- /dev/null +++ b/src/app/pages/chat-create/chat-create.page.html @@ -0,0 +1,12 @@ + + + Создание нового чата + + + + + + Название + + + diff --git a/src/app/pages/chat-create/chat-create.page.scss b/src/app/pages/chat-create/chat-create.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/chat-create/chat-create.page.spec.ts b/src/app/pages/chat-create/chat-create.page.spec.ts new file mode 100644 index 0000000..41da6de --- /dev/null +++ b/src/app/pages/chat-create/chat-create.page.spec.ts @@ -0,0 +1,27 @@ +import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ChatCreatePage } from './chat-create.page'; + +describe('ChatCreatePage', () => { + let component: ChatCreatePage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ChatCreatePage ], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ChatCreatePage); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/chat-create/chat-create.page.ts b/src/app/pages/chat-create/chat-create.page.ts new file mode 100644 index 0000000..522a48e --- /dev/null +++ b/src/app/pages/chat-create/chat-create.page.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-chat-create', + templateUrl: './chat-create.page.html', + styleUrls: ['./chat-create.page.scss'], +}) +export class ChatCreatePage implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/pages/chats/chats.module.ts b/src/app/pages/chats/chats.module.ts index 558df83..ab52530 100644 --- a/src/app/pages/chats/chats.module.ts +++ b/src/app/pages/chats/chats.module.ts @@ -6,6 +6,7 @@ import { Routes, RouterModule } from '@angular/router'; import { IonicModule } from '@ionic/angular'; import { ChatsPage } from './chats.page'; +import { ChatCreatePage } from '../chat-create/chat-create.page'; const routes: Routes = [ { @@ -21,6 +22,7 @@ const routes: Routes = [ IonicModule, RouterModule.forChild(routes) ], - declarations: [ChatsPage] + declarations: [ChatsPage, ChatCreatePage], + entryComponents: [ChatCreatePage] }) export class ChatsPageModule {} diff --git a/src/app/pages/chats/chats.page.html b/src/app/pages/chats/chats.page.html index e80035b..9ec75f7 100644 --- a/src/app/pages/chats/chats.page.html +++ b/src/app/pages/chats/chats.page.html @@ -1,5 +1,10 @@ + + + + + Активные чаты diff --git a/src/app/pages/chats/chats.page.ts b/src/app/pages/chats/chats.page.ts index a8739f7..8386806 100644 --- a/src/app/pages/chats/chats.page.ts +++ b/src/app/pages/chats/chats.page.ts @@ -2,6 +2,8 @@ import { Component, OnInit } from '@angular/core'; import { IChat } from 'src/app/providers/interfaces'; import { Router } from '@angular/router'; import { ChatService } from 'src/app/providers/chat.service'; +import { ModalController } from '@ionic/angular'; +import { ChatCreatePage } from '../chat-create/chat-create.page'; @Component({ selector: 'app-chats', @@ -14,13 +16,22 @@ export class ChatsPage implements OnInit { constructor( private router: Router, - private cs: ChatService + private cs: ChatService, + private modalController: ModalController, ) { } async ngOnInit() { await this.load(); } + public async createChat() { + const modal = await this.modalController.create({ + component: ChatCreatePage, + componentProps: { value: 123 } + }); + return await modal.present(); + } + public async update(event: any) { this.load() .then(() => event.target.complete()) From 7f33c79195e30212984ba876811348820a188058 Mon Sep 17 00:00:00 2001 From: deissh Date: Wed, 17 Apr 2019 10:04:20 +0300 Subject: [PATCH 16/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=87=D0=B0=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xml | 2 +- .../pages/chat-create/chat-create.page.html | 42 ++++++++++-- src/app/pages/chat-create/chat-create.page.ts | 66 ++++++++++++++++++- src/app/pages/chats/chats.page.html | 34 +++++----- src/app/pages/chats/chats.page.ts | 30 +++++++-- src/app/providers/api.service.ts | 3 +- src/app/providers/chat.service.ts | 35 ++++++++-- src/app/providers/user.service.ts | 4 +- 8 files changed, 176 insertions(+), 40 deletions(-) diff --git a/config.xml b/config.xml index 2a057ae..4dead05 100644 --- a/config.xml +++ b/config.xml @@ -90,7 +90,7 @@ - + diff --git a/src/app/pages/chat-create/chat-create.page.html b/src/app/pages/chat-create/chat-create.page.html index 00ad46d..e62a5e9 100644 --- a/src/app/pages/chat-create/chat-create.page.html +++ b/src/app/pages/chat-create/chat-create.page.html @@ -1,12 +1,42 @@ - Создание нового чата + + + Сохранить + + + {{title}} - - - Название - - + + + + + + Загрузить + + + + Название: + + + + + + + Пользователи + + + + + + + {{ user.name }} + + + Удалить + + + diff --git a/src/app/pages/chat-create/chat-create.page.ts b/src/app/pages/chat-create/chat-create.page.ts index 522a48e..b70ae8d 100644 --- a/src/app/pages/chat-create/chat-create.page.ts +++ b/src/app/pages/chat-create/chat-create.page.ts @@ -1,4 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, Input } from '@angular/core'; +import { ModalController, ToastController } from '@ionic/angular'; +import { IChat, IUser } from 'src/app/providers/interfaces'; +import { ImagePicker } from '@ionic-native/image-picker/ngx'; +import { ChatService } from 'src/app/providers/chat.service'; +import { UserService } from 'src/app/providers/user.service'; @Component({ selector: 'app-chat-create', @@ -6,10 +11,67 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./chat-create.page.scss'], }) export class ChatCreatePage implements OnInit { + @Input() public info?: IChat; + @Input() public title: string; + public name: string; + public picture = 'https://avatars.mds.yandex.net/get-pdb/1532603/ac56ac6f-b354-4c5b-bf06-533910e0fae8/s1200'; - constructor() { } + public users: IUser[] = []; + public selectedUsers: IUser[] = []; + + constructor( + private modalController: ModalController, + private imagePicker: ImagePicker, + private toast: ToastController, + private chat: ChatService, + private user: UserService + ) { } ngOnInit() { + if (this.info) { + this.name = this.info.name; + this.picture = this.info.picture; + + this.info.users.forEach(async (id: string) => { + this.users.push(await this.user.get(id)); + }); + } + } + + public async save() { + if (this.info) { + await this.chat.editChat(this.info.id, this.info.name, this.info.picture) + } else { + await this.chat.createChat(this.name, this.picture); + } + + this.modalController.dismiss(); } + public async pickImage() { + if (!await this.imagePicker.hasReadPermission()) { + await this.imagePicker.requestReadPermission(); + + (await this.toast.create({ + message: 'Попробуйте снова', + duration: 2000 + })).present(); + return; + } + const result = await this.imagePicker.getPictures({ + maximumImagesCount: 1 + }); + + // this.picture = await this.user.updateAvatar(result[0]); + + (await this.toast.create({ + message: 'Ваша аватарка успешно загружена и скоро обновиться', + duration: 5000 + })).present(); + } + + public async remove(id: string) { + await this.chat.actionsChat(this.info.id, id, 'ban'); + this.users = this.users.filter((v: any) => v.id !== id); + } } diff --git a/src/app/pages/chats/chats.page.html b/src/app/pages/chats/chats.page.html index 9ec75f7..d5947d9 100644 --- a/src/app/pages/chats/chats.page.html +++ b/src/app/pages/chats/chats.page.html @@ -12,28 +12,26 @@ - + - - - - - - - {{ item.name }} - -

{{ item.lastmessage.body }}

-
-
+ + + + + + + {{ item.name }} + + + Изменить + Удалить + + +
diff --git a/src/app/pages/chats/chats.page.ts b/src/app/pages/chats/chats.page.ts index 8386806..0cd93ff 100644 --- a/src/app/pages/chats/chats.page.ts +++ b/src/app/pages/chats/chats.page.ts @@ -1,9 +1,10 @@ -import { Component, OnInit } from '@angular/core'; -import { IChat } from 'src/app/providers/interfaces'; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { IChat, IUserSelf } from 'src/app/providers/interfaces'; import { Router } from '@angular/router'; import { ChatService } from 'src/app/providers/chat.service'; import { ModalController } from '@ionic/angular'; import { ChatCreatePage } from '../chat-create/chat-create.page'; +import { Storage } from '@ionic/storage'; @Component({ selector: 'app-chats', @@ -13,23 +14,34 @@ import { ChatCreatePage } from '../chat-create/chat-create.page'; export class ChatsPage implements OnInit { public chats: IChat[] = []; + @ViewChild('myList') private slidingList: any; + + private userlocal: IUserSelf; constructor( private router: Router, private cs: ChatService, private modalController: ModalController, + private storage: Storage ) { } async ngOnInit() { await this.load(); + + this.userlocal = await this.storage.get('user_local'); } - public async createChat() { + public async createChat(chatinfo?: IChat) { const modal = await this.modalController.create({ component: ChatCreatePage, - componentProps: { value: 123 } + componentProps: { + title: chatinfo ? 'Редактирование' : 'Создание нового чата', + info: chatinfo + } }); - return await modal.present(); + await modal.present(); + await modal.onDidDismiss(); + await this.load(); } public async update(event: any) { @@ -42,7 +54,15 @@ export class ChatsPage implements OnInit { this.router.navigateByUrl(`/chat-id/${id}`); } + public async remove(id: string) { + await this.cs.deleteChat(id); + await this.load(); + } + private async load(): Promise { + if (this.chats === []) { + await this.slidingList.closeOpened(); + } this.chats = await this.cs.getAll(); } } diff --git a/src/app/providers/api.service.ts b/src/app/providers/api.service.ts index 3af9531..c2a4187 100644 --- a/src/app/providers/api.service.ts +++ b/src/app/providers/api.service.ts @@ -32,7 +32,8 @@ export class API { * @description содержит ссылку на api * @type {string} */ - private baseURL = 'https://api.anibe.ru'; + // private baseURL = 'https://api.anibe.ru'; + private baseURL = 'http://127.0.0.1:8080'; /** * @private * @description тип содержимого ответа и запроса diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index a38692d..8402a5d 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -6,7 +6,8 @@ import { ToastController } from '@ionic/angular'; import * as socketIo from 'socket.io-client'; import { Observable } from 'rxjs'; -const SERVER_URL = 'https://api.anibe.ru'; +// const SERVER_URL = 'https://api.anibe.ru'; +const SERVER_URL = 'http://127.0.0.1:2300'; @Injectable({ providedIn: 'root' @@ -166,10 +167,10 @@ export class ChatService { public async deleteChat(chat_id: string) { this.token = await this.storage.get('token') || ''; - const res = await this.api.delete(`/chats`, { + await this.api.delete(`/chats/${chat_id}`, { 'Authorization': 'Bearer ' + this.token }); - return JSON.parse(res.data); + return true; } /** @@ -179,12 +180,36 @@ export class ChatService { */ public async actionsChat( chat_id: string, + user_id: string, action: string, ): Promise { this.token = await this.storage.get('token') || ''; - const res = await this.api.post(`/chats/${chat_id}/actions`, { - action + await this.api.post(`/chats/${chat_id}/actions`, { + action, + user_id + }, { + 'Authorization': 'Bearer ' + this.token + }); + return true; + } + + /** + * Изменяет картинку и название чата + * @param chat_id id чата + * @param name название + * @param picture картинка + */ + public async editChat( + chat_id: string, + name: string, + picture: string + ): Promise { + this.token = await this.storage.get('token') || ''; + + const res = await this.api.patch(`/chats/${chat_id}`, { + name, + picture }, { 'Authorization': 'Bearer ' + this.token }); diff --git a/src/app/providers/user.service.ts b/src/app/providers/user.service.ts index 64e572d..0783f77 100644 --- a/src/app/providers/user.service.ts +++ b/src/app/providers/user.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { API } from './api.service'; import { Storage } from '@ionic/storage'; -import { INotif, IPost } from './interfaces'; +import { INotif, IPost, IUser } from './interfaces'; @Injectable({ providedIn: 'root' @@ -77,7 +77,7 @@ export class UserService { * @description получить информацию о пользователе * @param id uuid пользователя */ - public async get(id: string) { + public async get(id: string): Promise { await this.setToken(); const url = `/users/${id}`; From 793f2caa172f3625c53d81a92a6ab58a28dcbb52 Mon Sep 17 00:00:00 2001 From: deissh Date: Fri, 19 Apr 2019 20:52:32 +0300 Subject: [PATCH 17/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D1=80=D0=B8=D0=B3=D0=BB=D0=B0=D1=88=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B2=20=D1=87=D0=B0=D1=82=D1=8B=20+=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/chat-create/chat-create.page.html | 15 ++++++++++--- src/app/pages/chat-create/chat-create.page.ts | 18 +++++++++++++++ src/app/pages/chats/chats.page.html | 22 ++++++++++++++----- src/app/providers/chat.service.ts | 2 +- src/app/providers/user.service.ts | 14 ++++++++++++ 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/app/pages/chat-create/chat-create.page.html b/src/app/pages/chat-create/chat-create.page.html index e62a5e9..7cfd734 100644 --- a/src/app/pages/chat-create/chat-create.page.html +++ b/src/app/pages/chat-create/chat-create.page.html @@ -11,22 +11,31 @@ - + Загрузить - Название: + Название чата - + Пользователи + + + Пригласить: + + + + + + diff --git a/src/app/pages/chat-create/chat-create.page.ts b/src/app/pages/chat-create/chat-create.page.ts index b70ae8d..3c3c619 100644 --- a/src/app/pages/chat-create/chat-create.page.ts +++ b/src/app/pages/chat-create/chat-create.page.ts @@ -18,6 +18,7 @@ export class ChatCreatePage implements OnInit { public users: IUser[] = []; public selectedUsers: IUser[] = []; + public newinvite = ''; constructor( private modalController: ModalController, @@ -44,6 +45,7 @@ export class ChatCreatePage implements OnInit { } else { await this.chat.createChat(this.name, this.picture); } + console.log(this); this.modalController.dismiss(); } @@ -74,4 +76,20 @@ export class ChatCreatePage implements OnInit { await this.chat.actionsChat(this.info.id, id, 'ban'); this.users = this.users.filter((v: any) => v.id !== id); } + + public async invite() { + try { + const user = await this.user.getName(this.newinvite); + await this.chat.actionsChat(this.info.id, user.id, 'add'); + + this.users.push(user); + } catch (e) { + console.error(e); + + (await this.toast.create({ + message: 'Пользователь с таким ником не найден!', + duration: 5000 + })).present(); + } + } } diff --git a/src/app/pages/chats/chats.page.html b/src/app/pages/chats/chats.page.html index d5947d9..6868557 100644 --- a/src/app/pages/chats/chats.page.html +++ b/src/app/pages/chats/chats.page.html @@ -20,17 +20,29 @@ - - - + + + - + {{ item.name }} + + + Изменить + Удалить + + + diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index 8402a5d..cdf2f7f 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -207,7 +207,7 @@ export class ChatService { ): Promise { this.token = await this.storage.get('token') || ''; - const res = await this.api.patch(`/chats/${chat_id}`, { + const res = await this.api.put(`/chats/${chat_id}`, { name, picture }, { diff --git a/src/app/providers/user.service.ts b/src/app/providers/user.service.ts index 0783f77..9a656a0 100644 --- a/src/app/providers/user.service.ts +++ b/src/app/providers/user.service.ts @@ -87,6 +87,20 @@ export class UserService { return JSON.parse(res.data); } + /** + * @description получить информацию о пользователе по его нику + * @param name + */ + public async getName(name: string): Promise { + await this.setToken(); + const url = `/users/name/${name}`; + + const res = await this.api.get(url, { + 'Authorization': 'Bearer ' + this.token + }); + return JSON.parse(res.data); + } + /** * @description обновить информацию о пользователе * @param body новая информация о пользователе From 159862135fd6c2314682d09497ba3c3a63089a42 Mon Sep 17 00:00:00 2001 From: deissh Date: Fri, 19 Apr 2019 21:00:45 +0300 Subject: [PATCH 18/26] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=83?= =?UTF-8?q?=20=D1=87=D0=B0=D1=82=D0=B0=20+=20=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/chat-create/chat-create.page.ts | 2 +- src/app/pages/chat-id/chat-id.page.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/pages/chat-create/chat-create.page.ts b/src/app/pages/chat-create/chat-create.page.ts index 3c3c619..7768f0b 100644 --- a/src/app/pages/chat-create/chat-create.page.ts +++ b/src/app/pages/chat-create/chat-create.page.ts @@ -67,7 +67,7 @@ export class ChatCreatePage implements OnInit { // this.picture = await this.user.updateAvatar(result[0]); (await this.toast.create({ - message: 'Ваша аватарка успешно загружена и скоро обновиться', + message: 'Ваша аватарка успешно загружена и скоро обновиться (наверно)', duration: 5000 })).present(); } diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index 24798f1..9c700dd 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -13,7 +13,7 @@
- + From 18c87da0cb2a2847ad456c248f10c4afab9f5dfb Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 21 Apr 2019 07:39:23 +0300 Subject: [PATCH 19/26] =?UTF-8?q?=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D1=83=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=87=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=20=D0=B2=D0=B8=D0=B4=D0=B8=D1=82=20=D1=82=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/chat-create/chat-create.module.ts | 26 ------------------- src/app/pages/chats/chats.page.html | 2 +- src/app/providers/api.service.ts | 4 +-- src/app/providers/chat.service.ts | 4 +-- 4 files changed, 5 insertions(+), 31 deletions(-) delete mode 100644 src/app/pages/chat-create/chat-create.module.ts diff --git a/src/app/pages/chat-create/chat-create.module.ts b/src/app/pages/chat-create/chat-create.module.ts deleted file mode 100644 index 7e73ff0..0000000 --- a/src/app/pages/chat-create/chat-create.module.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; -import { Routes, RouterModule } from '@angular/router'; - -import { IonicModule } from '@ionic/angular'; - -import { ChatCreatePage } from './chat-create.page'; - -const routes: Routes = [ - { - path: '', - component: ChatCreatePage - } -]; - -@NgModule({ - imports: [ - CommonModule, - FormsModule, - IonicModule, - RouterModule.forChild(routes) - ], - declarations: [ChatCreatePage] -}) -export class ChatCreatePageModule {} diff --git a/src/app/pages/chats/chats.page.html b/src/app/pages/chats/chats.page.html index 6868557..11a4f61 100644 --- a/src/app/pages/chats/chats.page.html +++ b/src/app/pages/chats/chats.page.html @@ -28,7 +28,7 @@ {{ item.name }} - + Изменить Удалить diff --git a/src/app/providers/api.service.ts b/src/app/providers/api.service.ts index c2a4187..916649b 100644 --- a/src/app/providers/api.service.ts +++ b/src/app/providers/api.service.ts @@ -32,8 +32,8 @@ export class API { * @description содержит ссылку на api * @type {string} */ - // private baseURL = 'https://api.anibe.ru'; - private baseURL = 'http://127.0.0.1:8080'; + private baseURL = 'https://api.anibe.ru'; + // private baseURL = 'http://127.0.0.1:8080'; /** * @private * @description тип содержимого ответа и запроса diff --git a/src/app/providers/chat.service.ts b/src/app/providers/chat.service.ts index cdf2f7f..d26e727 100644 --- a/src/app/providers/chat.service.ts +++ b/src/app/providers/chat.service.ts @@ -6,8 +6,8 @@ import { ToastController } from '@ionic/angular'; import * as socketIo from 'socket.io-client'; import { Observable } from 'rxjs'; -// const SERVER_URL = 'https://api.anibe.ru'; -const SERVER_URL = 'http://127.0.0.1:2300'; +const SERVER_URL = 'https://api.anibe.ru'; +// const SERVER_URL = 'http://127.0.0.1:2300'; @Injectable({ providedIn: 'root' From dfd2becc6951b5ed09692056430affdbe1d229ab Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 28 Apr 2019 10:33:21 +0300 Subject: [PATCH 20/26] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20+?= =?UTF-8?q?=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BF=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=B5=D1=84=D0=BE=D0=BB=D1=82=D1=83=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D1=83=20+=20?= =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA?= =?UTF-8?q?=D1=83=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D0=B8=D0=BD=D0=BA=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D1=87=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xml | 3 ++- src/app/pages/chat-id/chat-id.page.html | 4 ++-- src/app/pages/reader/reader.page.ts | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config.xml b/config.xml index 4dead05..b008745 100644 --- a/config.xml +++ b/config.xml @@ -90,8 +90,9 @@ - + + diff --git a/src/app/pages/chat-id/chat-id.page.html b/src/app/pages/chat-id/chat-id.page.html index 9c700dd..116df2f 100644 --- a/src/app/pages/chat-id/chat-id.page.html +++ b/src/app/pages/chat-id/chat-id.page.html @@ -46,9 +46,9 @@ - + diff --git a/src/app/pages/reader/reader.page.ts b/src/app/pages/reader/reader.page.ts index 5c8391c..20dc9c2 100644 --- a/src/app/pages/reader/reader.page.ts +++ b/src/app/pages/reader/reader.page.ts @@ -60,6 +60,9 @@ export class ReaderPage implements OnInit { await this.storage.ready(); this.preload = (await this.storage.get('image_preload')); + if (this.preload === undefined) { + this.preload = true; + } this.info = await this.post.get(this.route.snapshot.paramMap.get('id')); From 497d1eee8f758a8ae83e3d23a2f25ee83b8de88d Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 28 Apr 2019 11:57:38 +0300 Subject: [PATCH 21/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BC=D0=BE=D0=B4=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5?= =?UTF-8?q?=20=D0=BE=D0=BA=D0=BD=D0=BE=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B5?= =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.xml | 2 +- src/app/modal/report/report.module.ts | 18 +++++++ src/app/modal/report/report.page.html | 34 ++++++++++++ src/app/modal/report/report.page.scss | 0 src/app/modal/report/report.page.spec.ts | 27 ++++++++++ src/app/modal/report/report.page.ts | 65 +++++++++++++++++++++++ src/app/pages/comments/comments.module.ts | 4 +- src/app/pages/comments/comments.page.ts | 34 ++++-------- src/app/pages/info/info.module.ts | 5 +- src/app/pages/info/info.page.ts | 37 ++++--------- 10 files changed, 174 insertions(+), 52 deletions(-) create mode 100644 src/app/modal/report/report.module.ts create mode 100644 src/app/modal/report/report.page.html create mode 100644 src/app/modal/report/report.page.scss create mode 100644 src/app/modal/report/report.page.spec.ts create mode 100644 src/app/modal/report/report.page.ts diff --git a/config.xml b/config.xml index b008745..3b68b2e 100644 --- a/config.xml +++ b/config.xml @@ -92,7 +92,7 @@ - + diff --git a/src/app/modal/report/report.module.ts b/src/app/modal/report/report.module.ts new file mode 100644 index 0000000..6e05c53 --- /dev/null +++ b/src/app/modal/report/report.module.ts @@ -0,0 +1,18 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { ReportPage } from 'src/app/modal/report/report.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + ], + declarations: [ReportPage], + entryComponents: [ReportPage] +}) +export class ReportPageModule {} diff --git a/src/app/modal/report/report.page.html b/src/app/modal/report/report.page.html new file mode 100644 index 0000000..8bf6cd1 --- /dev/null +++ b/src/app/modal/report/report.page.html @@ -0,0 +1,34 @@ + + + + + + + + Создание репорта + + + Отправить + + + + + + + + Название + + + + + Описание проблемы + + + + + diff --git a/src/app/modal/report/report.page.scss b/src/app/modal/report/report.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/modal/report/report.page.spec.ts b/src/app/modal/report/report.page.spec.ts new file mode 100644 index 0000000..8c7d2f1 --- /dev/null +++ b/src/app/modal/report/report.page.spec.ts @@ -0,0 +1,27 @@ +import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ReportPage } from './report.page'; + +describe('ReportPage', () => { + let component: ReportPage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ReportPage ], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ReportPage); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/modal/report/report.page.ts b/src/app/modal/report/report.page.ts new file mode 100644 index 0000000..e5b8561 --- /dev/null +++ b/src/app/modal/report/report.page.ts @@ -0,0 +1,65 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { Storage } from '@ionic/storage'; +import { ToastController, ModalController } from '@ionic/angular'; +import { ReportService } from 'src/app/providers/report.service'; +import { Firebase } from '@ionic-native/firebase/ngx'; +import { Form } from '@angular/forms'; + +@Component({ + selector: 'app-report', + templateUrl: './report.page.html', + styleUrls: ['./report.page.scss'], +}) +export class ReportPage implements OnInit { + // привязка к посту, пользователю + @Input() public post_id?: string; + @Input() public user_id?: string; + + public name: string; + public body: string; + + public reportForm: Form; + + constructor( + private modalController: ModalController, + private storage: Storage, + private toast: ToastController, + private rep: ReportService, + private firebase: Firebase + ) { } + + ngOnInit() { + } + + public async close() { + await this.modalController.dismiss({ action: 'closed' }); + } + + public async report() { + const user_local = await this.storage.get('user_local'); + try { + await this.rep.send({ + name: this.name, + body: this.body, + post_id: this.post_id, + user_id: this.user_id, + authod_id: user_local.id || '' + }); + + (await this.toast.create({ + message: 'Спасибо за репорт!', + duration: 5000 + })).present(); + this.modalController.dismiss({ action: 'sended' }); + } catch (e) { + // логируем в консоль браузера + console.error(e); + // логируем в фаербейс + await this.firebase.logError(e); + (await this.toast.create({ + message: 'Ошибка при отправке, попробуйте чуть позже', + duration: 5000 + })).present(); + } + } +} diff --git a/src/app/pages/comments/comments.module.ts b/src/app/pages/comments/comments.module.ts index c7bf342..9e4c29c 100644 --- a/src/app/pages/comments/comments.module.ts +++ b/src/app/pages/comments/comments.module.ts @@ -6,6 +6,7 @@ import { Routes, RouterModule } from '@angular/router'; import { IonicModule } from '@ionic/angular'; import { CommentsPage } from './comments.page'; +import { ReportPageModule } from 'src/app/modal/report/report.module'; const routes: Routes = [ { @@ -19,7 +20,8 @@ const routes: Routes = [ CommonModule, FormsModule, IonicModule, - RouterModule.forChild(routes) + RouterModule.forChild(routes), + ReportPageModule ], declarations: [CommentsPage] }) diff --git a/src/app/pages/comments/comments.page.ts b/src/app/pages/comments/comments.page.ts index c85c5f5..5440cde 100644 --- a/src/app/pages/comments/comments.page.ts +++ b/src/app/pages/comments/comments.page.ts @@ -4,8 +4,9 @@ import { IComment, IPost } from 'src/app/providers/interfaces'; import { ActivatedRoute, Router } from '@angular/router'; import { Storage } from '@ionic/storage'; import { Firebase } from '@ionic-native/firebase/ngx'; -import { ToastController } from '@ionic/angular'; +import { ToastController, ModalController } from '@ionic/angular'; import { ReportService } from 'src/app/providers/report.service'; +import { ReportPage } from 'src/app/modal/report/report.page'; @Component({ selector: 'app-comments', @@ -31,6 +32,7 @@ export class CommentsPage implements OnInit { private storage: Storage, private firebase: Firebase, private toast: ToastController, + private modalController: ModalController ) { } ngOnInit() { @@ -95,28 +97,14 @@ export class CommentsPage implements OnInit { } public async report(item: IComment) { - try { - await this.rep.send({ - body: 'comment', - post_id: this.id, - user_id: item.user.id, - authod_id: this.local_user.id - }); - - (await this.toast.create({ - message: 'Спасибо за репорт!', - duration: 5000 - })).present(); - } catch (e) { - // логируем в консоль браузера - console.error(e); - // логируем в фаербейс - await this.firebase.logError(e); - (await this.toast.create({ - message: 'Ошибка при отправке, попробуйте чуть позже', - duration: 5000 - })).present(); - } + const modal = await this.modalController.create({ + component: ReportPage, + componentProps: { + post_id: this.id + } + }); + await modal.present(); + await modal.onDidDismiss(); } private async load() { diff --git a/src/app/pages/info/info.module.ts b/src/app/pages/info/info.module.ts index d51eda1..69eae74 100644 --- a/src/app/pages/info/info.module.ts +++ b/src/app/pages/info/info.module.ts @@ -6,6 +6,8 @@ import { Routes, RouterModule } from '@angular/router'; import { IonicModule } from '@ionic/angular'; import { InfoPage } from './info.page'; +import { ReportPage } from 'src/app/modal/report/report.page'; +import { ReportPageModule } from 'src/app/modal/report/report.module'; const routes: Routes = [ { @@ -19,7 +21,8 @@ const routes: Routes = [ CommonModule, FormsModule, IonicModule, - RouterModule.forChild(routes) + RouterModule.forChild(routes), + ReportPageModule ], declarations: [InfoPage] }) diff --git a/src/app/pages/info/info.page.ts b/src/app/pages/info/info.page.ts index 3000e12..9dc115b 100644 --- a/src/app/pages/info/info.page.ts +++ b/src/app/pages/info/info.page.ts @@ -1,12 +1,12 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { LoadingController, ModalController, PopoverController, ActionSheetController, ToastController } from '@ionic/angular'; +import { LoadingController, ModalController, ActionSheetController } from '@ionic/angular'; import { IPostFull } from 'src/app/providers/interfaces'; import { PostService } from 'src/app/providers/post.service'; import { Firebase } from '@ionic-native/firebase/ngx'; import { Storage } from '@ionic/storage'; import { UserService } from 'src/app/providers/user.service'; -import { ReportService } from 'src/app/providers/report.service'; +import { ReportPage } from 'src/app/modal/report/report.page'; @Component({ selector: 'app-info', @@ -29,8 +29,7 @@ export class InfoPage implements OnInit { private user: UserService, private storage: Storage, private asc: ActionSheetController, - private toast: ToastController, - private rep: ReportService, + private modalController: ModalController, private firebase: Firebase ) {} @@ -116,27 +115,13 @@ export class InfoPage implements OnInit { } public async report() { - const user_local = await this.storage.get('user_local'); - try { - await this.rep.send({ - body: 'manga', - post_id: this.id, - authod_id: user_local.id || '' - }); - - (await this.toast.create({ - message: 'Спасибо за репорт!', - duration: 5000 - })).present(); - } catch (e) { - // логируем в консоль браузера - console.error(e); - // логируем в фаербейс - await this.firebase.logError(e); - (await this.toast.create({ - message: 'Ошибка при отправке, попробуйте чуть позже', - duration: 5000 - })).present(); - } + const modal = await this.modalController.create({ + component: ReportPage, + componentProps: { + post_id: this.id + } + }); + await modal.present(); + await modal.onDidDismiss(); } } From 0c6f6cad5eaef446b79c58293f19f88ab553ffa3 Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 28 Apr 2019 13:11:29 +0300 Subject: [PATCH 22/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20virtual-scroller=20=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=20=D0=B4=D0=B8=D0=B7=D0=B0=D0=B9=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search-results/search-results.page.html | 25 +++++++++++++++- .../search-results/search-results.page.scss | 12 ++++++++ .../search-results/search-results.page.ts | 29 ++++++++++--------- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/app/pages/search-results/search-results.page.html b/src/app/pages/search-results/search-results.page.html index 9a5c68b..9280de9 100644 --- a/src/app/pages/search-results/search-results.page.html +++ b/src/app/pages/search-results/search-results.page.html @@ -5,7 +5,8 @@ - + + + + + + + + + + + {{ item.name }} + +

{{ item.annotation }}

+ +

{{ item.genre.join(', ') }}

+
+
+
+
+ + + +
diff --git a/src/app/pages/search-results/search-results.page.scss b/src/app/pages/search-results/search-results.page.scss index e69de29..d6715ec 100644 --- a/src/app/pages/search-results/search-results.page.scss +++ b/src/app/pages/search-results/search-results.page.scss @@ -0,0 +1,12 @@ +.scroller { + .post { + .cover { + width: 150px; + padding-right: var(--padding-start); + + img { + border-radius: 5px; + } + } + } +} diff --git a/src/app/pages/search-results/search-results.page.ts b/src/app/pages/search-results/search-results.page.ts index cfabbba..dcf1206 100644 --- a/src/app/pages/search-results/search-results.page.ts +++ b/src/app/pages/search-results/search-results.page.ts @@ -1,6 +1,6 @@ // tslint:disable:max-line-length -import { Component, OnInit } from '@angular/core'; -import { ModalController } from '@ionic/angular'; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { ModalController, IonVirtualScroll } from '@ionic/angular'; import { SearchParamsPage } from '../search-params/search-params.page'; import { Router } from '@angular/router'; @@ -15,14 +15,15 @@ import { Storage } from '@ionic/storage'; styleUrls: ['./search-results.page.scss'], }) export class SearchResultsPage implements OnInit { - // используется для переключения вида отображения данных - private mode: boolean; - - public result: IPost[] = []; private query = null; private page = 0; private activegenres: string[] = []; + // virtualScroll + public render: any[] = []; + + @ViewChild('scroller') private scroller: IonVirtualScroll; + constructor( private modalController: ModalController, private router: Router, @@ -47,11 +48,11 @@ export class SearchResultsPage implements OnInit { } this.activegenres = result.data.activegenres; - this.result = []; + this.render = []; this.page = 0; if (this.query !== '') { - this.result = []; + this.render = []; await this.load(this.query); } else { await this.load(null); @@ -94,14 +95,15 @@ export class SearchResultsPage implements OnInit { custom: (this.activegenres.length !== 0) ? `&genre=${this.activegenres.join(',')}` : '' }); if (temp.length === 0 && this.page === 1) { - this.result = []; + this.render = []; this.page = 0; return; } else { - temp.forEach(i => { - this.result.push(i); - }); + temp.forEach((i: IPost) => this.render.push(i)); } + + // this.render = this.result; + this.scroller.checkEnd(); } /** @@ -112,7 +114,7 @@ export class SearchResultsPage implements OnInit { this.query = event.target.value; this.page = 0; - this.result = []; + this.render = []; console.log(event.target.value); if (this.query !== '') { @@ -131,5 +133,6 @@ export class SearchResultsPage implements OnInit { public loadNewPage(event: any) { this.load(); event.target.complete(); + console.log(this); } } From 9a635b073a70cd889a46f5cb8fca92d867fb6f6d Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 28 Apr 2019 13:38:28 +0300 Subject: [PATCH 23/26] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B2=D0=B5=D1=80=D1=81=D1=82=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BC=D0=B0=D0=BB=D0=B5=D0=BD=D1=8C=D0=BA=D0=B8?= =?UTF-8?q?=D1=85=20=D1=8D=D0=BA=D1=80=D0=B0=D0=BD=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/search-results/search-results.page.html | 2 +- src/app/pages/search-results/search-results.page.scss | 1 + src/app/pages/tab1/tab1.page.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/pages/search-results/search-results.page.html b/src/app/pages/search-results/search-results.page.html index 9280de9..9f518c2 100644 --- a/src/app/pages/search-results/search-results.page.html +++ b/src/app/pages/search-results/search-results.page.html @@ -20,7 +20,7 @@ - + diff --git a/src/app/pages/search-results/search-results.page.scss b/src/app/pages/search-results/search-results.page.scss index d6715ec..5be46f2 100644 --- a/src/app/pages/search-results/search-results.page.scss +++ b/src/app/pages/search-results/search-results.page.scss @@ -2,6 +2,7 @@ .post { .cover { width: 150px; + height: 200px; padding-right: var(--padding-start); img { diff --git a/src/app/pages/tab1/tab1.page.ts b/src/app/pages/tab1/tab1.page.ts index e293e0c..cd5a9aa 100644 --- a/src/app/pages/tab1/tab1.page.ts +++ b/src/app/pages/tab1/tab1.page.ts @@ -103,7 +103,7 @@ export class Tab1Page implements OnInit { } } if (this.storage.get('token')) { - this.recommendations = await this.user.getRecommendations(); + this.recommendations = await this.user.getOffer(); } } From 3b08cd50b13b9aa6aacc9e0ce9cf4b04958eedd3 Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 28 Apr 2019 13:55:38 +0300 Subject: [PATCH 24/26] fix lint --- config.xml | 3 +-- src/app/pages/chat-create/chat-create.page.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/config.xml b/config.xml index 3b68b2e..2914817 100644 --- a/config.xml +++ b/config.xml @@ -90,9 +90,8 @@ - + - diff --git a/src/app/pages/chat-create/chat-create.page.ts b/src/app/pages/chat-create/chat-create.page.ts index 7768f0b..9714b25 100644 --- a/src/app/pages/chat-create/chat-create.page.ts +++ b/src/app/pages/chat-create/chat-create.page.ts @@ -41,7 +41,7 @@ export class ChatCreatePage implements OnInit { public async save() { if (this.info) { - await this.chat.editChat(this.info.id, this.info.name, this.info.picture) + await this.chat.editChat(this.info.id, this.info.name, this.info.picture); } else { await this.chat.createChat(this.name, this.picture); } From 98d1a419e218dc8a8d7f7b5aecc36d441fef5a6b Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 28 Apr 2019 14:04:29 +0300 Subject: [PATCH 25/26] Update config.yml --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index ade525d..188f34c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,6 +15,7 @@ jobs: steps: - checkout + - run: chmod -R 777 * - restore_cache: keys: - v1-dependencies-{{ checksum "package.json" }} From 3423258bbe9ebbec0ef869c0ed5ab0f3c0dc1e57 Mon Sep 17 00:00:00 2001 From: deissh Date: Sun, 28 Apr 2019 14:13:38 +0300 Subject: [PATCH 26/26] Update config.yml --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 188f34c..ff35dbf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,6 @@ jobs: - restore_cache: keys: - v1-dependencies-{{ checksum "package.json" }} - - v1-dependencies- - run: yarn install - save_cache: paths: @@ -37,7 +36,6 @@ jobs: - restore_cache: keys: - v1-dependencies-{{ checksum "package.json" }} - - v1-dependencies- - run: npm install