mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-11 05:45:56 +10:00
add groupWithGroupID; saveFeedWithFeedData when syncGroupsAndDoFurtherAction; sync full groupInfo when group with feed; now can show group.owner's avatar in ConversationCell if it with group
This commit is contained in:
+16
-1
@@ -545,7 +545,22 @@ func countOfUnreadMessagesInConversation(conversation: Conversation) -> Int {
|
||||
}
|
||||
|
||||
func saveFeedWithFeedData(feedData: DiscoveredFeed, group: Group, inRealm realm: Realm) {
|
||||
|
||||
|
||||
// try sync group first
|
||||
|
||||
groupWithGroupID(groupID: group.groupID, failureHandler: nil, completion: { groupInfo in
|
||||
|
||||
guard let realm = try? Realm() else {
|
||||
return
|
||||
}
|
||||
|
||||
println("feed groupInfo: \(groupInfo)")
|
||||
|
||||
syncGroupWithGroupInfo(groupInfo, inRealm: realm)
|
||||
})
|
||||
|
||||
// save feed
|
||||
|
||||
if let feed = feedWithFeedID(feedData.id, inRealm: realm) {
|
||||
print("Join Feed \(feed.feedID)")
|
||||
|
||||
|
||||
@@ -1258,6 +1258,21 @@ func friendships(completion completion: [JSONDictionary] -> Void) {
|
||||
|
||||
// MARK: - Groups
|
||||
|
||||
func groupWithGroupID(groupID groupID: String, failureHandler: ((Reason, String?) -> Void)?, completion: JSONDictionary -> Void) {
|
||||
|
||||
let parse: JSONDictionary -> JSONDictionary? = { data in
|
||||
return data
|
||||
}
|
||||
|
||||
let resource = authJsonResource(path: "/api/v1/circles/\(groupID)", method: .GET, requestParameters: [:], parse: parse)
|
||||
|
||||
if let failureHandler = failureHandler {
|
||||
apiRequest({_ in}, baseURL: baseURL, resource: resource, failure: failureHandler, completion: completion)
|
||||
} else {
|
||||
apiRequest({_ in}, baseURL: baseURL, resource: resource, failure: defaultFailureHandler, completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
func joinGroup(groupID groupID: String, failureHandler: ((Reason, String?) -> Void)?, completion: JSONDictionary -> Void) {
|
||||
|
||||
let parse: JSONDictionary -> JSONDictionary? = { data in
|
||||
|
||||
@@ -519,7 +519,17 @@ func syncGroupsAndDoFurtherAction(furtherAction: () -> Void) {
|
||||
// 增加本地没有的 Group
|
||||
|
||||
for groupInfo in allGroups {
|
||||
syncGroupWithGroupInfo(groupInfo, inRealm: realm)
|
||||
|
||||
let group = syncGroupWithGroupInfo(groupInfo, inRealm: realm)
|
||||
|
||||
//Sync Feed
|
||||
|
||||
if let
|
||||
topic = groupInfo["topic"] as? JSONDictionary,
|
||||
feedData = DiscoveredFeed.fromJSONDictionary(topic),
|
||||
group = group {
|
||||
saveFeedWithFeedData(feedData, group: group, inRealm: realm)
|
||||
}
|
||||
}
|
||||
|
||||
// do further action
|
||||
@@ -529,7 +539,8 @@ func syncGroupsAndDoFurtherAction(furtherAction: () -> Void) {
|
||||
}
|
||||
}
|
||||
|
||||
private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: Realm) {
|
||||
func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: Realm) -> Group? {
|
||||
|
||||
if let groupID = groupInfo["id"] as? String {
|
||||
|
||||
var group = groupWithGroupID(groupID, inRealm: realm)
|
||||
@@ -604,12 +615,6 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: Re
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Sync Feed
|
||||
|
||||
if let topic = groupInfo["topic"] as? JSONDictionary, feedData = DiscoveredFeed.fromJSONDictionary(topic) {
|
||||
saveFeedWithFeedData(feedData, group: group, inRealm: realm)
|
||||
}
|
||||
|
||||
// 同步 Group 的成员
|
||||
|
||||
@@ -683,7 +688,11 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: Re
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return group
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var isFetchingUnreadMessages = Listenable<Bool>(false) { _ in }
|
||||
|
||||
@@ -106,15 +106,6 @@ class FeedsViewController: UIViewController {
|
||||
let newGroup = Group()
|
||||
newGroup.groupID = groupID
|
||||
|
||||
// TOOD: newGroup of Feed
|
||||
/*
|
||||
if let groupInfo = messageInfo["circle"] as? JSONDictionary {
|
||||
if let groupName = groupInfo["name"] as? String {
|
||||
newGroup.groupName = groupName
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
realm.write {
|
||||
realm.add(newGroup)
|
||||
}
|
||||
|
||||
@@ -113,28 +113,64 @@ class ConversationCell: UITableViewCell {
|
||||
self.chatLabel.text = NSLocalizedString("No messages yet.", comment: "")
|
||||
self.timeAgoLabel.text = NSDate(timeIntervalSince1970: group.createdUnixTime).timeAgo
|
||||
}
|
||||
|
||||
|
||||
if let user = group.owner {
|
||||
AvatarCache.sharedInstance.roundAvatarOfUser(user, withRadius: radius, completion: {[weak self] image in
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
if let _ = tableView.cellForRowAtIndexPath(indexPath) {
|
||||
self?.avatarImageView.image = image
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
if let feed = group.withFeed {
|
||||
|
||||
|
||||
if let user = feed.creator {
|
||||
AvatarCache.sharedInstance.roundAvatarOfUser(user, withRadius: radius, completion: {[weak self] image in
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
if let _ = tableView.cellForRowAtIndexPath(indexPath) {
|
||||
self?.avatarImageView.image = image
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
if let URL = feed.attachments.first?.URLString {
|
||||
AvatarCache.sharedInstance.roundAvatarWithAvatarURLString(URL, withRadius: 30.0, completion: {[weak self] (image) -> Void in
|
||||
self?.avatarImageView.image = image
|
||||
AvatarCache.sharedInstance.roundAvatarWithAvatarURLString(URL, withRadius: radius, completion: {[weak self] (image) -> Void in
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
if let _ = tableView.cellForRowAtIndexPath(indexPath) {
|
||||
self?.avatarImageView.image = image
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if let avatarURL = feed.creator?.avatarURLString {
|
||||
AvatarCache.sharedInstance.roundAvatarWithAvatarURLString(avatarURL, withRadius: 30.0, completion: {[weak self] (image) -> Void in
|
||||
self?.avatarImageView.image = image
|
||||
if let user = feed.creator {
|
||||
AvatarCache.sharedInstance.roundAvatarOfUser(user, withRadius: radius, completion: {[weak self] image in
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
if let _ = tableView.cellForRowAtIndexPath(indexPath) {
|
||||
self?.avatarImageView.image = image
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
} else {
|
||||
if let avatarURL = group.owner?.avatarURLString {
|
||||
AvatarCache.sharedInstance.roundAvatarWithAvatarURLString(avatarURL, withRadius: 30.0, completion: {[weak self] (image) -> Void in
|
||||
self?.avatarImageView.image = image
|
||||
AvatarCache.sharedInstance.roundAvatarWithAvatarURLString(avatarURL, withRadius: radius, completion: {[weak self] image in
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
if let _ = tableView.cellForRowAtIndexPath(indexPath) {
|
||||
self?.avatarImageView.image = image
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user