Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit ddd3952

Browse files
committed
Can now edit thread
1 parent 6ff3129 commit ddd3952

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

client/app/discussion/app-thread/app-thread.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ng-container *ngIf="thread$ | async as thread">
22
<div class="app-primary-header">
33
<mat-icon class="app-nav-back-icon" routerLink="/discussion">keyboard_arrow_left</mat-icon>
4-
<h1>{{ thread.title }}</h1>
4+
<h1>Thread</h1>
55
</div>
66

77
<thread [thread]="thread"></thread>

client/components/messaging/messaging.service.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,22 @@ export class MessagingService {
5050
*/
5151
updateThread(thread: Thread): Observable<Thread> {
5252
return this.httpClient.patch<Thread>(`/api/threads/${thread._id}`, [
53-
{ op: 'replace', path: '/title', value: thread.title }
53+
{ op: 'replace', path: '/title', value: thread.title },
5454
]);
5555
}
5656

5757
// MESSAGES FUNCTIONS
5858

59+
/**
60+
* Returns the messages associated to the thread specified.
61+
* @param thread
62+
*/
63+
getMessages(thread: Thread): Observable<Message[]> {
64+
return this.httpClient
65+
.get<Message[]>(`/api/threads/${thread._id}/messages`)
66+
.pipe(map(messages => orderBy(['createdAt'], ['asc'], messages)));
67+
}
68+
5969
/**
6070
* Creates a new message and associates it to the thread specified.
6171
* @param thread
@@ -99,12 +109,6 @@ export class MessagingService {
99109
this.secondarySidenavService.open();
100110
}
101111

102-
getMessagesByThread(thread: Thread): Observable<Message[]> {
103-
return this.httpClient
104-
.get<Message[]>(`/api/threads/entity/${thread.entityId}/${thread._id}/messages`)
105-
.pipe(map(messages => orderBy(['createdAt'], ['asc'], messages)));
106-
}
107-
108112
updateMessage(thread: Thread, message: Message): Observable<Message> {
109113
return this.httpClient.patch<Message>(
110114
`/api/threads/entity/${thread.entityId}/${thread._id}/messages/${message._id}`,

client/components/messaging/thread-sidenav/thread-sidenav.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class ThreadSidenavComponent implements OnDestroy {
5252
take(1),
5353
// TODO Emit socket event when Message is created or added
5454
tap(thread => this.socketMessagesEventName = `message:entity:${thread.entityId}:${thread._id}`),
55-
switchMap(thread => this.messagingService.getMessagesByThread(thread))
55+
switchMap(thread => this.messagingService.getMessages(thread))
5656
)
5757
.subscribe(messages => {
5858
this._messages.next(messages);

client/components/messaging/thread/thread.component.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { App } from 'models/entities/app.model';
55
import { Thread } from 'models/messaging/thread.model';
66
// import { AppService } from './../../app.service';
77
// import config from '../../app.constants';
8-
import { switchMap } from 'rxjs/operators';
8+
import { switchMap, filter, take, tap } from 'rxjs/operators';
99
import { NotificationService } from 'components/notification/notification.service';
10+
import { MessagingService } from '../messaging.service';
11+
import { Message } from 'models/messaging/message.model';
1012

1113
@Component({
1214
selector: 'thread',
@@ -15,13 +17,18 @@ import { NotificationService } from 'components/notification/notification.servic
1517
})
1618
export class ThreadComponent implements OnInit {
1719
private _thread: BehaviorSubject<Thread> = new BehaviorSubject<Thread>(null);
20+
private messages: BehaviorSubject<Message[]> = new BehaviorSubject<Message[]>([]);
1821

1922
// @Input() private thread$: Observable<Thread>;
2023
private showThreadEditTemplate = false;
2124

22-
static parameters = [Router, ActivatedRoute, NotificationService];
23-
constructor(private router: Router, private route: ActivatedRoute, private notificationService: NotificationService) {
24-
25+
static parameters = [Router, ActivatedRoute, NotificationService, MessagingService];
26+
constructor(
27+
private router: Router,
28+
private route: ActivatedRoute,
29+
private notificationService: NotificationService,
30+
private messagingService: MessagingService
31+
) {
2532
// this.thread$ = this.route.params.pipe(
2633
// switchMap(res => this.dataCatalogService.get(res.id))
2734
// );
@@ -33,12 +40,32 @@ export class ThreadComponent implements OnInit {
3340

3441
@Input()
3542
set thread(thread) {
36-
console.log('THEAD IS NOW', thread);
3743
this._thread.next(thread);
3844
}
3945

46+
get messages$(): Observable<Message[]> {
47+
return this.messages.asObservable();
48+
}
49+
4050
ngOnInit() {
41-
// this.app$ = this.appService.getApp();
51+
this._thread
52+
.pipe(
53+
filter(thread => !!thread),
54+
take(1),
55+
// TODO Emit socket event when Message is created or added
56+
// tap(thread => this.socketMessagesEventName = `message:entity:${thread.entityId}:${thread._id}`),
57+
switchMap(thread => this.messagingService.getMessages(thread))
58+
)
59+
.subscribe(
60+
messages => {
61+
this.messages.next(messages);
62+
// this.socketService.syncArraySubject(this.socketMessagesEventName,
63+
// this._messages, (items: Message[]) => {
64+
// return orderBy('createdAt', 'asc', items);
65+
// });
66+
},
67+
err => console.error(err)
68+
);
4269
}
4370

4471
getLink(): string {

client/components/messaging/thread/thread.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
</mat-menu>
3939
</div>
4040
</mat-card-header>
41+
42+
<div *ngIf="messages$ | async as messages">
43+
<ng-template ngFor let-message let-i="index" let-first="first" [ngForOf]="messages">
44+
<!-- <message-date-separator *ngIf="first" class="message-date-separator" [isoDate]="message.createdAt"></message-date-separator>
45+
<message-date-separator *ngIf="!first && !(message.createdAt | sameDay: (messages)[i-1].createdAt)" class="message-date-separator" [isoDate]="message.createdAt"></message-date-separator> -->
46+
<!-- TODO Remove message.showStartThreadButton -->
47+
<!-- TODO Remove message.showReplyButton -->
48+
<!-- <message [thread]="thread" [message]="message" (deleteMessage)="onDeleteMessage($event)" (editMessage)="onEditMessage($event)"></message> -->
49+
</ng-template>
50+
</div>
51+
<!-- <message-new class="app-messaging-new" [thread]="thread" (newMessage)="onNewMessage($event)"></message-new> -->
4152
</mat-card>
4253

4354
<ng-template #showThreadEditForm>

server/api/thread/index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ router.patch('/:id', auth.isAuthenticated(), controller.patch);
1717
// Returns the threads associated with the entity specified.
1818
router.get('/entity/:entityId', auth.isAuthenticated(), controller.indexByEntity);
1919

20+
// Returns the messages for the thread specified.
21+
router.get('/:id/messages', auth.isAuthenticated(), controller.indexMessages);
22+
2023
// Adds a message to the thread specified.
2124
router.post('/:id/messages', auth.isAuthenticated(), controller.createMessage);
2225

@@ -27,6 +30,8 @@ router.get('/:id/messages/count', auth.isAuthenticated(), controller.messagesCou
2730

2831

2932

33+
34+
3035
// import {
3136
// accessTypes,
3237
// } from '../../config/environment';
@@ -44,15 +49,6 @@ router.get('/:id/messages/count', auth.isAuthenticated(), controller.messagesCou
4449
// // ),
4550
// controller.destroy);
4651

47-
// // Returns the messages for the thread specified.
48-
// router.get('/entity/:entityId/:id/messages',
49-
// // auth.canAccessEntity(
50-
// // READ_ACCESS,
51-
// // WRITE_ACCESS,
52-
// // ADMIN_ACCESS
53-
// // ),
54-
// controller.indexMessages);
55-
5652
// // Patches the message specified.
5753
// router.patch('/entity/:entityId/:id/messages/:messageId',
5854
// // auth.hasPermissionForEntityRelatedObject(Thread),

0 commit comments

Comments
 (0)