From 4d68e5082d8102a61479ab585fa18b72a55a1fe2 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Thu, 17 May 2018 21:54:14 +0200 Subject: [PATCH] Replace momentjs with pipes from ngx-moment and factor it out to its own component --- package.json | 1 + src/app/app.module.ts | 4 +++ .../event-tiles/event-tile.component.base.ts | 10 ++----- .../message/message.component.html | 2 +- .../state/create/create.component.html | 2 +- .../state/member/member.component.html | 22 +++++++-------- .../state/name/name.component.html | 4 +-- .../state/topic/topic.component.html | 4 +-- .../timestamp/timestamp.component.html | 1 + .../elements/timestamp/timestamp.component.ts | 27 +++++++++++++++++++ 10 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 src/app/elements/timestamp/timestamp.component.html create mode 100644 src/app/elements/timestamp/timestamp.component.ts diff --git a/package.json b/package.json index c7425f7..0fe670d 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "zone.js": "^0.8.20" }, "dependencies": { + "ngx-moment": "^2.0.0", "url-parse": "^1.2.0" } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e3bf4cc..8b87d21 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -27,6 +27,8 @@ import { ToasterModule } from "angular2-toaster"; import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; import { BootstrapModalModule } from "ngx-modialog/plugins/bootstrap"; import { ModalModule } from "ngx-modialog"; +import { MomentModule } from 'ngx-moment'; +import { TimestampComponent } from "./elements/timestamp/timestamp.component"; import { LocatorService } from "./services/locator.service"; import { LandingComponent } from "./views/landing/landing.component"; import { SpinnerComponent } from "./elements/spinner/spinner.component"; @@ -94,11 +96,13 @@ const SHOWDOWN_CONVERTER = new showdown.Converter(); ModalModule.forRoot(), BootstrapModalModule, PerfectScrollbarModule, + MomentModule, ], declarations: [ AppComponent, LandingComponent, SpinnerComponent, + TimestampComponent, LoggedInComponent, LoginComponent, RoomListComponent, diff --git a/src/app/elements/event-tiles/event-tile.component.base.ts b/src/app/elements/event-tiles/event-tile.component.base.ts index c659b90..2415149 100644 --- a/src/app/elements/event-tiles/event-tile.component.base.ts +++ b/src/app/elements/event-tiles/event-tile.component.base.ts @@ -21,8 +21,6 @@ import { Room } from "../../models/matrix/dto/room"; import { RoomTimelineEvent } from "../../views/room/room.component"; import { RoomEvent } from "../../models/matrix/events/room/room-event"; import { RoomMemberEvent } from "../../models/matrix/events/room/state/m.room.member"; -import { MOMENT_FULL_TIMESTAMP_FORMAT } from "../../app.module"; -import moment = require("moment"); export abstract class EventTileComponentBase { @Input() timelineEvent: RoomTimelineEvent; @@ -44,11 +42,7 @@ export abstract class EventTileComponentBase { return this.room.getMemberEvent(this.event.sender); } - public get timestamp(): string { - return moment(this.event.origin_server_ts).fromNow(); - } - - public get fullTimestamp(): string { - return moment(this.event.origin_server_ts).format(MOMENT_FULL_TIMESTAMP_FORMAT); + public get timestamp(): number { + return this.event.origin_server_ts / 1000; } } \ No newline at end of file diff --git a/src/app/elements/event-tiles/message/message.component.html b/src/app/elements/event-tiles/message/message.component.html index 959a626..02b84da 100644 --- a/src/app/elements/event-tiles/message/message.component.html +++ b/src/app/elements/event-tiles/message/message.component.html @@ -27,7 +27,7 @@
{{ senderDisplayName }} - {{ timestamp }} +
diff --git a/src/app/elements/event-tiles/state/create/create.component.html b/src/app/elements/event-tiles/state/create/create.component.html index 31fd759..a72dcd9 100644 --- a/src/app/elements/event-tiles/state/create/create.component.html +++ b/src/app/elements/event-tiles/state/create/create.component.html @@ -20,5 +20,5 @@ created the room - {{ timestamp }} + \ No newline at end of file diff --git a/src/app/elements/event-tiles/state/member/member.component.html b/src/app/elements/event-tiles/state/member/member.component.html index 5e06a8f..5453ea1 100644 --- a/src/app/elements/event-tiles/state/member/member.component.html +++ b/src/app/elements/event-tiles/state/member/member.component.html @@ -30,7 +30,7 @@ [forcedAvatarUrl]="target.content.avatar_url" > - {{ timestamp }} + @@ -47,7 +47,7 @@ [forcedAvatarUrl]="target.content.avatar_url" > - {{ timestamp }} + @@ -64,7 +64,7 @@ [forcedAvatarUrl]="target.content.avatar_url" > - {{ timestamp }} + @@ -72,7 +72,7 @@ joined the room - {{ timestamp }} + @@ -80,7 +80,7 @@ left the room - {{ timestamp }} + @@ -93,7 +93,7 @@ for "{{ target.content.reason }}" - {{ timestamp }} + @@ -106,7 +106,7 @@ for "{{ target.content.reason }}" - {{ timestamp }} + @@ -115,7 +115,7 @@ lifted the ban on - {{ timestamp }} + @@ -125,7 +125,7 @@ to the room - {{ timestamp }} + @@ -133,7 +133,7 @@ declined the invite - {{ timestamp }} + @@ -141,6 +141,6 @@ had their membership updated - {{ timestamp }} + diff --git a/src/app/elements/event-tiles/state/name/name.component.html b/src/app/elements/event-tiles/state/name/name.component.html index 44fa68a..ee42510 100644 --- a/src/app/elements/event-tiles/state/name/name.component.html +++ b/src/app/elements/event-tiles/state/name/name.component.html @@ -20,11 +20,11 @@ changed the room name to "{{ event.content.name }}" - {{ timestamp }} +
removed the room name - {{ timestamp }} +
\ No newline at end of file diff --git a/src/app/elements/event-tiles/state/topic/topic.component.html b/src/app/elements/event-tiles/state/topic/topic.component.html index 5407ab5..657a93f 100644 --- a/src/app/elements/event-tiles/state/topic/topic.component.html +++ b/src/app/elements/event-tiles/state/topic/topic.component.html @@ -20,11 +20,11 @@ changed the room topic to "{{ event.content.topic }}" - {{ timestamp }} +
removed the room's topic - {{ timestamp }} +
\ No newline at end of file diff --git a/src/app/elements/timestamp/timestamp.component.html b/src/app/elements/timestamp/timestamp.component.html new file mode 100644 index 0000000..f55adbf --- /dev/null +++ b/src/app/elements/timestamp/timestamp.component.html @@ -0,0 +1 @@ +{{(timestamp | amFromUnix) | amTimeAgo }} \ No newline at end of file diff --git a/src/app/elements/timestamp/timestamp.component.ts b/src/app/elements/timestamp/timestamp.component.ts new file mode 100644 index 0000000..5de8866 --- /dev/null +++ b/src/app/elements/timestamp/timestamp.component.ts @@ -0,0 +1,27 @@ +/* + * Evelium - A matrix client + * Copyright (C) 2018 Marcel Radzio + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import { Component, Input } from "@angular/core"; + +@Component({ + selector: "my-timestamp", + templateUrl: "./timestamp.component.html", +}) +export class TimestampComponent { + @Input() timestamp: number; +}