@@ -19,15 +19,16 @@ You should have received a copy of the Affero GNU General Public License
1919
2020using System ;
2121using System . Security . Claims ;
22+ using System . Text . Json ;
2223using System . Threading . Tasks ;
2324using Microsoft . AspNetCore . Authorization ;
2425using Microsoft . AspNetCore . Mvc ;
2526using MongoDB . Bson ;
2627using Notesnook . API . Authorization ;
27- using Notesnook . API . Interfaces ;
2828using Notesnook . API . Models ;
29- using Notesnook . API . Repositories ;
29+ using Notesnook . API . Services ;
3030using Streetwriters . Common ;
31+ using Streetwriters . Common . Messages ;
3132using Streetwriters . Data . Repositories ;
3233
3334namespace Notesnook . API . Controllers
@@ -38,16 +39,16 @@ public class InboxController : ControllerBase
3839 {
3940 private readonly Repository < InboxApiKey > InboxApiKey ;
4041 private readonly Repository < UserSettings > UserSetting ;
41- private SyncItemsRepository InboxItems ;
42+ private Repository < InboxSyncItem > InboxItems ;
4243
4344 public InboxController (
4445 Repository < InboxApiKey > inboxApiKeysRepository ,
4546 Repository < UserSettings > userSettingsRepository ,
46- ISyncItemsRepositoryAccessor syncItemsRepositoryAccessor )
47+ Repository < InboxSyncItem > inboxItemsRepository )
4748 {
4849 InboxApiKey = inboxApiKeysRepository ;
4950 UserSetting = userSettingsRepository ;
50- InboxItems = syncItemsRepositoryAccessor . InboxItems ;
51+ InboxItems = inboxItemsRepository ;
5152 }
5253
5354 [ HttpGet ( "api-keys" ) ]
@@ -189,6 +190,18 @@ public async Task<IActionResult> CreateInboxItemAsync([FromBody] InboxSyncItem r
189190 request . UserId = userId ;
190191 request . ItemId = ObjectId . GenerateNewId ( ) . ToString ( ) ;
191192 await InboxItems . InsertAsync ( request ) ;
193+ new SyncDeviceService ( new SyncDevice ( userId , string . Empty ) )
194+ . AddIdsToAllDevices ( [ $ "{ request . ItemId } :inboxItems"] ) ;
195+ await WampServers . MessengerServer . PublishMessageAsync ( MessengerServerTopics . SendSSETopic , new SendSSEMessage
196+ {
197+ OriginTokenId = null ,
198+ UserId = userId ,
199+ Message = new Message
200+ {
201+ Type = "triggerSync" ,
202+ Data = JsonSerializer . Serialize ( new { reason = "Inbox items updated." } )
203+ }
204+ } ) ;
192205 return Ok ( ) ;
193206 }
194207 catch ( Exception ex )
0 commit comments