blob: 3cf942710ecf6d682fb328c05c5e03348c756353 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package net.lacolaco.smileessence.twitter
import net.lacolaco.smileessence.World
import net.lacolaco.smileessence.entity.Tweet
import net.lacolaco.smileessence.util.bg
import twitter4j.StatusUpdate
import java.io.InputStream
fun World.getTweetAsync(id: Long, fetchAlways: Boolean = true) = bg {
if (!fetchAlways) {
Tweet.fetch(id)
} else {
null
} ?: TwitterTaskException.wrap {
Tweet.fromTwitter(twitter.tweets().showStatus(id), id)
}
}
fun World.deleteTweetAsync(id: Long) = bg {
Tweet.fromTwitter(TwitterTaskException.wrap {
twitter.tweets().destroyStatus(id)
}, id)
}
fun World.createTweetAsync(text: String, inReplyTo: Long?, mediaIds: LongArray) = bg {
val su = StatusUpdate(text)
if (inReplyTo != null)
su.inReplyToStatusId = inReplyTo
su.setMediaIds(*mediaIds)
Tweet.fromTwitter(TwitterTaskException.wrap { twitter.tweets().updateStatus(su) }, id)
}
fun World.uploadMedia(stream: InputStream) = bg {
TwitterTaskException.wrap { twitter.tweets().uploadMedia("image.blob", stream) }.mediaId
}
|