Own Feed now gets sent with WANT-Vector and the receiving device compares with it's own feeds, if it has that person in it's friends list, and prints to the console, how much it is behind
This commit is contained in:
parent
1582f57eab
commit
9bf4ffe51d
@ -98,6 +98,7 @@ extension BluetoothPeripheral: CBPeripheralManagerDelegate {
|
|||||||
let receivedObject = try decoder.decode(WantMessage.self, from: receivedData)
|
let receivedObject = try decoder.decode(WantMessage.self, from: receivedData)
|
||||||
// Use the received object to update your app state as needed
|
// Use the received object to update your app state as needed
|
||||||
print("Received Write")
|
print("Received Write")
|
||||||
|
self.incomingMsg = ""
|
||||||
self.incomingMsg = receivedObject.printMsg()
|
self.incomingMsg = receivedObject.printMsg()
|
||||||
self.wantVector = receivedObject
|
self.wantVector = receivedObject
|
||||||
print(receivedObject.printMsg())
|
print(receivedObject.printMsg())
|
||||||
|
|||||||
@ -22,13 +22,17 @@ struct PeeringView: View {
|
|||||||
List {
|
List {
|
||||||
ForEach(btPeripheral.wantVector.friends.keys.sorted(), id: \.self) { friend in
|
ForEach(btPeripheral.wantVector.friends.keys.sorted(), id: \.self) { friend in
|
||||||
Text("Feed: \(friend.description), SEQ: \(btPeripheral.wantVector.friends[friend] ?? -1)")
|
Text("Feed: \(friend.description), SEQ: \(btPeripheral.wantVector.friends[friend] ?? -1)")
|
||||||
// Send new log Entries...
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text("Incoming msg: \(btPeripheral.incomingMsg)")
|
Text("Incoming msg: \(btPeripheral.incomingMsg)")
|
||||||
|
.onChange(of: btPeripheral.incomingMsg) { newValue in
|
||||||
|
compareWithSavedFeeds(newVector: btPeripheral.wantVector)
|
||||||
|
}
|
||||||
Button(action: {
|
Button(action: {
|
||||||
do {
|
do {
|
||||||
let WANT_msg = WantMessage(friends: dataStore.friends)
|
var combinedDict = dataStore.friends
|
||||||
|
combinedDict[dataStore.personalFeed.feedID] = dataStore.personalFeed.feed.count
|
||||||
|
let WANT_msg = WantMessage(friends: combinedDict)
|
||||||
let encoded_msg = try JSONEncoder().encode(WANT_msg)
|
let encoded_msg = try JSONEncoder().encode(WANT_msg)
|
||||||
btController.writeToCharacteristics(message: String(data: encoded_msg, encoding: .utf8)!)
|
btController.writeToCharacteristics(message: String(data: encoded_msg, encoding: .utf8)!)
|
||||||
//btController.writeToCharacteristics(message: "Test")
|
//btController.writeToCharacteristics(message: "Test")
|
||||||
@ -42,6 +46,20 @@ struct PeeringView: View {
|
|||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func compareWithSavedFeeds(newVector: WantMessage) {
|
||||||
|
print("comparing with saved Feeds...")
|
||||||
|
for friend in newVector.friends.keys.sorted() {
|
||||||
|
if(dataStore.friends.keys.contains(friend.description)) {
|
||||||
|
print("Found friend \(friend.description) in own Feeds!")
|
||||||
|
var missingFeedEntries: Int = -1
|
||||||
|
if let ownCount = dataStore.friends[friend] {
|
||||||
|
missingFeedEntries = newVector.friends[friend]! - ownCount
|
||||||
|
}
|
||||||
|
print("You are \(missingFeedEntries) behind on the feed of \(friend.description)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PeeringView_Previews: PreviewProvider {
|
struct PeeringView_Previews: PreviewProvider {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user