Change mentions to track usernames rather than user ids

This commit is contained in:
Alessio 2021-05-24 13:17:08 -04:00
parent 5449b16038
commit e5337ef0d0
2 changed files with 10 additions and 2 deletions

View File

@ -22,7 +22,7 @@ type Tweet struct {
Urls []string Urls []string
Images []string Images []string
Mentions []UserID Mentions []string
Hashtags []string Hashtags []string
QuotedTweet TweetID QuotedTweet TweetID
} }
@ -66,7 +66,7 @@ func ParseSingleTweet(apiTweet APITweet) (ret Tweet, err error) {
ret.Hashtags = append(ret.Hashtags, hashtag.Text) ret.Hashtags = append(ret.Hashtags, hashtag.Text)
} }
for _, mention := range apiTweet.Entities.Mentions { for _, mention := range apiTweet.Entities.Mentions {
ret.Mentions = append(ret.Mentions, UserID(mention.UserID)) ret.Mentions = append(ret.Mentions, mention.UserName)
} }
ret.QuotedTweet = TweetID(apiTweet.QuotedStatusIDStr) ret.QuotedTweet = TweetID(apiTweet.QuotedStatusIDStr)

View File

@ -47,6 +47,10 @@ func TestParseSingleTweet(t *testing.T) {
if actual_text != expected_text { if actual_text != expected_text {
t.Errorf("Expected: %q; got %q", expected_text, actual_text) t.Errorf("Expected: %q; got %q", expected_text, actual_text)
} }
if len(tweet.Mentions) != 1 || tweet.Mentions[0] != "michaelmalice" {
t.Errorf("Expected %v, got %v", []string{"michaelmalice"}, tweet.Mentions)
}
} }
func TestParseSingleTweet2(t *testing.T) { func TestParseSingleTweet2(t *testing.T) {
@ -101,6 +105,10 @@ func TestParseSingleTweet2(t *testing.T) {
if len(tweet1.Images) != 1 { if len(tweet1.Images) != 1 {
t.Errorf("Expected 1 images but got %d", len(tweet1.Images)) t.Errorf("Expected 1 images but got %d", len(tweet1.Images))
} }
if tweet2.InReplyTo != tweet1.ID {
t.Errorf("Expected %q, got %q", tweet1.ID, tweet2.InReplyTo)
}
if tweet1.QuotedTweet != "" { if tweet1.QuotedTweet != "" {
t.Errorf("Incorrectly believes it quote-tweets %q", tweet1.QuotedTweet) t.Errorf("Incorrectly believes it quote-tweets %q", tweet1.QuotedTweet)
} }