mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-22 04:21:44 +00:00
feat: community user status pt 2
This commit is contained in:
parent
c21f80e7da
commit
6849091460
@ -33,6 +33,12 @@ proc handleChatEvents(self: ChatController) =
|
|||||||
self.view.updateUsernames(evArgs.contacts)
|
self.view.updateUsernames(evArgs.contacts)
|
||||||
self.view.updateChats(evArgs.chats)
|
self.view.updateChats(evArgs.chats)
|
||||||
self.view.pushMessages(evArgs.messages)
|
self.view.pushMessages(evArgs.messages)
|
||||||
|
|
||||||
|
# TODO: update current user status
|
||||||
|
|
||||||
|
for statusUpdate in evArgs.statusUpdates:
|
||||||
|
self.view.communities.updateMemberVisibility(statusUpdate)
|
||||||
|
|
||||||
for message in evArgs.messages:
|
for message in evArgs.messages:
|
||||||
if (message.replace != ""):
|
if (message.replace != ""):
|
||||||
# Delete the message that this message replaces
|
# Delete the message that this message replaces
|
||||||
|
@ -4,7 +4,7 @@ import
|
|||||||
proc handleSignals(self: ChatController) =
|
proc handleSignals(self: ChatController) =
|
||||||
self.status.events.on(SignalType.Message.event) do(e:Args):
|
self.status.events.on(SignalType.Message.event) do(e:Args):
|
||||||
var data = MessageSignal(e)
|
var data = MessageSignal(e)
|
||||||
self.status.chat.update(data.chats, data.messages, data.emojiReactions, data.communities, data.membershipRequests, data.pinnedMessages, data.activityCenterNotification)
|
self.status.chat.update(data.chats, data.messages, data.emojiReactions, data.communities, data.membershipRequests, data.pinnedMessages, data.activityCenterNotification, data.statusUpdates)
|
||||||
|
|
||||||
self.status.events.on(SignalType.DiscoverySummary.event) do(e:Args):
|
self.status.events.on(SignalType.DiscoverySummary.event) do(e:Args):
|
||||||
## Handle mailserver peers being added and removed
|
## Handle mailserver peers being added and removed
|
||||||
|
@ -66,11 +66,10 @@ QtObject:
|
|||||||
if unreadTotal != community.unviewedMessagesCount:
|
if unreadTotal != community.unviewedMessagesCount:
|
||||||
community.unviewedMessagesCount = unreadTotal
|
community.unviewedMessagesCount = unreadTotal
|
||||||
|
|
||||||
proc updateMemberVisibility*(self: CommunitiesView, communityId, pubKey, timestamp: string) =
|
proc updateMemberVisibility*(self: CommunitiesView, statusUpdate: StatusUpdate) =
|
||||||
self.joinedCommunityList.updateMemberVisibility(communityId, pubKey, timestamp)
|
self.joinedCommunityList.updateMemberVisibility(statusUpdate)
|
||||||
if communityId == self.activeCommunity.communityItem.id:
|
self.activeCommunity.setCommunityItem(self.joinedCommunityList.getCommunityById(self.activeCommunity.communityItem.id))
|
||||||
self.activeCommunity.setCommunityItem(self.joinedCommunityList.getCommunityById(communityId))
|
self.activeCommunity.triggerMemberUpdate()
|
||||||
self.activeCommunity.triggerMemberUpdate()
|
|
||||||
|
|
||||||
proc updateCommunityChat*(self: CommunitiesView, newChat: Chat) =
|
proc updateCommunityChat*(self: CommunitiesView, newChat: Chat) =
|
||||||
var community = self.joinedCommunityList.getCommunityById(newChat.communityId)
|
var community = self.joinedCommunityList.getCommunityById(newChat.communityId)
|
||||||
|
@ -199,11 +199,15 @@ QtObject:
|
|||||||
self.members.triggerUpdate()
|
self.members.triggerUpdate()
|
||||||
|
|
||||||
proc memberLastSeen*(self: CommunityItemView, pubKey: string): string {.slot.} =
|
proc memberLastSeen*(self: CommunityItemView, pubKey: string): string {.slot.} =
|
||||||
if self.communityItem.lastSeen.hasKey(pubKey):
|
if self.communityItem.memberStatus.hasKey(pubKey):
|
||||||
result = self.communityItem.lastSeen[pubKey]
|
result = $self.communityItem.memberStatus[pubKey].clock
|
||||||
else:
|
else:
|
||||||
result = "0"
|
result = "0"
|
||||||
|
|
||||||
|
proc memberStatus*(self: CommunityItemView, pubKey: string): int {.slot.} =
|
||||||
|
if self.communityItem.memberStatus.hasKey(pubKey):
|
||||||
|
result = self.communityItem.memberStatus[pubKey].statusType.int
|
||||||
|
|
||||||
proc hasMember*(self: CommunityItemView, pubKey: string): bool {.slot.} =
|
proc hasMember*(self: CommunityItemView, pubKey: string): bool {.slot.} =
|
||||||
result = self.members.members.contains(pubKey)
|
result = self.members.members.contains(pubKey)
|
||||||
|
|
||||||
|
@ -171,14 +171,14 @@ QtObject:
|
|||||||
if community.id == communityId:
|
if community.id == communityId:
|
||||||
return community
|
return community
|
||||||
|
|
||||||
proc updateMemberVisibility*(self: CommunityList, communityId, pubKey, timestamp: string) =
|
proc updateMemberVisibility*(self: CommunityList, statusUpdate: StatusUpdate) =
|
||||||
for community in self.communities.mitems:
|
for community in self.communities.mitems:
|
||||||
if community.id != communityId: continue
|
if not community.members.contains(statusUpdate.publicKey): continue
|
||||||
if community.lastSeen.haskey(pubKey):
|
if community.memberStatus.haskey(statusUpdate.publicKey):
|
||||||
if parseBiggestInt(timestamp) > parseBiggestInt(community.lastSeen[pubKey]):
|
if statusUpdate.clock > community.memberStatus[statusUpdate.publicKey].clock:
|
||||||
community.lastSeen[pubKey] = timestamp
|
community.memberStatus[statusUpdate.publicKey] = statusUpdate
|
||||||
else:
|
else:
|
||||||
community.lastSeen[pubKey] = timestamp
|
community.memberStatus[statusUpdate.publicKey] = statusUpdate
|
||||||
break
|
break
|
||||||
|
|
||||||
proc addChannelToCommunity*(self: CommunityList, communityId: string, chat: Chat) =
|
proc addChannelToCommunity*(self: CommunityList, communityId: string, chat: Chat) =
|
||||||
@ -209,7 +209,7 @@ QtObject:
|
|||||||
let topLeft = self.createIndex(index, index, nil)
|
let topLeft = self.createIndex(index, index, nil)
|
||||||
let bottomRight = self.createIndex(index, index, nil)
|
let bottomRight = self.createIndex(index, index, nil)
|
||||||
var oldCommunity = self.communities[index]
|
var oldCommunity = self.communities[index]
|
||||||
community.lastSeen = oldCommunity.lastSeen
|
community.memberStatus = oldCommunity.memberStatus
|
||||||
self.communities[index] = community
|
self.communities[index] = community
|
||||||
self.dataChanged(topLeft, bottomRight, @[CommunityRoles.Name.int, CommunityRoles.Description.int, CommunityRoles.UnviewedMessagesCount.int, CommunityRoles.ThumbnailImage.int])
|
self.dataChanged(topLeft, bottomRight, @[CommunityRoles.Name.int, CommunityRoles.Description.int, CommunityRoles.UnviewedMessagesCount.int, CommunityRoles.ThumbnailImage.int])
|
||||||
|
|
||||||
|
@ -250,9 +250,7 @@ QtObject:
|
|||||||
if (channel == nil):
|
if (channel == nil):
|
||||||
channel = self.communities.getChannel(msg.chatId)
|
channel = self.communities.getChannel(msg.chatId)
|
||||||
if (channel == nil):
|
if (channel == nil):
|
||||||
continue
|
continue
|
||||||
else:
|
|
||||||
self.communities.updateMemberVisibility(channel.communityId, msg.fromAuthor, msg.timestamp)
|
|
||||||
if msg.chatId == self.channelView.activeChannel.id:
|
if msg.chatId == self.channelView.activeChannel.id:
|
||||||
discard self.status.chat.markMessagesSeen(msg.chatId, @[msg.id])
|
discard self.status.chat.markMessagesSeen(msg.chatId, @[msg.id])
|
||||||
self.newMessagePushed()
|
self.newMessagePushed()
|
||||||
|
@ -28,6 +28,7 @@ type
|
|||||||
communities*: seq[Community]
|
communities*: seq[Community]
|
||||||
communityMembershipRequests*: seq[CommunityMembershipRequest]
|
communityMembershipRequests*: seq[CommunityMembershipRequest]
|
||||||
activityCenterNotifications*: seq[ActivityCenterNotification]
|
activityCenterNotifications*: seq[ActivityCenterNotification]
|
||||||
|
statusUpdates*: seq[StatusUpdate]
|
||||||
|
|
||||||
ChatIdArg* = ref object of Args
|
ChatIdArg* = ref object of Args
|
||||||
chatId*: string
|
chatId*: string
|
||||||
@ -89,7 +90,7 @@ proc newChatModel*(events: EventEmitter): ChatModel =
|
|||||||
proc delete*(self: ChatModel) =
|
proc delete*(self: ChatModel) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc update*(self: ChatModel, chats: seq[Chat], messages: seq[Message], emojiReactions: seq[Reaction], communities: seq[Community], communityMembershipRequests: seq[CommunityMembershipRequest], pinnedMessages: seq[Message], activityCenterNotifications: seq[ActivityCenterNotification]) =
|
proc update*(self: ChatModel, chats: seq[Chat], messages: seq[Message], emojiReactions: seq[Reaction], communities: seq[Community], communityMembershipRequests: seq[CommunityMembershipRequest], pinnedMessages: seq[Message], activityCenterNotifications: seq[ActivityCenterNotification], statusUpdates: seq[StatusUpdate]) =
|
||||||
for chat in chats:
|
for chat in chats:
|
||||||
self.channels[chat.id] = chat
|
self.channels[chat.id] = chat
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ proc update*(self: ChatModel, chats: seq[Chat], messages: seq[Message], emojiRea
|
|||||||
if self.lastMessageTimestamps[chatId] > ts:
|
if self.lastMessageTimestamps[chatId] > ts:
|
||||||
self.lastMessageTimestamps[chatId] = ts
|
self.lastMessageTimestamps[chatId] = ts
|
||||||
|
|
||||||
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages,chats: chats, contacts: @[], emojiReactions: emojiReactions, communities: communities, communityMembershipRequests: communityMembershipRequests, pinnedMessages: pinnedMessages, activityCenterNotifications: activityCenterNotifications))
|
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages,chats: chats, contacts: @[], emojiReactions: emojiReactions, communities: communities, communityMembershipRequests: communityMembershipRequests, pinnedMessages: pinnedMessages, activityCenterNotifications: activityCenterNotifications, statusUpdates: statusUpdates))
|
||||||
|
|
||||||
proc hasChannel*(self: ChatModel, chatId: string): bool =
|
proc hasChannel*(self: ChatModel, chatId: string): bool =
|
||||||
self.channels.hasKey(chatId)
|
self.channels.hasKey(chatId)
|
||||||
|
@ -107,6 +107,17 @@ type CommunityCategory* = object
|
|||||||
name*: string
|
name*: string
|
||||||
position*: int
|
position*: int
|
||||||
|
|
||||||
|
type StatusUpdateType* {.pure.}= enum
|
||||||
|
Unknown = 0,
|
||||||
|
Online = 1,
|
||||||
|
DoNotDisturb = 2
|
||||||
|
|
||||||
|
type StatusUpdate* = object
|
||||||
|
publicKey*: string
|
||||||
|
statusType*: StatusUpdateType
|
||||||
|
clock*: int64
|
||||||
|
text*: string
|
||||||
|
|
||||||
type Community* = object
|
type Community* = object
|
||||||
id*: string
|
id*: string
|
||||||
name*: string
|
name*: string
|
||||||
@ -129,7 +140,7 @@ type Community* = object
|
|||||||
communityImage*: IdentityImage
|
communityImage*: IdentityImage
|
||||||
membershipRequests*: seq[CommunityMembershipRequest]
|
membershipRequests*: seq[CommunityMembershipRequest]
|
||||||
communityColor*: string
|
communityColor*: string
|
||||||
lastSeen*: OrderedTable[string, string]
|
memberStatus*: OrderedTable[string, StatusUpdate]
|
||||||
|
|
||||||
type ActivityCenterNotification* = ref object of RootObj
|
type ActivityCenterNotification* = ref object of RootObj
|
||||||
id*: string # ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one is the hex encoded public key and for group chats is a random uuid appended with the hex encoded pk of the creator of the chat
|
id*: string # ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one is the hex encoded public key and for group chats is a random uuid appended with the hex encoded pk of the creator of the chat
|
||||||
|
@ -19,6 +19,8 @@ proc toMessage*(jsonMsg: JsonNode): Message
|
|||||||
|
|
||||||
proc toChat*(jsonChat: JsonNode): Chat
|
proc toChat*(jsonChat: JsonNode): Chat
|
||||||
|
|
||||||
|
proc toStatusUpdate*(jsonStatusUpdate: JsonNode): StatusUpdate
|
||||||
|
|
||||||
proc toReaction*(jsonReaction: JsonNode): Reaction
|
proc toReaction*(jsonReaction: JsonNode): Reaction
|
||||||
|
|
||||||
proc toCommunity*(jsonCommunity: JsonNode): Community
|
proc toCommunity*(jsonCommunity: JsonNode): Community
|
||||||
@ -52,6 +54,11 @@ proc fromEvent*(event: JsonNode): Signal =
|
|||||||
chat.mentionsCount.inc
|
chat.mentionsCount.inc
|
||||||
signal.chats.add(chat)
|
signal.chats.add(chat)
|
||||||
|
|
||||||
|
if event["event"]{"statusUpdates"} != nil:
|
||||||
|
for jsonStatusUpdate in event["event"]["statusUpdates"]:
|
||||||
|
var statusUpdate = jsonStatusUpdate.toStatusUpdate
|
||||||
|
signal.statusUpdates.add(statusUpdate)
|
||||||
|
|
||||||
if event["event"]{"installations"} != nil:
|
if event["event"]{"installations"} != nil:
|
||||||
for jsonInstallation in event["event"]["installations"]:
|
for jsonInstallation in event["event"]["installations"]:
|
||||||
signal.installations.add(jsonInstallation.toInstallation)
|
signal.installations.add(jsonInstallation.toInstallation)
|
||||||
@ -196,6 +203,16 @@ proc toChat*(jsonChat: JsonNode): Chat =
|
|||||||
for jsonMember in jsonChat["membershipUpdateEvents"]:
|
for jsonMember in jsonChat["membershipUpdateEvents"]:
|
||||||
result.membershipUpdateEvents.add(jsonMember.toChatMembershipEvent)
|
result.membershipUpdateEvents.add(jsonMember.toChatMembershipEvent)
|
||||||
|
|
||||||
|
proc toStatusUpdate*(jsonStatusUpdate: JsonNode): StatusUpdate =
|
||||||
|
let statusTypeInt = jsonStatusUpdate{"status-type"}.getInt
|
||||||
|
let statusType: StatusUpdateType = if statusTypeInt >= ord(low(StatusUpdateType)) or statusTypeInt <= ord(high(StatusUpdateType)): StatusUpdateType(statusTypeInt) else: StatusUpdateType.Unknown
|
||||||
|
result = StatusUpdate(
|
||||||
|
publicKey: jsonStatusUpdate{"public-key"}.getStr,
|
||||||
|
statusType: statusType,
|
||||||
|
clock: jsonStatusUpdate{"clock"}.getBiggestInt,
|
||||||
|
text: jsonStatusUpdate{"text"}.getStr
|
||||||
|
)
|
||||||
|
|
||||||
proc toCommunity*(jsonCommunity: JsonNode): Community =
|
proc toCommunity*(jsonCommunity: JsonNode): Community =
|
||||||
result = Community(
|
result = Community(
|
||||||
id: jsonCommunity{"id"}.getStr,
|
id: jsonCommunity{"id"}.getStr,
|
||||||
@ -217,7 +234,7 @@ proc toCommunity*(jsonCommunity: JsonNode): Community =
|
|||||||
communityImage: IdentityImage()
|
communityImage: IdentityImage()
|
||||||
)
|
)
|
||||||
|
|
||||||
result.lastSeen = initOrderedTable[string, string]()
|
result.memberStatus = initOrderedTable[string, StatusUpdate]()
|
||||||
|
|
||||||
if jsonCommunity.hasKey("images") and jsonCommunity["images"].kind != JNull:
|
if jsonCommunity.hasKey("images") and jsonCommunity["images"].kind != JNull:
|
||||||
if jsonCommunity["images"].hasKey("thumbnail"):
|
if jsonCommunity["images"].hasKey("thumbnail"):
|
||||||
|
@ -37,6 +37,7 @@ type MessageSignal* = ref object of Signal
|
|||||||
communities*: seq[Community]
|
communities*: seq[Community]
|
||||||
membershipRequests*: seq[CommunityMembershipRequest]
|
membershipRequests*: seq[CommunityMembershipRequest]
|
||||||
activityCenterNotification*: seq[ActivityCenterNotification]
|
activityCenterNotification*: seq[ActivityCenterNotification]
|
||||||
|
statusUpdates*: seq[StatusUpdate]
|
||||||
|
|
||||||
type CommunitySignal* = ref object of Signal
|
type CommunitySignal* = ref object of Signal
|
||||||
community*: Community
|
community*: Community
|
||||||
|
@ -10,6 +10,7 @@ Item {
|
|||||||
property string name: "channelName"
|
property string name: "channelName"
|
||||||
property string lastSeen: ""
|
property string lastSeen: ""
|
||||||
property string identicon
|
property string identicon
|
||||||
|
property int statusType: Constants.statusType_Online
|
||||||
property bool hovered: false
|
property bool hovered: false
|
||||||
property bool enableMouseArea: true
|
property bool enableMouseArea: true
|
||||||
property var currentTime
|
property var currentTime
|
||||||
@ -80,16 +81,16 @@ Item {
|
|||||||
width: 10
|
width: 10
|
||||||
radius: 20
|
radius: 20
|
||||||
color: {
|
color: {
|
||||||
let lastSeenMinutesAgo = (currentTime - parseInt(lastSeen)) / 1000 / 60
|
let lastSeenMinutesAgo = (currentTime/1000 - parseInt(lastSeen)) / 60
|
||||||
|
|
||||||
if (!chatsModel.isOnline) {
|
if (!chatsModel.isOnline) {
|
||||||
return Style.current.darkGrey
|
return Style.current.darkGrey
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCurrentUser || lastSeenMinutesAgo < 5){
|
if (isCurrentUser || lastSeenMinutesAgo < 5){
|
||||||
return Style.current.green;
|
return statusType == Constants.statusType_DoNotDisturb ? Style.current.red : Style.current.green;
|
||||||
} else if (lastSeenMinutesAgo < 20) {
|
} else if (lastSeenMinutesAgo < 20) {
|
||||||
return Style.current.orange
|
return statusType == Constants.statusType_DoNotDisturb ? Style.current.red : Style.current.orange;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Style.current.darkGrey
|
return Style.current.darkGrey
|
||||||
|
@ -42,11 +42,12 @@ Rectangle {
|
|||||||
property string nickname: appMain.getUserNickname(model.pubKey)
|
property string nickname: appMain.getUserNickname(model.pubKey)
|
||||||
|
|
||||||
publicKey: model.pubKey
|
publicKey: model.pubKey
|
||||||
name: !model.userName.endsWith(".eth") && !!nickname ?
|
name: chatsModel.communities.activeCommunity.memberLastSeen(model.pubKey) + "--" + ( !model.userName.endsWith(".eth") && !!nickname ?
|
||||||
nickname : Utils.removeStatusEns(model.userName)
|
nickname : Utils.removeStatusEns(model.userName))
|
||||||
identicon: model.identicon
|
identicon: model.identicon
|
||||||
lastSeen: chatsModel.communities.activeCommunity.memberLastSeen(model.pubKey)
|
lastSeen: chatsModel.communities.activeCommunity.memberLastSeen(model.pubKey)
|
||||||
currentTime: svRoot.currentTime
|
currentTime: svRoot.currentTime
|
||||||
|
statusType: chatsModel.communities.activeCommunity.memberStatus(model.pubKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -85,6 +85,10 @@ QtObject {
|
|||||||
readonly property string linux: "linux"
|
readonly property string linux: "linux"
|
||||||
readonly property string mac: "mac"
|
readonly property string mac: "mac"
|
||||||
|
|
||||||
|
readonly property int statusType_Unknown: 0
|
||||||
|
readonly property int statusType_Online: 1
|
||||||
|
readonly property int statusType_DoNotDisturb: 2
|
||||||
|
|
||||||
// Transaction states
|
// Transaction states
|
||||||
readonly property int addressRequested: 1
|
readonly property int addressRequested: 1
|
||||||
readonly property int declined: 2
|
readonly property int declined: 2
|
||||||
|
2
vendor/status-go
vendored
2
vendor/status-go
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 003f384409b0c6471450543809e7aee568cce170
|
Subproject commit 5b513bc791922a1aa3afdd02b16d2854e5d95296
|
Loading…
x
Reference in New Issue
Block a user