convert posts which exceed 254 characters to raw "nl.chimpnut.blog.post" resolves #51

This commit is contained in:
Morgan McMillian 2018-02-17 09:28:10 -08:00
parent d0f69b88a9
commit e3938a2efe

View file

@ -274,7 +274,7 @@ export class StreamPage {
}
showNewPost() {
let newPostModal = this.modalCtrl.create(NewPostModal);
let newPostModal = this.modalCtrl.create(NewPostModal, {me: this.myUsername});
newPostModal.present();
}
@ -335,7 +335,7 @@ export class StreamPage {
</ion-item>
</ion-card-content>
<ion-row justify-content-end>
<ion-col col-2><div text-center>{{254 - ptext.length}}</div></ion-col>
<ion-col col-2><div text-center>{{textCount()}}</div></ion-col>
<ion-col col-2>
<button ion-button (click)="send()">
<ion-icon name="send"></ion-icon>
@ -350,12 +350,14 @@ export class NewPostModal {
title: string;
replyid: string;
ptext: string = "";
options: Object;
options: Object = {};
myUsername: string;
longpost: Object = {};
raw: {type: string, value: Object}[] = [];
constructor(public navParams: NavParams, public viewCtrl: ViewController, public toastCtrl: ToastController,
public events: Events) {
console.log(this.navParams);
console.log(JSON.stringify(this.navParams));
this.myUsername = navParams.data.me;
if (navParams.data.type === 'reply') {
this.replyid = navParams.data.post.id;
@ -384,13 +386,28 @@ export class NewPostModal {
}
send() {
console.log(this.ptext);
if (this.ptext.length > 254) {
this.longpost = {
'title': '',
'body': this.ptext,
'tstamp': new Date().valueOf()
}
this.ptext = this.ptext.substr(0, 40) + "... - http://chimpnut.nl/u/";
this.ptext = this.ptext + this.navParams.data.me + "/lp/{object_id} - #longpost";
this.raw.push({
type: "nl.chimpnut.blog.post",
value: this.longpost
});
}
this.options['raw'] = this.raw;
pnut.createPost(this.ptext, this.options).then(res => {
console.log(res);
this.presentToast("Status posted.");
this.events.publish('stream:reload', {});
}).catch(err => {
console.log(err);
console.log(JSON.stringify(err));
});
this.viewCtrl.dismiss();
}
@ -421,6 +438,17 @@ export class NewPostModal {
return "";
}
}
textCount() {
let counttext = ""
let count = 254 - this.ptext.length
if (count < 1) {
counttext = "longpost"
} else {
counttext = String(count)
}
return counttext
}
}
@Component({