Skip to content

Commit

Permalink
Merge pull request #574 from NicolasConstant/topic_fixing-things
Browse files Browse the repository at this point in the history
Topic fixing things
  • Loading branch information
NicolasConstant authored Apr 24, 2023
2 parents cb342ce + 06dbdef commit f46d7d4
Show file tree
Hide file tree
Showing 24 changed files with 333 additions and 99 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ It is strongly focused on the following points:

It is released as a **browser webapp** and also packaged as an **cross-platform desktop application** (Mac, Windows, and Linux).

The Electron code isn't hosted here anymore, and you'll find it [here](https://github.com/NicolasConstant/sengi-electron).

## Official project page

[Discover Sengi](https://nicolasconstant.github.io/sengi/)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sengi",
"version": "1.2.0",
"version": "1.3.0",
"license": "AGPL-3.0-or-later",
"main": "main-electron.js",
"description": "A multi-account desktop client for Mastodon and Pleroma",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
</a>

<textarea #reply [(ngModel)]="status" name="status" class="form-control form-control-sm status-editor__content" (paste)="onPaste($event)"
rows="5" required title="content" placeholder="What's on your mind?" (keydown.control.enter)="onCtrlEnter()"
rows="5" required title="content" placeholder="What's on your mind?"
(keydown.control.enter)="onCtrlEnter()"
(keydown.meta.enter)="onCtrlEnter()"
(keydown)="handleKeyDown($event)" (blur)="statusTextEditorLostFocus()" dir="auto">
</textarea>

Expand Down
10 changes: 6 additions & 4 deletions src/app/components/create-status/create-status.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.isEditing = true;
this.editingStatusId = value.status.id;
this.redraftedStatus = value;
this.mediaService.loadMedia(value.status.media_attachments);
}
}

Expand Down Expand Up @@ -537,7 +538,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
return false;
}

