-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from rohan031/main
`Inbox` plugin support for MongooseIM
- Loading branch information
Showing
8 changed files
with
379 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'package:whixp/src/plugins/inbox/inbox.dart'; | ||
import 'package:whixp/whixp.dart'; | ||
|
||
void main() { | ||
final whixp = Whixp( | ||
jabberID: 'asdf@localhost', | ||
password: 'passwd', | ||
logger: Log( | ||
enableWarning: true, | ||
enableError: true, | ||
includeTimestamp: true, | ||
), | ||
internalDatabasePath: 'whixp', | ||
); | ||
|
||
whixp | ||
..addEventHandler('streamNegotiated', (_) { | ||
return getInbox(); | ||
}) | ||
..addEventHandler<Message>('message', (message) { | ||
final result = message?.get<InboxResult>(); | ||
if (result?.isNotEmpty ?? false) { | ||
for (final stanza in result!) { | ||
final forwarded = stanza.forwarded; | ||
if (forwarded?.delay?.stamp != null) { | ||
Log.instance.info(forwarded!.delay!.stamp!); | ||
} | ||
Log.instance.info("marked: ${forwarded?.actual?.isMarked}"); | ||
Log.instance.info( | ||
"box: ${stanza.box} \t archive: ${stanza.archive} \t mute: ${stanza.mute}"); | ||
Log.instance.info( | ||
"from: ${forwarded?.actual?.from?.username} \t to: ${forwarded?.actual?.to?.username}", | ||
); | ||
|
||
Log.instance.info("unread: ${stanza.unread}"); | ||
|
||
Log.instance.info( | ||
"type: ${forwarded?.actual?.subject} \t value: ${forwarded?.actual?.body}", | ||
); | ||
} | ||
} | ||
}); | ||
whixp.connect(); | ||
} | ||
|
||
String? globalLast; | ||
|
||
Future<void> getInbox({ | ||
String? lastItem, | ||
}) async { | ||
globalLast = null; | ||
final result = await Inbox.queryInbox( | ||
pagination: RSMSet( | ||
max: 25, | ||
after: lastItem, | ||
), | ||
); | ||
|
||
final fin = result.payload as InboxFin?; | ||
final last = fin?.last?.lastItem; | ||
Log.instance.warning( | ||
"active-conversations: ${fin?.activeConversation}", | ||
); | ||
Log.instance.warning( | ||
"unread: ${fin?.unreadMessages}", | ||
); | ||
Log.instance.warning( | ||
"cursor: $last", | ||
); | ||
|
||
if (last != null && last != globalLast) { | ||
getInbox( | ||
lastItem: last, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:whixp/src/_static.dart'; | ||
import 'package:whixp/src/plugins/plugins.dart'; | ||
import 'package:whixp/src/stanza/forwarded.dart'; | ||
import 'package:whixp/src/stanza/iq.dart'; | ||
import 'package:whixp/src/stanza/stanza.dart'; | ||
import 'package:whixp/src/utils/src/utils.dart'; | ||
import 'package:xml/xml.dart'; | ||
|
||
part 'stanza.dart'; | ||
|
||
class Inbox { | ||
const Inbox(); | ||
|
||
/// read here for all the options for the inbox querying | ||
/// https://esl.github.io/MongooseDocs/latest/open-extensions/inbox/ | ||
static FutureOr<IQ> queryInbox<T>({ | ||
RSMSet? pagination, | ||
int timeout = 5, | ||
}) { | ||
final query = InboxQuery( | ||
rsm: pagination, | ||
); | ||
|
||
final iq = IQ(generateID: true) | ||
..type = iqTypeSet | ||
..payload = query; | ||
|
||
return iq.send( | ||
timeout: timeout, | ||
); | ||
} | ||
} |
Oops, something went wrong.