@@ -23,58 +23,96 @@ internal AirshipMessageCenter(IAirshipPlugin plugin)
2323 }
2424
2525 /// <summary>
26- /// Gets the number of unread messages for the message center.
26+ /// Gets the number of unread messages for the message center asynchronously using a coroutine.
27+ /// This method does not block Unity's main thread.
2728 /// </summary>
28- /// <returns>The number of unread messages.</returns>
29- public int GetUnReadCount ( )
29+ /// <param name="onComplete">Callback invoked with the unread count when the operation completes.</param>
30+ /// <param name="onError">Optional callback invoked if an error occurs.</param>
31+ /// <returns>A coroutine that can be started with StartCoroutine.</returns>
32+ public IEnumerator GetUnReadCount ( Action < int > onComplete , Action < Exception > onError = null )
3033 {
31- return plugin . Call < int > ( "getUnreadCount" ) ;
34+ yield return AirshipCoroutineHelper . RunAsync (
35+ ( ) => plugin . Call < int > ( "getUnreadCount" ) ,
36+ onComplete ,
37+ onError
38+ ) ;
3239 }
3340
3441 /// <summary>
35- /// Gets the inbox messages.
42+ /// Gets the inbox messages asynchronously using a coroutine.
43+ /// This method does not block Unity's main thread.
3644 /// </summary>
37- /// <value>An enumberable list of InboxMessage objects.</value>
38- public IEnumerable < InboxMessage > GetMessages ( )
45+ /// <param name="onComplete">Callback invoked with the messages when the operation completes.</param>
46+ /// <param name="onError">Optional callback invoked if an error occurs.</param>
47+ /// <returns>A coroutine that can be started with StartCoroutine.</returns>
48+ public IEnumerator GetMessages ( Action < IEnumerable < InboxMessage > > onComplete , Action < Exception > onError = null )
3949 {
50+ yield return AirshipCoroutineHelper . RunAsync (
51+ ( ) => {
4052 var inboxMessages = new List < InboxMessage > ( ) ;
41-
4253 string inboxMessagesAsJson = plugin . Call < string > ( "getMessages" ) ;
4354 InternalInboxMessage [ ] internalInboxMessages = JsonArray < InternalInboxMessage > . FromJson ( inboxMessagesAsJson ) . values ;
44-
4555 // TODO verify this as the proxy provide a the extras into a map
4656 // Unity's JsonUtility doesn't support embedded dictionaries - constructor will create the extras dictionary
4757 foreach ( InternalInboxMessage internalInboxMessage in internalInboxMessages )
4858 {
4959 inboxMessages . Add ( new InboxMessage ( internalInboxMessage ) ) ;
5060 }
51- return inboxMessages ;
61+ return ( IEnumerable < InboxMessage > ) inboxMessages ;
62+ } ,
63+ onComplete ,
64+ onError
65+ ) ;
5266 }
5367
5468 /// <summary>
55- /// Mark an inbox message as having been read.
69+ /// Mark an inbox message as having been read asynchronously using a coroutine.
70+ /// This method does not block Unity's main thread.
5671 /// </summary>
5772 /// <param name="messageId">The messageId for the message.</param>
58- public void MarkMessageRead ( string messageId )
73+ /// <param name="onComplete">Optional callback invoked when the operation completes.</param>
74+ /// <param name="onError">Optional callback invoked if an error occurs.</param>
75+ /// <returns>A coroutine that can be started with StartCoroutine.</returns>
76+ public IEnumerator MarkMessageRead ( string messageId , Action onComplete = null , Action < Exception > onError = null )
5977 {
60- plugin . Call ( "markMessageRead" , messageId ) ;
78+ yield return AirshipCoroutineHelper . RunAsync (
79+ ( ) => plugin . Call ( "markMessageRead" , messageId ) ,
80+ onComplete ,
81+ onError
82+ ) ;
6183 }
6284
6385 /// <summary>
64- /// Delete an inbox message.
86+ /// Delete an inbox message asynchronously using a coroutine.
87+ /// This method does not block Unity's main thread.
6588 /// </summary>
6689 /// <param name="messageId">The messageId for the message.</param>
67- public void DeleteMessage ( string messageId )
90+ /// <param name="onComplete">Optional callback invoked when the operation completes.</param>
91+ /// <param name="onError">Optional callback invoked if an error occurs.</param>
92+ /// <returns>A coroutine that can be started with StartCoroutine.</returns>
93+ public IEnumerator DeleteMessage ( string messageId , Action onComplete = null , Action < Exception > onError = null )
6894 {
69- plugin . Call ( "deleteMessage" , messageId ) ;
95+ yield return AirshipCoroutineHelper . RunAsync (
96+ ( ) => plugin . Call ( "deleteMessage" , messageId ) ,
97+ onComplete ,
98+ onError
99+ ) ;
70100 }
71101
72102 /// <summary>
73- /// Refreshes the inbox.
103+ /// Refreshes the inbox asynchronously using a coroutine.
104+ /// This method does not block Unity's main thread.
74105 /// </summary>
75- public void RefreshInbox ( )
106+ /// <param name="onComplete">Optional callback invoked when the operation completes.</param>
107+ /// <param name="onError">Optional callback invoked if an error occurs.</param>
108+ /// <returns>A coroutine that can be started with StartCoroutine.</returns>
109+ public IEnumerator RefreshInbox ( Action onComplete = null , Action < Exception > onError = null )
76110 {
77- plugin . Call ( "refreshMessages" ) ;
111+ yield return AirshipCoroutineHelper . RunAsync (
112+ ( ) => plugin . Call ( "refreshMessages" ) ,
113+ onComplete ,
114+ onError
115+ ) ;
78116 }
79117
80118 /// <summary>
0 commit comments