1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 14:47:29 +00:00

fix(StoryViewerFragment): crash when parsing unexpected Instagram id

This commit is contained in:
Pablo Rodríguez Caballero 2021-03-21 21:30:20 +01:00
parent 622363c2c6
commit 0afe482b86
No known key found for this signature in database
GPG Key ID: 2788EF5E4218A68E

View File

@ -65,6 +65,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import awais.instagrabber.BuildConfig; import awais.instagrabber.BuildConfig;
import awais.instagrabber.R; import awais.instagrabber.R;
@ -735,7 +737,7 @@ public class StoryViewerFragment extends Fragment {
return; return;
} }
final HighlightModel model = models.get(currentFeedStoryIndex); final HighlightModel model = models.get(currentFeedStoryIndex);
currentStoryMediaId = model.getId(); currentStoryMediaId = parseStoryMediaId(model.getId());
currentStoryUsername = model.getTitle(); currentStoryUsername = model.getTitle();
fetchOptions = StoryViewerOptions.forUser(Long.parseLong(currentStoryMediaId), currentStoryUsername); fetchOptions = StoryViewerOptions.forUser(Long.parseLong(currentStoryMediaId), currentStoryUsername);
break; break;
@ -1146,4 +1148,20 @@ public class StoryViewerFragment extends Fragment {
resetView(); resetView();
} }
} }
/**
* Parses the Story's media ID. For user stories this is a number, but for archive stories
* this is "archiveDay:" plus a number.
*/
private static String parseStoryMediaId(String rawId) {
final String regex = "(?:archiveDay:)?(.+)";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(rawId);
if (matcher.matches() && matcher.groupCount() >= 1) {
return matcher.group(1);
}
return rawId;
}
} }