onSubmit(): boolean {
async onSubmit(): Promise<boolean> {
if (this.isSending || this.mentionTooFarAwayError) return false;

this.isSending = true;
Expand All @@ -558,9 +559,10 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
break;
}

const mediaAttachments = this.mediaService.mediaSubject.value.map(x => x.attachment);

const acc = this.toolsService.getSelectedAccounts()[0];

const mediaAttachments = (await this.mediaService.retrieveUpToDateMedia(acc)).map(x => x.attachment);

let usableStatus: Promise<Status>;
if (this.statusReplyingToWrapper) {
usableStatus = this.toolsService.getStatusUsableByAccount(acc, this.statusReplyingToWrapper);
Expand Down Expand Up @@ -628,7 +630,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
let postPromise: Promise<Status>;

if (this.isEditing) {
postPromise = this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt);
postPromise = this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, attachments, poll, scheduledAt);
} else {
postPromise = this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/create-status/media/media.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div *ngFor="let m of media" class="media">
<div *ngIf="m.attachment === null" class="media__loading" title="{{m.file.name}}">
<div *ngIf="m.attachment === null" class="media__loading" title="{{getName(m)}}">
<app-waiting-animation class="waiting-icon"></app-waiting-animation>
</div>
<div *ngIf="m.attachment !== null && m.attachment.type !== 'audio'" class="media__loaded" title="{{m.file.name}}"
<div *ngIf="m.attachment !== null && m.attachment.type !== 'audio'" class="media__loaded" title="{{getName(m)}}"
(mouseleave)="updateMedia(m)">
<div class="media__loaded--migrating" *ngIf="m.isMigrating">
<app-waiting-animation class="waiting-icon"></app-waiting-animation>
Expand Down
9 changes: 9 additions & 0 deletions src/app/components/create-status/media/media.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ export class MediaComponent implements OnInit, OnDestroy {
this.mediaService.update(account, media);
return false;
}

getName(media: MediaWrapper): string {
if(media && media.file && media.file.name){
return media.file.name;
}
if(media.attachment && media.attachment.description){
return media.attachment.description;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class MentionsComponent extends TimelineBase {
}

protected getNextStatuses(): Promise<Status[]> {
return this.mastodonService.getNotifications(this.account, ['follow', 'favourite', 'reblog', 'poll', 'move'], this.lastId)
return this.mastodonService.getNotifications(this.account, ['follow', 'favourite', 'reblog', 'poll', 'move', 'update'], this.lastId)
.then((result: Notification[]) => {
const statuses = result.map(x => x.status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class NotificationsComponent extends BrowseBase {
this.isLoading = true;
this.isProcessingInfiniteScroll = true;

this.mastodonService.getNotifications(this.account.info, ['mention'], this.lastId)
this.mastodonService.getNotifications(this.account.info, ['mention', 'update'], this.lastId)
.then((notifications: Notification[]) => {
if (notifications.length === 0) {
this.maxReached = true;
Expand Down Expand Up @@ -168,5 +168,5 @@ export class NotificationWrapper {
account: Account;
target: Account;
status: StatusWrapper;
type: 'mention' | 'reblog' | 'favourite' | 'follow' | 'poll' | 'follow_request' | 'move';
type: 'mention' | 'reblog' | 'favourite' | 'follow' | 'poll' | 'follow_request' | 'move' | 'update';
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@
Unmute conversation
</ng-template>
<ng-template contextMenuItem divider="true"></ng-template>
<ng-template contextMenuItem (execute)="muteAccount()" *ngIf="!isOwnerSelected">
<ng-template contextMenuItem (execute)="muteAccount()" *ngIf="!isOwnerSelected && this.relationship && !this.relationship.muting">
Mute @{{ this.username }}
</ng-template>
<ng-template contextMenuItem (execute)="blockAccount()" *ngIf="!isOwnerSelected">
<ng-template contextMenuItem (execute)="unmuteAccount()" *ngIf="!isOwnerSelected && this.relationship && this.relationship.muting">
Unmute @{{ this.username }}
</ng-template>
<ng-template contextMenuItem (execute)="blockAccount()" *ngIf="!isOwnerSelected && this.relationship && !this.relationship.blocking">
Block @{{ this.username }}
</ng-template>
<ng-template contextMenuItem (execute)="unblockAccount()" *ngIf="!isOwnerSelected && this.relationship && this.relationship.blocking">
Unblock @{{ this.username }}
</ng-template>
<ng-template contextMenuItem (execute)="pinOnProfile()" *ngIf="statusWrapper && isOwnerSelected && !displayedStatus.pinned && displayedStatus.visibility === 'public'">
Pin on profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ContextMenuComponent, ContextMenuService } from 'ngx-contextmenu';
import { Observable, Subscription } from 'rxjs';
import { Store } from '@ngxs/store';

import { Status, Account, Results } from '../../../../../services/models/mastodon.interfaces';
import { Status, Account, Results, Relationship } from '../../../../../services/models/mastodon.interfaces';
import { ToolsService, OpenThreadEvent, InstanceInfo } from '../../../../../services/tools.service';
import { StatusWrapper } from '../../../../../models/common.model';
import { NavigationService } from '../../../../../services/navigation.service';
Expand All @@ -31,8 +31,10 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {

@Input() statusWrapper: StatusWrapper;
@Input() displayedAccount: Account;
@Input() relationship: Relationship;

@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@Output() relationshipChanged = new EventEmitter<Relationship>();

@ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;

Expand Down Expand Up @@ -166,37 +168,75 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
}

muteAccount(): boolean {
this.loadedAccounts.forEach(acc => {
this.toolsService.findAccount(acc, this.fullHandle)
.then((target: Account) => {
this.mastodonService.mute(acc, target.id);
return target;
})
.then((target: Account) => {
this.notificationService.hideAccount(target);
})
.catch(err => {
this.notificationService.notifyHttpError(err, acc);
});
});
const acc = this.toolsService.getSelectedAccounts()[0];

this.toolsService.findAccount(acc, this.fullHandle)
.then(async (target: Account) => {
const relationship = await this.mastodonService.mute(acc, target.id);
this.relationship = relationship;
this.relationshipChanged.next(relationship);
return target;
})
.then((target: Account) => {
this.notificationService.hideAccount(target);
})
.catch(err => {
this.notificationService.notifyHttpError(err, acc);
});

return false;
}

unmuteAccount(): boolean {
const acc = this.toolsService.getSelectedAccounts()[0];

this.toolsService.findAccount(acc, this.fullHandle)
.then(async (target: Account) => {
const relationship = await this.mastodonService.unmute(acc, target.id);
this.relationship = relationship;
this.relationshipChanged.next(relationship);
return target;
})
.catch(err => {
this.notificationService.notifyHttpError(err, acc);
});

return false;
}

blockAccount(): boolean {
this.loadedAccounts.forEach(acc => {
this.toolsService.findAccount(acc, this.fullHandle)
.then((target: Account) => {
this.mastodonService.block(acc, target.id);
return target;
})
.then((target: Account) => {
this.notificationService.hideAccount(target);
})
.catch(err => {
this.notificationService.notifyHttpError(err, acc);
});
});
const acc = this.toolsService.getSelectedAccounts()[0];

this.toolsService.findAccount(acc, this.fullHandle)
.then(async (target: Account) => {
const relationship = await this.mastodonService.block(acc, target.id);
this.relationship = relationship;
this.relationshipChanged.next(relationship);
return target;
})
.then((target: Account) => {
this.notificationService.hideAccount(target);
})
.catch(err => {
this.notificationService.notifyHttpError(err, acc);
});

return false;
}

unblockAccount(): boolean {
const acc = this.toolsService.getSelectedAccounts()[0];

this.toolsService.findAccount(acc, this.fullHandle)
.then(async (target: Account) => {
const relationship = await this.mastodonService.unblock(acc, target.id);
this.relationship = relationship;
this.relationshipChanged.next(relationship);
return target;
})
.catch(err => {
this.notificationService.notifyHttpError(err, acc);
});

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export class AttachementsComponent implements OnInit {

@Input('attachments')
set attachments(value: Attachment[]) {
this.imageAttachments = [];
this.videoAttachments = [];
this.audioAttachments = [];

this._attachments = value;
this.setAttachments(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class StreamNotificationsComponent extends BrowseBase {
this.loadMentions(userNotifications);
});

this.mastodonService.getNotifications(this.account, null, null, null, 10)
this.mastodonService.getNotifications(this.account, ['update'], null, null, 10) //FIXME: disable edition update until supported
.then((notifications: Notification[]) => {
this.isNotificationsLoading = false;

Expand Down Expand Up @@ -201,7 +201,7 @@ export class StreamNotificationsComponent extends BrowseBase {

this.isNotificationsLoading = true;

this.mastodonService.getNotifications(this.account, null, this.lastNotificationId)
this.mastodonService.getNotifications(this.account, ['update'], this.lastNotificationId)
.then((result: Notification[]) => {
if (result.length === 0) {
this.notificationsMaxReached = true;
Expand Down Expand Up @@ -235,7 +235,7 @@ export class StreamNotificationsComponent extends BrowseBase {

this.isMentionsLoading = true;

this.mastodonService.getNotifications(this.account, ['follow', 'favourite', 'reblog', 'poll', 'follow_request', 'move'], this.lastMentionId)
this.mastodonService.getNotifications(this.account, ['follow', 'favourite', 'reblog', 'poll', 'follow_request', 'move', 'update'], this.lastMentionId)
.then((result: Notification[]) => {
if (result.length === 0) {
this.mentionsMaxReached = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ <h2 class="profile-header__fullhandle"><a href="{{displayedAccount.url}}" target
</div>
</div>

<app-status-user-context-menu class="profile-header__more" [displayedAccount]="displayedAccount">
<app-status-user-context-menu class="profile-header__more"
[displayedAccount]="displayedAccount" [relationship]="relationship"
(relationshipChanged)="relationshipChanged($event)">
</app-status-user-context-menu>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ export class UserProfileComponent extends BrowseBase {
this.showFloatingStatusMenu = false;
this.load(this.lastAccountName);
}

relationshipChanged(relationship: Relationship){
this.relationship = relationship;
}

browseAccount(accountName: string): void {
if (accountName === this.toolsService.getAccountFullHandle(this.displayedAccount)) return;
Expand Down
17 changes: 13 additions & 4 deletions src/app/services/instances-info.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';

import { VisibilityEnum } from './mastodon.service';
import { MastodonWrapperService } from './mastodon-wrapper.service';
import { Instance, Account } from './models/mastodon.interfaces';
import { Instance, Instancev1, Instancev2, Account } from './models/mastodon.interfaces';
import { AccountInfo } from '../states/accounts.state';

@Injectable({
Expand All @@ -19,11 +19,20 @@ export class InstancesInfoService {
if (!this.cachedMaxInstanceChar[instance]) {
this.cachedMaxInstanceChar[instance] = this.mastodonService.getInstance(instance)
.then((instance: Instance) => {
if (instance.max_toot_chars) {
return instance.max_toot_chars;
if (+instance.version.split('.')[0] >= 4) {
const instanceV2 = <Instancev2>instance;
if (instanceV2
&& instanceV2.configuration
&& instanceV2.configuration.statuses
&& instanceV2.configuration.statuses.max_characters)
return instanceV2.configuration.statuses.max_characters;
} else {
return this.defaultMaxChars;
const instanceV1 = <Instancev1>instance;
if (instanceV1 && instanceV1.max_toot_chars)
return instanceV1.max_toot_chars;
}

return this.defaultMaxChars;
})
.catch(() => {
return this.defaultMaxChars;
Expand Down
Loading

0 comments on commit f46d7d4

Please sign in to comment.