...
 
Commits (6)
......@@ -70,6 +70,9 @@ export class ChannelComponent {
ngOnInit() {
this.updateMeta();
if (this.user) {
this.clientMetaService.recordView(this.user);
}
this.context.set('activity');
this.onScroll();
......@@ -171,6 +174,7 @@ export class ChannelComponent {
this.addRecent();
}
// this.load() is only called if this.user was not previously set
this.clientMetaService.recordView(this.user);
})
.catch(e => {
......
......@@ -67,6 +67,7 @@ export class CommentPosterComponent {
async post(e) {
e.preventDefault();
this.attachment.resetPreviewRequests();
if (this.content.length > this.maxLength) {
return;
}
......
......@@ -38,7 +38,7 @@ export class SidebarSelectorComponent implements OnInit {
showAll: boolean = true;
loading: boolean;
showExtendedList: boolean = false;
showTrending: boolean = false;
showTrending: boolean = true;
constructor(
protected topbarHashtagsService: TopbarHashtagsService,
......
......@@ -14,12 +14,13 @@ import { HashtagsSelectorComponent } from '../../hashtags/selector/selector.comp
import { Tag } from '../../hashtags/types/tag';
import autobind from '../../../helpers/autobind';
import { Subject, Subscription } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { debounceTime, map } from 'rxjs/operators';
import { Router } from '@angular/router';
import { InMemoryStorageService } from '../../../services/in-memory-storage.service';
import { AutocompleteSuggestionsService } from '../../suggestions/services/autocomplete-suggestions.service';
import { NSFWSelectorComponent } from '../../../common/components/nsfw-selector/nsfw-selector.component';
import { TagsService } from '../../../common/services/tags.service';
import { worker } from 'cluster';
@Component({
moduleId: module.id,
......@@ -134,15 +135,20 @@ export class PosterComponent {
this.meta.message = $event;
this.tags = [];
let words = $event.split(' ');
let words = $event.split(/\s|^/); // split words on space or newline.
for (let word of words) {
//itterate through words for hashtags.
if (
word.match(this.tagsService.getRegex('hash')) &&
!word.match(this.tagsService.getRegex('url'))
) {
// Account for non space-separated tags.
let tags = word.split('#').filter(c => c);
let tags = word
.split(/(?=\#)/) // retain # symbol in split.
.map(tag => {
if (tag[0] === '#') {
return tag.split(/\W/).filter(e => e);
}
})
.filter(e => e); // remove null array entries.
if (tags.length > 1) {
for (let tag of tags) {
......
......@@ -173,4 +173,38 @@ describe('Service: Attachment Service', () => {
tick(1000);
expect(clientMock.get).toHaveBeenCalledTimes(1);
}));
it('should populate the request array', fakeAsync(() => {
spyOn(service, 'addPreviewRequest');
service.preview('https://github.com/releases');
tick(1000);
expect(service.addPreviewRequest).toHaveBeenCalledTimes(1);
}));
it('should check the request array on response', fakeAsync(() => {
spyOn(service, 'getPreviewRequests');
service.preview('https://github.com/releases');
tick(1000);
expect(service.getPreviewRequests).toHaveBeenCalledTimes(1);
}));
it('should reset the request array when called', fakeAsync(() => {
service.addPreviewRequest('https://github.com/releases');
expect(service.getPreviewRequests().length).toBe(1);
service.resetPreviewRequests();
tick(1000);
expect(service.getPreviewRequests().length).toBe(0);
}));
it('should discard changes if request array has been cleared', fakeAsync(() => {
service.preview('https://github.com/releases');
tick(1000);
expect(this.meta).toBeFalsy();
}));
});
......@@ -33,6 +33,7 @@ export class AttachmentService {
private pendingDelete: boolean = false;
private xhr: XMLHttpRequest = null;
private previewRequests: string[] = [];
constructor(
public session: Session,
......@@ -356,7 +357,37 @@ export class AttachmentService {
this.meta.description = '';
}
preview(content: string, detectChangesFn?: Function) {
/**
* Resets preview requests to null.
*/
resetPreviewRequests(): AttachmentService {
this.previewRequests = [];
return this;
}
/**
* Returns preview requests.
*/
getPreviewRequests(): string[] {
return this.previewRequests;
}
/**
* Adds a new preview request.
* @param { string } url -
*/
addPreviewRequest(url: string): AttachmentService {
this.previewRequests.push(url);
return this;
}
/**
* Gets attachment preview from content.
* @param { string } content - Content to be parsed for preview URL.
* @param { Function } detectChangesFn - Function to be ran on change emission.
* @returns void.
*/
preview(content: string, detectChangesFn?: Function): void {
let match = content.match(/(\b(https?|ftp|file):\/\/[^\s\]\)]+)/gi),
url;
......@@ -389,6 +420,7 @@ export class AttachmentService {
}
this.attachment.richUrl = url;
this.addPreviewRequest(url);
if (detectChangesFn) detectChangesFn();
......@@ -401,7 +433,7 @@ export class AttachmentService {
this.clientService
.get('api/v1/newsfeed/preview', { url })
.then((data: any) => {
if (!data) {
if (!data || this.getPreviewRequests().length < 1) {
this.resetRich();
if (detectChangesFn) detectChangesFn();
return;
......