This commit is contained in:
fmodf 2025-01-14 03:52:20 +01:00
parent 0dff34318b
commit d95c9c1671
5 changed files with 46 additions and 3 deletions

View file

@ -81,6 +81,7 @@ identifier_name:
- db - db
- _db - _db
- iq - iq
- xa
# Disable rules from the default enabled set. # Disable rules from the default enabled set.
disabled_rules: disabled_rules:

View file

@ -43,6 +43,7 @@ enum Event {
case streamReady case streamReady
case requestRoster case requestRoster
case rosterRequestDone
case addRosterItem(jidStr: String, args: [String: String]) case addRosterItem(jidStr: String, args: [String: String])
case updateRosterItem(jidStr: String, args: [String: String]) case updateRosterItem(jidStr: String, args: [String: String])
case deleteRosterItem(jidStr: String) case deleteRosterItem(jidStr: String)

View file

@ -0,0 +1,28 @@
import Foundation
enum PresenceType {
case chat
case online
case away
case xa
case dnd
var weight: Int {
switch self {
case .chat:
return 5
case .online:
return 4
case .away:
return 3
case .xa:
return 2
case .dnd:
return 1
}
}
}

View file

@ -16,7 +16,16 @@ final class PresenceModule: XmppModule {
oldState oldState
} }
func process(state _: ClientState, with _: Event) async -> Event? { func process(state _: ClientState, with event: Event) async -> Event? {
nil switch event {
case .rosterRequestDone:
return nil
case .stanzaInbound(let stanza):
return nil
default:
return nil
}
} }
} }

View file

@ -130,6 +130,10 @@ final class RosterModule: XmppModule {
return nil return nil
} }
// when roster requested, also raise .done event
case .rosterRequestDone:
return .rosterUpdated
default: default:
return nil return nil
} }
@ -220,7 +224,7 @@ private extension RosterModule {
// save roster // save roster
guard let data = try? JSONEncoder().encode(existItems.map { $0.wrapped }) else { return nil } guard let data = try? JSONEncoder().encode(existItems.map { $0.wrapped }) else { return nil }
await storage?.setRoster(jid: state.jid, roster: data) await storage?.setRoster(jid: state.jid, roster: data)
return .rosterUpdated return .rosterRequestDone
// for result of one of our request // for result of one of our request
case .iq(.set): case .iq(.set):