@@ -48,40 +48,39 @@ const getSingleMessage =
48
48
( messageId : number ) : ThunkAction < Promise < Message | null >> =>
49
49
async ( dispatch , getState ) => {
50
50
const state = getState ( ) ;
51
-
52
- const auth = getAuth ( state ) ;
53
51
const messages = getMessages ( state ) ;
54
- const zulipFeatureLevel = getZulipFeatureLevel ( state ) ;
55
- const allowEditHistory = getRealm ( state ) . allowEditHistory ;
56
-
57
- // Try to get it from our local data to avoid a server round-trip…
58
52
let message = messages . get ( messageId ) ;
53
+ if ( message ) {
54
+ return message ;
55
+ }
59
56
60
- // …but if we have to, go and ask the server.
61
57
// TODO: Give feedback when the server round trip takes longer than
62
58
// expected.
63
59
// TODO: Let the user cancel the request so we don't force a doNarrow
64
60
// after they've given up on tapping the link, and perhaps forgotten
65
61
// about it. Like any request, this might take well over a minute to
66
62
// resolve, or never resolve.
67
63
// TODO: When these are fixed, remove warning in jsdoc.
68
- if ( ! message ) {
64
+
65
+ const auth = getAuth ( state ) ;
66
+ const zulipFeatureLevel = getZulipFeatureLevel ( state ) ;
67
+ const allowEditHistory = getRealm ( state ) . allowEditHistory ;
68
+
69
+ if ( zulipFeatureLevel < 120 ) {
69
70
// TODO(server-5.0): Simplify; simplify jsdoc to match.
70
- if ( zulipFeatureLevel < 120 ) {
71
- // api.getSingleMessage won't give us the message's stream and
72
- // topic; see there.
73
- return null ;
74
- }
75
- try {
76
- message = await api . getSingleMessage (
77
- auth ,
78
- { message_id : messageId } ,
79
- zulipFeatureLevel ,
80
- allowEditHistory ,
81
- ) ;
82
- } catch {
83
- return null ;
84
- }
71
+ // api.getSingleMessage won't give us the message's stream and
72
+ // topic; see there.
73
+ return null ;
74
+ }
75
+ try {
76
+ message = await api . getSingleMessage (
77
+ auth ,
78
+ { message_id : messageId } ,
79
+ zulipFeatureLevel ,
80
+ allowEditHistory ,
81
+ ) ;
82
+ } catch {
83
+ return null ;
85
84
}
86
85
87
86
// The FL 120 condition on calling api.getSingleMessage should ensure
@@ -91,7 +90,6 @@ const getSingleMessage =
91
90
logging . error ( '`message` from api.getSingleMessage unexpectedly falsy' ) ;
92
91
return null ;
93
92
}
94
-
95
93
return message ;
96
94
} ;
97
95
0 commit comments