Skip to content

Commit

Permalink
Merge pull request #7 from jamesmagoo/client-improvements
Browse files Browse the repository at this point in the history
Add publish as draft (kind 30024) feature
  • Loading branch information
jamesmagoo authored Apr 14, 2024
2 parents 93c4d3e + 8d22cc9 commit 11a4960
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
14 changes: 7 additions & 7 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ export default class NostrWriterPlugin extends Plugin {
async checkAndPublish() {
if (!this.settings.privateKey) {
new Notice(
`Please set your private key in the Nostr Writer Plugin settings before publishing.`
`🔑 Please set your private key in the Nostr Writer Plugin settings before publishing.`
);
return;
}
const activeFile = this.app.workspace.getActiveFile();
if (activeFile) {
const fileContent: string = await this.app.vault.read(activeFile);
if (this.isEmptyContent(fileContent)) {
new Notice("The note is empty and cannot be published.");
new Notice("The note is empty and cannot be published.");
return;
}
if (this.nostrService.getConnectionStatus()) {
Expand All @@ -212,10 +212,10 @@ export default class NostrWriterPlugin extends Plugin {
this
).open();
} else {
new Notice(`Please connect to Nostr before publishing.`);
new Notice(`❗️ Please connect to Nostr before publishing.`);
}
} else {
new Notice("No note is currently active. Click into a note.");
new Notice("❗️ No note is currently active. Click into a note.");
}
}

Expand All @@ -228,7 +228,7 @@ export default class NostrWriterPlugin extends Plugin {
(evt: MouseEvent) => {
if (!this.settings.privateKey) {
new Notice(
`Please set your private key in the Nostr Writer Plugin settings before publishing.`
`🔑 Please set your private key in the Nostr Writer Plugin settings before publishing.`
);
return;
}
Expand All @@ -241,7 +241,7 @@ export default class NostrWriterPlugin extends Plugin {
return;
} else {
new Notice(
`Please connect to Nostr before publishing.`
`❗️ Please connect to Nostr before publishing.`
);
}
}
Expand All @@ -264,7 +264,7 @@ export default class NostrWriterPlugin extends Plugin {
});
this.statusBar.addEventListener("click", () => {
this.nostrService.connectToRelays();
new Notice("Re-connecting to Nostr..");
new Notice("⚡️ Re-connecting to Nostr..");
});
}
} else if (this.statusBar) {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "nostr-writer",
"name": "Nostr Writer",
"version": "2.1.0",
"version": "2.1.1",
"minAppVersion": "0.15.0",
"description": "Publish your writing directly to Nostr.",
"author": "jamesmagoo",
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": "nostr-writer",
"version": "2.1.0",
"version": "2.1.1",
"description": "Publish your writing seamlessly to Nostr.",
"main": "main.js",
"scripts": {
Expand Down
43 changes: 23 additions & 20 deletions src/ConfirmPublishModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ export default class ConfirmPublishModal extends Modal {
return;
}

const maxSizeInBytes = 10 * 1024 * 1024; // 10 MB
// TODO only do this check for non-premium nostr build users..
//if (premiumImageStorageUser){
// maxSizeInBytes = 100 * 1024 * 1024;
//}
// Option toggle in settings for user to indicate this ?
let maxSizeInBytes = 10 * 1024 * 1024; // 10 MB
if (this.plugin.settings.premiumStorageEnabled) {
maxSizeInBytes = 100 * 1024 * 1024;
}
if (file.size > maxSizeInBytes) {
new Notice('❌ File size exceeds the limit. Please upload a smaller image.');
return;
Expand Down Expand Up @@ -221,20 +219,24 @@ export default class ConfirmPublishModal extends Modal {
dropdown.onChange(async (value) => {
selectedProfileKey = value;
new Notice(`${selectedProfileKey} selected`);
console.log(selectedProfileKey)
});
});
}

// TODO is this a featue I want to add? Why publish as a draft? Obsidian is the draft location.
// let x = new Setting(contentEl)
// .setName("Publish as a draft")
// .setDesc("Nostr clients allow you to edit your drafts later.")
// .addToggle((toggle) =>
// toggle.setValue(false).onChange(async (value) => {
// console.log("Toggled", value);
// })
// );
let publishAsDraft = false;
new Setting(contentEl)
.setName("Publish as a draft")
.setDesc("Nostr clients allow you to edit your drafts later.")
.addToggle((toggle) =>
toggle.setValue(false).onChange(async (value) => {
publishAsDraft = value;
if (publishAsDraft) {
new Notice(`🗒️ Publishing as a draft.`);
} else {
new Notice(`📜 Publishing as final.`);
}
})
);

contentEl.createEl("hr");

Expand All @@ -247,7 +249,7 @@ export default class ConfirmPublishModal extends Modal {
.setButtonText("Confirm and Publish")
.setCta()
.onClick(async () => {
if (confirm("Are you sure you want to publish this note to Nostr?")) {
if (confirm(`Are you sure you want to publish this note ${publishAsDraft ? "as a draft" : "publically" } to Nostr?`)) {
// Disable the button and change the text to show a loading state
publishButton.setButtonText("Publishing...").setDisabled(true);
setTimeout(async () => {
Expand All @@ -262,7 +264,8 @@ export default class ConfirmPublishModal extends Modal {
selectedBannerImage && selectedBannerImage.path ? selectedBannerImage.path : null,
title,
noteCategoryTags,
selectedProfileKey
selectedProfileKey,
publishAsDraft
);
if (res.success) {
setTimeout(() => {
Expand Down Expand Up @@ -312,8 +315,8 @@ export default class ConfirmPublishModal extends Modal {

function addTagAsPill(tag: string) {
if (tag.trim() === "") return;
noteCategoryTags.push(tag);
const pillElement = createPillElement(tag);
noteCategoryTags.push(tag.trim());
const pillElement = createPillElement(tag.trim());
pillsContainer.appendChild(pillElement);
tagsText.setValue("");
}
Expand Down
27 changes: 16 additions & 11 deletions src/service/NostrService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,14 @@ export default class NostrService {
imageBannerFilePath: string | null,
title: string,
userSelectedTags: string[],
profileNickname: string
profileNickname: string,
publishAsDraft: boolean
): Promise<{ success: boolean; publishedRelays: string[] }> {
console.log(`Publishing your note to Nostr...`);
if (!publishAsDraft) {
new Notice(`⏳ Publishing your note ${activeFile.name} to nostr...`)
} else {
new Notice(`⏳ Publishing your note ${activeFile.name} as a draft to nostr...`)
}

let profilePrivateKey = this.privateKey;
let profilePublicKey = this.publicKey;
Expand All @@ -248,14 +253,14 @@ export default class NostrService {
}

if (imageBannerFilePath !== null) {
new Notice("🖼️ Uploading Banner Image")
let imageUploadResult = await this.imageUploadService.uploadArticleBannerImage(imageBannerFilePath);
if (imageUploadResult !== null) {
tags.push(["image", imageUploadResult]);
new Notice("✅ Uploaded Banner Image")
} else {
new Notice("❌ Problem Uploading Banner Image..")
}
new Notice("🖼️ Uploading Banner Image")
let imageUploadResult = await this.imageUploadService.uploadArticleBannerImage(imageBannerFilePath);
if (imageUploadResult !== null) {
tags.push(["image", imageUploadResult]);
new Notice("✅ Uploaded Banner Image")
} else {
new Notice("❌ Problem Uploading Banner Image..")
}
} else {
console.info("No banner image...")
}
Expand Down Expand Up @@ -314,7 +319,7 @@ export default class NostrService {
}

let eventTemplate = {
kind: 30023,
kind: publishAsDraft ? 30024 : 30023,
created_at: timestamp,
tags: tags,
content: fileContent,
Expand Down
4 changes: 1 addition & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ export class NostrWriterSettingTab extends PluginSettingTab {
.setValue(this.plugin.settings.premiumStorageEnabled)
.onChange(async (value) => {
this.plugin.settings.premiumStorageEnabled = value;
new Notice(
`✅ Premium image user mode ${value ? "enabled" : "disabled"}`
);
new Notice( `✅ Premium image user mode ${value ? "enabled" : "disabled"}`);
await this.plugin.saveSettings();
this.refreshDisplay();
})
Expand Down

0 comments on commit 11a4960

Please sign in to comment.