convert posts which exceed 254 characters to raw "nl.chimpnut.blog.post" resolves #51
This commit is contained in:
parent
d0f69b88a9
commit
e3938a2efe
1 changed files with 34 additions and 6 deletions
|
@ -274,7 +274,7 @@ export class StreamPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
showNewPost() {
|
showNewPost() {
|
||||||
let newPostModal = this.modalCtrl.create(NewPostModal);
|
let newPostModal = this.modalCtrl.create(NewPostModal, {me: this.myUsername});
|
||||||
newPostModal.present();
|
newPostModal.present();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ export class StreamPage {
|
||||||
</ion-item>
|
</ion-item>
|
||||||
</ion-card-content>
|
</ion-card-content>
|
||||||
<ion-row justify-content-end>
|
<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>
|
<ion-col col-2>
|
||||||
<button ion-button (click)="send()">
|
<button ion-button (click)="send()">
|
||||||
<ion-icon name="send"></ion-icon>
|
<ion-icon name="send"></ion-icon>
|
||||||
|
@ -350,12 +350,14 @@ export class NewPostModal {
|
||||||
title: string;
|
title: string;
|
||||||
replyid: string;
|
replyid: string;
|
||||||
ptext: string = "";
|
ptext: string = "";
|
||||||
options: Object;
|
options: Object = {};
|
||||||
myUsername: string;
|
myUsername: string;
|
||||||
|
longpost: Object = {};
|
||||||
|
raw: {type: string, value: Object}[] = [];
|
||||||
|
|
||||||
constructor(public navParams: NavParams, public viewCtrl: ViewController, public toastCtrl: ToastController,
|
constructor(public navParams: NavParams, public viewCtrl: ViewController, public toastCtrl: ToastController,
|
||||||
public events: Events) {
|
public events: Events) {
|
||||||
console.log(this.navParams);
|
console.log(JSON.stringify(this.navParams));
|
||||||
this.myUsername = navParams.data.me;
|
this.myUsername = navParams.data.me;
|
||||||
if (navParams.data.type === 'reply') {
|
if (navParams.data.type === 'reply') {
|
||||||
this.replyid = navParams.data.post.id;
|
this.replyid = navParams.data.post.id;
|
||||||
|
@ -384,13 +386,28 @@ export class NewPostModal {
|
||||||
}
|
}
|
||||||
|
|
||||||
send() {
|
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 => {
|
pnut.createPost(this.ptext, this.options).then(res => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
this.presentToast("Status posted.");
|
this.presentToast("Status posted.");
|
||||||
this.events.publish('stream:reload', {});
|
this.events.publish('stream:reload', {});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err);
|
console.log(JSON.stringify(err));
|
||||||
});
|
});
|
||||||
this.viewCtrl.dismiss();
|
this.viewCtrl.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -421,6 +438,17 @@ export class NewPostModal {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textCount() {
|
||||||
|
let counttext = ""
|
||||||
|
let count = 254 - this.ptext.length
|
||||||
|
if (count < 1) {
|
||||||
|
counttext = "longpost"
|
||||||
|
} else {
|
||||||
|
counttext = String(count)
|
||||||
|
}
|
||||||
|
return counttext
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
Reference in a new issue